1

我需要加载外部 swf 并能够将其用作 FlashDevelop 中的 Movieclip,即我需要能够转到特定的关键帧、开始和停止播放等。一些简单的工作示例代码将不胜感激,因为我不能通过谷歌找到任何令人满意的教程。

编辑 我现在有这个代码

package 
{
import flash.net.*;
import flash.display.*;
import flash.events.*;
import flash.utils.getQualifiedClassName;

public class Main extends MovieClip 
{

    var animatedBox:MovieClip = new MovieClip();
    var ldr:Loader = new Loader();
    var frames:int = 0;

    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onload);
        ldr.load(new URLRequest("../lib/test.swf"));
    }

    function onload(e:Event)
    {
        if ( !e.target )
        return;

        if( e.target.content is MovieClip )
        {
            animatedBox = e.target.content as MovieClip;

            animatedBox.gotoAndPlay("Start");
        }
        else
        {
            trace( getQualifiedClassName( e.target.content ) );
        }
    }

}

}

在我尝试运行它后,我得到 [Fault] 异常,信息=TypeError:错误 #1009:无法访问空对象引用的属性或方法。有任何想法吗?

4

1 回答 1

2
import flash.utils.getQualifiedClassName;

var mc: MovieClip;

var ldr: Loader = new Loader();
ldr.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoad );
ldr.load( new URLRequest("your.swf") );


function onLoad( e:Event ):void 
{
    if( !e.target )
        return;

    trace( getQualifiedClassName( e.target.content ) );
    /* if you get: flash.display::AVM1Movie
       it means you are trying to load an AS1 or AS2 SWF
       into AS3 SWF. They both need to be AS3 */

    mc = e.target.content as MovieClip;
    mc.gotoAndPlay( 2 );    
    // or  mc.gotoAndPlay( 'yourLabel' ); 

}
于 2013-06-02T10:54:20.473 回答