开发者

Flash: Error #2007 when loading AS2 file into AS3 Movie

I have a main SWF file, in AS3, wich works as holder/loader for many other SWF files (sections). I had to make a new section ("verano.swf"), but I did it in AS2. When I try to load it, I get the following error:

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

It refers to this function:

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

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

Now, the file loads, because the output console shows everything I told the AS2 file ("verano.swf") to trace, but it doesn't display nevertheless.

The full code as follows:

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)开发者_StackOverflow中文版;
                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);
        }


    }

}


The issue you're having is that AVM1Movie cannot be converted to a MovieClip this will result in a null, which is why you are getting that error.

If you simplify your code to the essentials before posting you might get more replies as there's less to look through, also you might isolate your problem and find it easier to solve it.

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);
}

the difference you will notice is that I'm adding the mLoader instead of loadEvent.currentTarget.content

content is an AVM1Movie which will return a null if you try to convert it to a MovieClip, and you can't change the parent, so using addChild won't work. You could however also use addChild(loadEvent.currentTarget.loader); which essentially returns mLoader without having to assign a global variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜