A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: addEventListener to loader? or loaded swf?

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    12

    addEventListener to loader? or loaded swf?

    I am loading an external swf file using the following code:


    Code:
    		//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
    		}
    Question 1:
    Once the loader loads my image, and I click on it, nothing is happening. Am I supposed to be adding the EventListener to the loader or something else?

    Question 2:
    How can I detect the height and width of the swf file in the loader?

  2. #2
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    This covers both questions

    private var _loader:Loader=new Loader();

    private function loadImage():void
    {
    _loader=new Loader();
    _loader.contentLoaderInfo.addEventListener( Event.INIT, loaderDone );
    //replace with whatever you are actually loading
    _loader.load(new URLRequest("./defaultavatar.png?timestamp="+new Date().getTime()));
    }

    private function loaderDone(e:Event):void
    {
    trace(e.currentTarget.content.width);
    trace(e.currentTarget.content.height);
    var loadbutton:MovieClip = new MovieClip();
    loadbutton.addChild(e.currentTarget.content)
    loadbutton.addEventListener(MouseEvent.MOUSE_DOWN, butClick);
    loadbutton.buttonMode = true;
    loadbutton.useHandCursor = true;
    addChild(loadbutton);

    }
    private function butClick(e:MouseEvent):void
    {
    navigateToURL( new URLRequest( "http://www.flashkit.com" ), "_blank" );
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center