getDefinitionByName()函數
public function getDefinitionByName(name:String):Object
傳回 name 參數所指定之類別的類別物件參照。
參數
name:String — 類別的名稱。
傳回值
Object — 會傳回 name 參數所指定之類別的類別物件參照。
擲回值
ReferenceError — 具有指定之名稱的公用定義不存在。
991231_GetDefinitionByName_1.swf
package { import flash.utils.getDefinitionByName; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Bitmap; import flash.display.Loader; //import flash.display.MovieClip; import flash.display.Sprite; import flash.net.URLRequest; import flash.events.Event; import flash.events.ProgressEvent; import flash.text.TextField; import flash.text.TextFieldAutoSize; //import flashx.textLayout.formats.FormatValue; import flash.text.TextFormat; public class GetDefinitionByName_1_991231 extends Sprite{ // private var urlString:String = "991230_GetDefinitionByName_1.jpg"; // //getDefinitionByName函數傳回flash.display.Loader類別的參照,指定給Class型別的classReference變數。 private var classReference:Class = getDefinitionByName("flash.display.Loader") as Class; //new 運算子建構classReference類別實體,指定給Object型別的ldr變數。ldr已經參照了Loader類別。 private var ldr:Object = new classReference(); private var tf:TextField = new TextField(); // public function GetDefinitionByName_1_991231() { setTextField(); ldrFun(); } // function setTextField():void{ // var format:TextFormat = new TextFormat(); with(format){ color = 0xffffff; size = 86; font = "Arial"; } // addChild(tf); with(tf){ defaultTextFormat = format; x = 0; y = stage.stageHeight/2 -50 ; width = stage.stageWidth; autoSize = TextFieldAutoSize.CENTER; } }; // private function ldrFun():void{ ldr.load(new URLRequest(urlString)); trace(urlString); ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress); ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete); } // private function onLoaderProgress(e:ProgressEvent):void{ tf.text = String(Math.floor(e.bytesLoaded/e.bytesTotal*100)); } // private function onComplete(e:Event):void{ trace(ldr); // [object LoaderInfo] var ldrBm:Bitmap = e.currentTarget.content as Bitmap; var bmd :BitmapData = ldrBm.bitmapData; var bm:Bitmap = new Bitmap(bmd); trace(bmd); // [object BitmapData] addChild(bm); bm.x = 50; bm.y = 30; } } }
適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.utils_getDefinitionByName()函數
沒有留言:
張貼留言