“flash开发”发展到今天,大体上已经细分为二个分支:Flash 设计师 和 Flash程序员,然而设计师不懂代码,程序员不懂设计,如何把这二种角色有机结合起来,实现代码、界面分离?可能下面的办法对你有用:
actionscript3允许把外部swf直接用Embed标记嵌入到主类中(当然用UrlLoader动态加载也行),这意味着设计师们可以把一些常用的与代码无关的素材(比如按钮,图片,小动画),以他们喜欢的方式,用Flash CS工具设计好放到库中。
然后程序员把这类包含(皮肤)素材的swf嵌入到程序代码中,用代码创建相应的实例,这样程序员用flash builder/flashdevelop做开发,设计师用flash cs做设计,互不相干。
关键点:
设计师把素材放入到库中时,一定要指定类名,这样代码才能创建这些类的实例。
![](https://pic002.cnblogs.com/img/yjmyzz/201007/2010071712353276.jpg)
如上图所示,这里库中放了三种基本的素材(按钮,位图,电影夹),然后在代码中可以这样处理:
04 |
import flash.display.Sprite; |
05 |
import flash.display.DisplayObject; |
06 |
import flash.display.SimpleButton; |
07 |
import flash.events.MouseEvent; |
08 |
import flash.display.MovieClip; |
09 |
import flash.display.BitmapData; |
10 |
import flash.display.Bitmap; |
13 |
public class Demo extends MovieClip |
15 |
[Embed(source = "skin.swf" ,symbol = "ButtonPause" )] |
16 |
private var ButtonPause:Class; |
18 |
[Embed(source = "skin.swf" ,symbol = "ButtonPlay" )] |
19 |
private var ButtonPlay:Class; |
21 |
[Embed(source = "skin.swf" ,symbol = "LogoImage" )] |
22 |
private var LogoImage:Class; |
24 |
[Embed(source = "skin.swf" ,symbol = "TestMovie" )] |
25 |
private var TestMovie:Class; |
28 |
public function Demo() |
33 |
private function init(): void |
35 |
var btnTest:SimpleButton = new ButtonPause() as SimpleButton; |
36 |
trace (btnTest,btnTest is SimpleButton); |
38 |
btnTest.x = btnTest.y = 50 ; |
39 |
btnTest.addEventListener(MouseEvent.CLICK,btnTestClick); |
41 |
var btnTest2:SimpleButton = new ButtonPlay() as SimpleButton; |
46 |
btnTest2.addEventListener(MouseEvent.CLICK,btnTest2Click); |
49 |
var bmd:Bitmap = new LogoImage() as Bitmap; |
54 |
var testMovie:MovieClip = new TestMovie() as MovieClip; |
56 |
testMovie.x = testMovie.y = 180 ; |
61 |
private function btnTestClick(e:MouseEvent): void |
63 |
trace ( "btnTest 被点击了!" ); |
66 |
private function btnTest2Click(e:MouseEvent): void |
68 |
trace ( "btnTest2 被点击了!" ); |