dngo
dngo

Reputation: 59

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

Upvotes: 0

Views: 8464

Answers (3)

www0z0k
www0z0k

Reputation: 4434

`(loader.content as MovieClip)`

Upvotes: 0

PatrickS
PatrickS

Reputation: 9572

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

Upvotes: 0

Tyler Egeto
Tyler Egeto

Reputation: 5495

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

Upvotes: 1

Related Questions