[英]AS3 Load swf As Movieclip
我需要加載一個外部swf並將其用作FlashDevelop中的Movieclip,即我需要能夠轉到特定的關鍵幀,啟動和停止它的播放等。一些簡單的工作示例代碼將受到極大的贊賞,因為我無法通過Google查找任何令人滿意的教程。
編輯我現在有這個代碼
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:無法訪問空對象引用的屬性或方法。 有任何想法嗎?
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' );
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.