开发者

AS3 - CONVERTING THE LOADER INTO MOVIECLIP

Here is my problem. I am trying to convert the [Loader Object] into the MovieClip but could't do it. Please see the comment in to code to see my problem. The reason i want to do this is because i have other movieclips on my code, I like to be able to use those code instead of converting the code to works with the loader object.

Thank you.

    var myLoader:Loader = new Loader();
    myLoader.load(new URLRequest("http://www.google.com/images/logos/ps_logo2.png"));/*load the image*/
    //addChild(myLoader); //Don't use this methoad.
    /*REMOVE the comment above to see the google logo, and ADD comment the  myMovieClip.addChild(myLoader) on line 13
    trace("myLoader = " + myLoader);
    /*CONVERTING THE LOADER INTO MOVIECLIP*/
    //Converting [object Loader] into MovieClip
    var myMovieClip:MovieClip = new MovieClip();
    //Add the MovieClip 开发者_C百科to replace the Loader.
    /*the code below doesn't work because you can't add a child to a 
    loader but this i'm not adding to the loader. I am adding to the 
    movieClip*/
    myMovieClip.addChild(myLoader); //this code doesn't work.******* THIS IS LINE 13**********
    trace("LoadLogos = " + myMovieClip);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMousePress); 
function onMousePress(evt:MouseEvent):void{ trace(evt.target); } 


Your code above should work fine, just make sure you add myMovieClip to the display list as well.


var mc:MovieClip = new MovieClip();
var myLoader:Loader = new Loader();
myLoader.load(new URLRequest("http://www.google.com/images/logos/ps_logo2.png"));
mc.addChild( myLoader );
addChild(mc);

Your Loader may not show instantly as it will take time to load its content, in order to make sure that the content has been loaded, you can listen to a complete event

var mc:MovieClip = new MovieClip();
addChild( mc);

var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE , completeHandler );
myLoader.load(new URLRequest("http://www.google.com/images/logos/ps_logo2.png"));

function completeHandler( event:Event ):void
{
   mc.addChild( myLoader );
}


`(loader.content as MovieClip)`
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜