简体   繁体   English

AS3:将事件侦听器添加到已加载的AS2 SWF中

[英]AS3: add event listeners to loaded AS2 SWF

What I am trying to do is - simply load an external SWF into my AS3 code. 我想做的是-只需将外部SWF加载到我的AS3代码中即可。

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. 然后,我想在舞台上展示它-并能够捕获SWF发生的'ROLL_OVER','ROLL_OUT'和'MOUSE_CLICK'事件,这意味着-我想知道用户何时将鼠标悬停在加载的SWF上以及何时他单击它。

If I load an external AS3 SWF - it all works fine, and I can trace the events successfully. 如果加载外部AS3 SWF ,则一切正常,并且可以成功跟踪事件。

If I load an external AS2 SWF - in some types of AS2 banners I can catch the events, and in some - I can't. 如果我加载外部AS2 SWF ,则在某些类型的AS2标语中,我可以捕获事件,而在某些类型中,则不能。

It is important to note that I cannot control the loaded SWFs and I cannot code them in a different manner. 重要的是要注意,我无法控制已加载的SWF,也无法以其他方式对其进行编码。

The way I load the external SWFs is like this: 我加载外部SWF的方式如下:

.

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 ! 我发现的是,如果加载的AS2 SWF上面有一个透明按钮(很多按钮都有)-那么鼠标事件不会触发我的AS3代码! They are somehow 'swallowed' inside the loaded AS2 SWF and not bubbled up. 它们以某种方式被“吞噬”在已加载的AS2 SWF内部,并且没有冒泡。

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. 如果我尝试加载具有透明按钮作为顶层的AS3 SWF,则它可以工作,并且仍然会将鼠标事件添加到我的AS3代码中。

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. PS-如果我加载没有透明按钮作为顶层的AS2 SWF,则鼠标事件会冒泡到我的AS3代码中。

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: link to AS2 SWF 这是指向AS2 SWF文件的链接,该文件具有“透明按钮”,可以阻止事件冒泡至AS3代码: 链接到AS2 SWF

ActionScript 2 runs in a different virtual machine and is not compatible with ActionScript 3. Communication between the two SWFs ist not even not easy, but works only with a local connection. ActionScript 2在不同的虚拟机中运行,并且与ActionScript 3不兼容。两个SWF之间的通信甚至不容易,但仅适用于本地连接。 ActionScript 2 also doesn't have an event system so this would be the second part to take care of. ActionScript 2也没有事件系统,因此这是第二部分。

-> it can't work as you expect it to. ->它无法按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM