2009-12-19 3 views
0

: 여기addEventListener를 로더에 추가 하시겠습니까? 또는로드 된 swf? 나는 다음과 같은 코드를 사용하여 외부 SWF 파일을로드하고

//add close button 
    var reqButton:URLRequest = new URLRequest(btn_close); 
    var loader2:Loader = new Loader(); 
    loader2.load(reqButton); 
    addChild(loader2); 

    loader2.addEventListener(MouseEvent.CLICK, closeInfoBubble); 

    function closeInfoBubble(event:MouseEvent):void 
    { 
    infoClip.removeMarkerObject(infoBubble) 
    infoBubble = null 
    } 

는 대한 전체 코드가

package com.modestmaps 
{ 
     import com.modestmaps.overlays.MarkerClip; 

     import flash.display.Graphics; 
     import flash.net.URLRequest; 
     import flash.display.Loader; 
     import flash.display.Shape; 
     import flash.display.Sprite; 
     import flash.filters.BlurFilter; 
     import flash.geom.Matrix; 
     import flash.geom.Rectangle; 
     import flash.text.TextField; 
     //import mx.core.Application; 
     import mx.core.Application; 
     import flash.events.MouseEvent; 


public class InfoBubble extends Sprite 
{ 
    private var btn_close:String = "http://www.cvcmaps.com/SabineParish/media/close_button.swf"; 
    public var textField:TextField; 
    public var background:Shape; 
    public var shadow:Shape; 
    public var infoClip:MarkerClip; 

    protected var map:InfoMap; 
    //var infoClip:MarkerClip; 
    public var infoBubble:InfoBubble; 
    public function InfoBubble(urlLink:String) 
    { 
     //the name of my markers are set to the links of the swf files in which I want to load into the infobubble 
     this.name = urlLink; 
     this.mouseEnabled = false; 
     this.mouseChildren = true; 
     this.buttonMode=false; 

     shadow = new Shape(); 
     shadow.filters = [ new BlurFilter(16, 16) ]; 
     shadow.transform.matrix = new Matrix(1, 0, -0.5, 0.5, 0, 0); 
     addChild(shadow); 

     background = new Shape(); 
     addChild(background); 

     textField = new TextField(); 
     textField.selectable = false; 
     //the infobubble is still sized according to the textField.width and height 
     //I don't know how to get the size of the loaded swf 
     textField.width = textField.textWidth+432+4; 
     textField.height = textField.textHeight+288+4; 

     //add main swf 
     var request:URLRequest = new URLRequest(urlLink); 
     var loader:Loader = new Loader(); 
     loader.load(request); 
     addChild(loader); 

     //position the main swf 
     //current measurements of swf file w432 h288 
     loader.y = -288 - 37; 
     loader.x = mx.core.FlexGlobals.topLevelApplication.LBloaderX; 

     //add close button 
     var reqButton:URLRequest = new URLRequest(btn_close); 
     var loader2:Loader = new Loader(); 
     loader2.load(reqButton); 
     addChild(loader2); 

     loader2.addEventListener(MouseEvent.CLICK, closeInfoBubble); 

     function closeInfoBubble(event:MouseEvent):void 
     { 
     infoClip.removeMarkerObject(infoBubble) 
     infoBubble = null 
     } 
     //position the closebutton swf 
     //current measurements of closebutton swf file w18 h18 
     loader2.y = -286 - 37; 
     loader2.x = mx.core.FlexGlobals.topLevelApplication.LBloader2X; 

     // remember that things in marker clips are positioned with (0,0) at the given location 
     textField.y = -textField.height - 35; 
     textField.x = -10; 

     //I need to find out how to detect the width and height of the swf file loaded into loader2 
     //instead of the size of the textField 
     var rect:Rectangle = textField.getRect(this); 

     // get your graph paper ready, here's a "speech bubble" 
     background.graphics.beginFill(0x12345); 
     shadow.graphics.beginFill(0x000000); 

     for each (var g:Graphics in [ background.graphics, shadow.graphics ]) { 
      g.moveTo(rect.left, rect.top); 
      g.lineTo(rect.right, rect.top); 
      g.lineTo(rect.right, rect.bottom); 
      g.lineTo(rect.left+15, rect.bottom); 
      g.lineTo(rect.left+10, rect.bottom+15); 
      g.lineTo(rect.left+5, rect.bottom); 
      g.lineTo(rect.left, rect.bottom); 
      g.lineTo(rect.left, rect.top); 
      g.endFill(); 
     } 
    } 
    } 
} 

질문 1 파일이 .as입니다 : 를 로더 내 이미지를로드하면, 및 클릭하면 아무 일도 일어나지 않습니다. EventListener를 로더 또는 다른 것에 추가해야합니까?

질문 2 : 로더에서 swf 파일의 높이와 너비를 어떻게 감지합니까?

답변

1

loader2.content.height을 사용하여로드

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, itemLoaded); 

다른들을 수 있습니다 이벤트가 발생하지만 이벤트를 전달하는 객체를 참조하므로 로더의 "contentLoaderInfo"속성을 사용해야합니다.

희망이 도움이됩니다.

0

1) MouseEvent를 로더에 추가하는 데 문제가 없으며 동일한 도메인에 이미지가로드 된 다른 문제가 있어야합니까? 부모가 모든 이벤트를 먹고 있거나 mouseChildren을 false로 설정 했습니까?

2) 내용의 크기를 들어, 한 번 당신의 SWF가로드 될 때 감지하기

loader2.content.width

+0

로드 된 상태를 어떻게 알 수 있습니까? – Phil

관련 문제