Flash:将AS2文件加载到AS3电影时出现错误#2007

时间:2011-01-18 02:57:33

标签: flash actionscript-3 actionscript actionscript-2

我有一个主要的SWF文件,在AS3中,它作为许多其他SWF文件(部分)的持有者/加载器。我不得不制作一个新的部分(“verano.swf”),但我在AS2中做到了。当我尝试加载它时,我收到以下错误:

TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/addChild()
    at Tabu/onCompleteHandler()

它指的是这个功能:

function onCompleteHandler(loadEvent:Event)
        {
            currentMovie = loadEvent.currentTarget.content as MovieClip;
            addChild(currentMovie);

            if (firstTime)
            {
                (root as MovieClip).afiche.showAfiche();
                firstTime = false;
            }
        }

现在,文件加载了,因为输出控制台显示我告诉AS2文件(“verano.swf”)要跟踪的所有内容,但它仍然没有显示。

完整代码如下:

package  
{
    import flash.display.MovieClip;
    import flash.net.FileFilter;
    import flash.net.FileReference;
    import flash.net.URLRequest;
    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.geom.Rectangle;

    import flash.external.*;

    import flash.net.URLLoaderDataFormat;
    import flash.net.URLLoader;
    import flash.display.Loader;

    import flash.events.*;

    import gs.TweenMax;
    import gs.plugins.*;


    public class Tabu extends MovieClip
    {
        public var currentMovie:MovieClip;
        public var currentMovieName:String;

        var firstTime:Boolean = true;

        function Tabu()
        {
            trace("inicializando pagina");
            ExternalInterface.addCallback("loadSeccion", callMe);
        }

        public function callMe(name:String) {
            trace("callme");
            this.x = -200;
        }

        function loadHome()
        {
            startLoad("home_1_v2.swf");

            var ldr:Loader = new Loader();
            var rand:String = Math.floor(Math.random() * 100000000) + "?";
            var spot_url:String = "http://ad.doubleclick.net/activity;src=2951116;type=lanza404;cat=inte760;ord=1;num=";
            var tag_url:String = spot_url + rand;
            var urlReq:URLRequest = new URLRequest(tag_url);
            ldr.load(urlReq);

        }


        function startLoad(url:String)
        {
            if (currentMovieName != url)
            {
                currentMovieName = url;
                var mLoader:Loader = new Loader();
                var mRequest:URLRequest = new URLRequest(currentMovieName);
                mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
                mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
                mLoader.load(mRequest);
            }

            try {
                (mLoader.content as Object).removed();
            }catch (err:Error)
            {

            }
        }

        function onCompleteHandler(loadEvent:Event)
        {
            currentMovie = loadEvent.currentTarget.content as MovieClip;
            addChild(currentMovie);

            if (firstTime)
            {
                (root as MovieClip).afiche.showAfiche();
                firstTime = false;
            }
        }

        public function setPage(e:MouseEvent)
        {
            if (e.target.name == "btn_1")
                changePage("campana.swf");
            if (e.target.name == "btn_2")
                changePage("toma_tabu.swf");
            else if (e.target.name == "btn_3")
                changePage("verano.swf"); //This is the one! AS2 file!
            else if (e.target.name == "btn_4")
                changePage("manda_tu_tabu.swf");
            else if (e.target.name == "btn_0")
                changePage("home_1_v2.swf");
        }

        public function setPageString(s:String)
        {
            changePage(s);
        }

        function changePage(newPage:String)
        {
            if (currentMovieName != newPage)
            {
                TweenMax.to(currentMovie, 1, { frame:1, onComplete:finishUnload, onCompleteParams:[newPage] } );
            }
        }

        function finishUnload(newPage:String)
        {
            //removeChild(currentMovie);
            startLoad(newPage);
        }

        function onProgressHandler(mProgress:ProgressEvent)
        {
            var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
            trace(percent);
        }


    }

}

1 个答案:

答案 0 :(得分:1)

您遇到的问题是AVM1Movie无法转换为MovieClip这会导致null,这就是您收到错误的原因。

如果您在发布之前将代码简化为基本要素,则可能会收到更多回复,因为您可以查看更少的回复,也可以找出问题并发现更容易解决问题。

var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("testvm1.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.load(mRequest);

function onCompleteHandler(loadEvent:Event)
{
    addChild(mLoader);
}

您会注意到的差异是我正在添加mLoader而不是loadEvent.currentTarget.content

内容是AVM1Movie,如果您尝试将其转换为MovieClip,它将返回null,并且您无法更改父级,因此使用addChild将无法正常工作。 但是,您也可以使用基本上返回addChild(loadEvent.currentTarget.loader);的{​​{1}},而无需分配全局变量。