为什么的MovieClipLoader事件不会触发时加载到AS3包装? [英] Why do MovieClipLoader events not fire when loaded into an AS3 wrapper?

查看:189
本文介绍了为什么的MovieClipLoader事件不会触发时加载到AS3包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图回答这个问题:<一href="http://stackoverflow.com/questions/8064798/call-to-an-as2-function-from-the-as3-container">Call从AS3容器中的AS2功能我所遇到的一个障碍。该设置是一个AS3的SWF它加载的AS2 SWF,从而加载另一个AS2的SWF。 AS3的SWF和家长AS2 SWF之间的通信通过的LocalConnection来实现的。

child_as2.swf - 这是一个非常简单的时间轴动画的盒子在屏幕上的第1帧运动有以下code的:

 停止();
功能的playMovie(){
    玩();
}
 

parent_as2.swf - 这是它加载在child_as2.swf中介AS2容器。负载由一个LocalConnection调用触发:

 进口mx.utils.Delegate;

this._lockroot = TRUE;

VAR容器:影片剪辑= createEmptyMovieClip(容器,10);
//不能施放此或代表休息区
VAR mcLoader =新的MovieClipLoader();
mcLoader._lockroot =真;
mcLoader.onLoadInit = Delegate.create(这一点,onMCLoadInit);

功能onMCLoadInit(){
    跟踪(负载INIT);
    container.playMovie();
}

//方LocalConnection code
VAR myLC​​:方LocalConnection =新的LocalConnection();

myLC.loadChild =功能(){
    mcLoader.loadClip(child_as2.swf,容器);
    跟踪(装载);
}

myLC.connect(AVM);
 

parent_as3.swf - 这是外包装,写在AS3。它加载parent_as2.swf,并通过方LocalConnection与其通信:

  VAR myLC​​:方LocalConnection =新的LocalConnection();

VAR装载机:装载机=新的Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT,onLoaded);
loader.load(新的URLRequest(parent_as2.swf));
的addChild(装载机);


功能onLoaded(事件:事件):无效{
    // setTimeout的黑客绕过#2000安全上下文错误
    的setTimeout(函数(){
        myLC.send(AVM,loadChild);
    },1);
}
 

的问题是,在parent_as2的 onMCLoadInit 函数时,它是在AS3包装内装载不会被调用,虽然负载确实需要的地方。在地方委托的使用侦听器对象时,事件也会失败。从child_as2.swf这个盒子是可见的,但从来没有开始移动。不过,如果我在它自己的运行parent_as2.swf和开工负荷不方LocalConnection它工作正常。它还wroks正确来自外部的LocalConnection调用时触发。为什么AS3的包装prevent从烧制的MovieClipLoader的事件?

更新:

所以接受没有事件可以从parent_as2.swf向MovieClipLoader被开除,我已经修改了code。通过投票相结合的检测loadInit状态 MovieClipLoader.getProgress()和child_as2.swf函数的存在性。这不是pretty的,但它似乎工作。我还是更愿意能够提供使用事件,虽然一个解决方案。

  VAR容器:影片剪辑= createEmptyMovieClip(容器,10);
VAR mcLoader:的MovieClipLoader =新的MovieClipLoader();
VAR loadStarted:布尔;
VAR checkingInt:数字;

功能checkProgress(){
    VAR progObj:对象= mcLoader.getProgress(容器);
    如果(progObj.bytesLoaded == progObj.bytesTotal和放大器;&安培; loadStarted){
        //加载完成后,等待load​​Init
        如果(typeof运算(container.playMovie)==功能){
            // loadInit
            clearInterval(checkingInt);
            container.playMovie();
        }
    }
    //确保了第一环路因不精确具有报告忽略
    loadStarted = TRUE;
}

//方LocalConnection code
VAR myLC​​:方LocalConnection =新的LocalConnection();

myLC.loadChild =功能(){
    loadStarted = FALSE;
    mcLoader.loadClip(child_as2.swf,容器);
    checkingInt =的setInterval(checkProgress,5);
}

myLC.connect(AVM);
 

解决方案

我认为它在AS2委托范围内,当加载到父父变得_root。
因此,这将涉及到的功能不存在父根。
您是否尝试过把 this._lockroot = TRUE; 在parent_as2

<一个href="http://help.adobe.com/en_US/as2/reference/flashlite/WS5b3ccc516d4fbf351e63e3d118ccf9c47f-7f6b.html"相对=nofollow>以下是

另外,作为一个侧面说明您的安全黑客。
对于正确的解决将是有孩子联系家长,并发出我已经准备好键入命令,这将开始从父通信事件的孩子。
的setTimeout只是推迟任何调用子给它的时间来初始化这可能是坏在速度较慢的计算机上。
我几年前做了装载AS2的很多成AS3。如果你看不出来大声笑

While trying to answer this question: Call to an AS2 function from the AS3 container I have come across a roadblock. The setup is an AS3 SWF which loads an AS2 SWF, which in turn loads another AS2 SWF. Communication between the AS3 SWF and the parent AS2 SWF is achieved through localConnection.

child_as2.swf - This is a very simple timeline animation of a box moving across the screen with the following code on frame 1:

stop();
function playMovie() {
    play();
}

parent_as2.swf - This is the intermediary AS2 container which loads in child_as2.swf. The load is triggered by a LocalConnection call:

import mx.utils.Delegate;

this._lockroot = true;

var container:MovieClip = createEmptyMovieClip("container", 10);
//mustn't cast this or the Delegate breaks
var mcLoader = new MovieClipLoader();
mcLoader._lockroot = true;
mcLoader.onLoadInit = Delegate.create(this,onMCLoadInit);

function onMCLoadInit() {
    trace("load init");
    container.playMovie();
}

//LocalConnection code
var myLC:LocalConnection = new LocalConnection();

myLC.loadChild = function(){
    mcLoader.loadClip("child_as2.swf", container);
    trace("loading");
}

myLC.connect("AVM");

parent_as3.swf - This is the outer wrapper, written in AS3. It loads parent_as2.swf, and communicates with it via LocalConnection:

var myLC:LocalConnection = new LocalConnection();

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT,onLoaded);
loader.load(new URLRequest("parent_as2.swf"));
addChild(loader);


function onLoaded(event:Event):void {
    //setTimeout hack to circumvent #2000 Security context error
    setTimeout(function() {
        myLC.send("AVM", "loadChild");
    },1);
}

The issue is that the onMCLoadInit function in parent_as2 is never called when it is loaded inside the AS3 wrapper, although the load does take place. The events also fail when using a listener object in place of Delegate. The box from child_as2.swf is visible, but never starts moving. However, if I run parent_as2.swf on it's own and start the load without the LocalConnection it works fine. It also wroks correctly when triggered from an external LocalConnection call. Why does the AS3 wrapper prevent the MovieClipLoader's events from firing?

Update:

So accepting that no events can be fired from the MovieClipLoader in parent_as2.swf, I have modified the code to detect the loadInit state by a combination of polling MovieClipLoader.getProgress() and the existance of a function in child_as2.swf. It's not pretty but it seems to work. I would still much rather be able to offer a solution using events though.

var container:MovieClip = createEmptyMovieClip("container", 10);
var mcLoader:MovieClipLoader = new MovieClipLoader();
var loadStarted:Boolean;
var checkingInt:Number;

function checkProgress() {
    var progObj:Object = mcLoader.getProgress(container);
    if(progObj.bytesLoaded == progObj.bytesTotal && loadStarted) {
        //load complete, wait for loadInit
        if(typeof(container.playMovie) == "function") {
            //loadInit
            clearInterval(checkingInt);
            container.playMovie();
        }
    }
    //ensures the first loop is ignored due to inaccuracy with reporting
    loadStarted = true;
}

//LocalConnection code
var myLC:LocalConnection = new LocalConnection();

myLC.loadChild = function() {
    loadStarted = false;
    mcLoader.loadClip("child_as2.swf", container);
    checkingInt = setInterval(checkProgress,5);
}

myLC.connect("AVM");

解决方案

I think its the delegate scope in as2 when loaded into a parent the parent becomes _root.
So "this" would be referring to the parent root where the function does not exist.
Have you tried putting this._lockroot = true; in parent_as2?

Here is a better explanation

Also as a side note to your security hack.
The proper fix for that would be to have the child contact the parent and issue an "I am ready type command" which would start the communication events from parent to child.
setTimeout is just delaying any calls to the child giving it time to initialize which could be bad on slower computers.
I did alot of loading AS2 into AS3 a few years ago. If you can't tell lol

这篇关于为什么的MovieClipLoader事件不会触发时加载到AS3包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆