views:

36

answers:

3

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); } 
+1  A: 

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

Tyler Egeto
how do you do that?
dngo
addChild(myMovieClip);
Tyler Egeto
A: 
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 );
}
PatrickS
I see your point but this is not the case. Your code doens't convert the Loader Object into the MovieClip object. I have tested your code and the new image is still Loader Object. stage.addEventListener(MouseEvent.MOUSE_DOWN, onMousePress); function onMousePress(evt:MouseEvent):void{ trace(evt.target); }
dngo
I have found the answer to my question. Thank you.
dngo
You don't need to convert the Loader into a MovieClip, by adding the Loader to a MovieClip you can use the MovieClip methods for your image to interact with your application. The Loader is just a container, a tool to load your image, whilst the MovieClip is another container with added functionality. It doesn't even have to be a MovieClip actually, you can use a Sprite instead.
PatrickS
A: 
`(loader.content as MovieClip)`
www0z0k
-1, this will not work. The loaded content is not a MovieClip, this could only work if you were loading a SWF, he is loading a PNG.
Tyler Egeto
just checked: throws TypeError: Error #2007 if png
www0z0k