标签:
actionscript3允许把外部swf直接用Embed标记嵌入到主类中(当然用UrlLoader动态加载也行)
原 作者:菩提树下的杨过
出处:http://yjmyzz.cnblogs.com
关键点:
设计师把素材放入到库中时,一定要指定类名,这样代码才能创建这些类的实例。
如上图所示,这里库中放了三种基本的素材(按钮,位图,电影夹),然后在代码中可以这样处理:
1 package 2 { 3 4 import flash.display.Sprite; 5 import flash.display.DisplayObject; 6 import flash.display.SimpleButton; 7 import flash.events.MouseEvent; 8 import flash.display.MovieClip; 9 import flash.display.BitmapData; 10 import flash.display.Bitmap; 11 12 13 public class Demo extends MovieClip 14 { 15 [Embed(source = "skin.swf",symbol = "ButtonPause")] 16 private var ButtonPause:Class; 17 18 [Embed(source = "skin.swf",symbol = "ButtonPlay")] 19 private var ButtonPlay:Class; 20 21 [Embed(source = "skin.swf",symbol = "LogoImage")] 22 private var LogoImage:Class; 23 24 [Embed(source = "skin.swf",symbol = "TestMovie")] 25 private var TestMovie:Class; 26 27 28 public function Demo() 29 { 30 init(); 31 } 32 33 private function init():void 34 { 35 var btnTest:SimpleButton = new ButtonPause() as SimpleButton; 36 trace(btnTest,btnTest is SimpleButton);//Demo_ButtonPause0,true 37 addChild(btnTest); 38 btnTest.x = btnTest.y = 50; 39 btnTest.addEventListener(MouseEvent.CLICK,btnTestClick); 40 41 var btnTest2:SimpleButton = new ButtonPlay() as SimpleButton; 42 trace(btnTest2);//Demo_ButtonPlay1 43 addChild(btnTest2); 44 btnTest2.y = 50; 45 btnTest2.x = 100; 46 btnTest2.addEventListener(MouseEvent.CLICK,btnTest2Click); 47 48 49 var bmd:Bitmap = new LogoImage() as Bitmap; 50 trace(bmd);//Demo_LogoImage2 51 addChild(bmd); 52 bmd.x = bmd.y = 200; 53 54 var testMovie:MovieClip = new TestMovie() as MovieClip; 55 addChild(testMovie); 56 testMovie.x = testMovie.y = 180; 57 trace(testMovie);//Demo_TestMovie3 58 59 } 60 61 private function btnTestClick(e:MouseEvent):void 62 { 63 trace("btnTest 被点击了!"); 64 } 65 66 private function btnTest2Click(e:MouseEvent):void 67 { 68 trace("btnTest2 被点击了!"); 69 } 70 } 71 72 }
标签:
原文地址:http://www.cnblogs.com/xiyuxiyu/p/4730992.html