A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS3: add event listener to loaded AS2 SWF

Hybrid View

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    8

    AS3: add event listener to loaded AS2 SWF

    Hi,
    What I am trying to do is - simply load an external SWF into my AS3 code.
    I then want to show it on my stage - and be able to catch the 'ROLL_OVER', 'ROLL_OUT' and 'MOUSE_CLICK' events that happen with the SWF,
    meaning - I want to know when the user hovers over the loaded SWF and when he clicks on it.

    If I load an external AS3 SWF - it all works fine, and I can trace the events successfully.

    If I load an external AS2 SWF - in some types of AS2 banners I can catch the events, and in some - I can't.

    It is important to note that I cannot control the loaded SWFs and I cannot code them in a different manner.

    The way I load the external SWFs is like this:

    Code:
    var loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded);
    loader.load(new URLRequest(externalSwfURL));
    
    function onLoaded(evt:Event):void
    {
    	// The reason I don't create the MovieClip like this is because I need to support 
    	// both AS2 and AS3 that will be loaded, and loaded AS2 cannot be casted to 'MovieClip'
    	//var mc:MovieClip = MovieClip(evt.target.content);  
    
    	// This method allows me to load both external AS2 and AS3 SWF files
    	var mc:MovieClip = new MovieClip();
    	mc.addChild(loader);
    
    	// Add the events that I want to track
    	mc.addEventListener(MouseEvent.ROLL_OVER	, onMouseEnterSWF);
    	mc.addEventListener(MouseEvent.ROLL_OUT	, onMouseLeaveSWF);
    	mc.addEventListener(MouseEvent.CLICK	, onMouseClickSWF);
    
    	mc.x = 100;
    	mc.y = 100;
    
    	stage.addChild(mc);
       }
    What I have found out is that if the loaded AS2 SWF has a transparent button on top of it (a lot of them have that) -
    then the mouse events aren't fired back up to my AS3 code ! They are somehow 'swallowed' inside the loaded AS2 SWF and not bubbled up.

    If I try to load an AS3 SWF that has a transparent button as the top layer - it works, and still bubbles up the mouse events to my AS3 code.

    Can anyone tell me why this happens ?

    PS - if I load an AS2 SWF that doesn't have a transparent button as a top layer - than the mouse events ARE bubbled up to my AS3 code.

    Here is a link to an AS2 SWF file that has the 'transparent button' that blocks the events from bubbling up to the AS3 code:
    http://www.filedropper.com/jdatebanner-copy

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Is the transparent button part of the AS2 movie, is that an AS2 button?
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    Quote Originally Posted by cancerinform View Post
    Is the transparent button part of the AS2 movie, is that an AS2 button?
    I guess so. I am not sure. You can check the banner in the link I sent.

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