码迷,mamicode.com
首页 > 其他好文 > 详细

as3中的embed

时间:2015-08-14 21:11:49      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

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 }

as3中的embed

标签:

原文地址:http://www.cnblogs.com/xiyuxiyu/p/4730992.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!