AS3 - 将装载机转换为MOVIECLIP

时间:2010-10-20 15:49:09

标签: actionscript-3

这是我的问题。我试图将[Loader Object]转换为MovieClip,但无法做到。请查看代码中的注释以查看我的问题。我想这样做的原因是因为我的代码上有其他动画片段,我希望能够使用这些代码而不是将代码转换为与loader对象一起使用。

谢谢。

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

3 个答案:

答案 0 :(得分:1)

上面的代码应该可以正常工作,只需确保将myMovieClip添加到显示列表中。

答案 1 :(得分:0)

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

您的Loader可能无法立即显示,因为加载其内容需要时间,为了确保内容已加载,您可以收听完整的活动

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

答案 2 :(得分:0)

`(loader.content as MovieClip)`
相关问题