關(guān)于ActionScript 1.0、ActionScript 2.0、java的區(qū)別與聯(lián)系——基于一個(gè)實(shí)例的討論
問(wèn)題:創(chuàng)建兩個(gè)位置大小顏色各不同的可拖拽的矩形。
方法一:method1.fla //ActionScript 1.0 //Flash Player 6(含)以上 //ActionScript 1.0或ActionScript 2.0均可
createEmptyMovieClip ("rectangle1_mc", 1); rectangle1_mc._x = 10; rectangle1_mc._y = 10; with (rectangle1_mc) { beginFill (0xff0000, 100); moveTo (0, 0); lineTo (200, 0); lineTo (200, 200); lineTo (0, 200); endFill (); } rectangle1_mc.onPress = startDrag; rectangle1_mc.onRelease = rectangle1_mc.onReleaseOutside = stopDrag; // createEmptyMovieClip ("rectangle2_mc", 2); rectangle2_mc._x = 50; rectangle2_mc._y = 50; with (rectangle2_mc) { beginFill (0xffcc00, 100); moveTo (0, 0); lineTo (400, 0); lineTo (400, 100); lineTo (0, 100); endFill (); } rectangle2_mc.onPress = startDrag; rectangle2_mc.onRelease = rectangle2_mc.onReleaseOutside = stopDrag;
方法二:method2.fla //ActionScript 2.0 //Flash Player 6(含)以上 //必須為ActionScript 2.0var rect1:Rectangle = new Rectangle (this, 10, 10, 200, 200, 0xff0000, 1); var rect2:Rectangle = new Rectangle (this, 50, 50, 400, 100, 0xffcc00, 2); delete rect1; delete rect2; delete Rectangle;
此方法必須得有一個(gè)Rectangle.as與之同路徑。Rectangle.as內(nèi)容如下:
class Rectangle extends MovieClip { private var rectangle_mc:MovieClip; public function Rectangle (target:MovieClip, x:Number, y:Number, w:Number, h:Number, color:Number, depth:Number) { rectangle_mc = target.createEmptyMovieClip ("rectangle_mc" + depth, depth); rectangle_mc._x = x; rectangle_mc._y = y; with (rectangle_mc) { beginFill (color, 100); moveTo (0, 0); lineTo (w, 0); lineTo (w, h); lineTo (0, h); endFill (); } rectangle_mc.onPress = startDrag; rectangle_mc.onRelease = rectangle_mc.onReleaseOutside = stopDrag; } }
方法三:method3.java //如果.java也可以直接編譯.swf的話
public class method3{ public static void main(String[] args){ Rectangle rect1 = new Rectangle (this, 10, 10, 200, 200, 0xff0000, 1); Rectangle rect2 = new Rectangle (this, 50, 50, 400, 100, 0xffcc00, 2); //這里就不需要手動(dòng)delete了,因?yàn)閖ava有垃圾回收器,它會(huì)自動(dòng)清除。 } } class Rectangle extends MovieClip { private MovieClip rectangle_mc; public Rectangle (MovieClip target, Double x, Double y, Double w, Double h, Double color, Double depth) { rectangle_mc = target.createEmptyMovieClip ("rectangle_mc" + depth, depth); rectangle_mc._x = x; rectangle_mc._y = y; with (rectangle_mc) { beginFill (color, 100); moveTo (0, 0); lineTo (w, 0); lineTo (w, h); lineTo (0, h); endFill (); } rectangle_mc.onPress = startDrag; rectangle_mc.onRelease = rectangle_mc.onReleaseOutside = stopDrag; } }
通過(guò)比較不難發(fā)現(xiàn),ActionScript 1.0最靈活、最簡(jiǎn)單、最容易理解。但重復(fù)類似的操作時(shí)也會(huì)最繁瑣。如果要畫1000個(gè)位置大小顏色各不同的矩形的話,不累死也會(huì)被笑死! ActionScript 2.0則非常系統(tǒng),單獨(dú)用Rectangle.as定義了一個(gè)矩形類,使用時(shí)new即可,爽!有點(diǎn)小小的遺憾的是有幾行delete,當(dāng)然你也可以不加,讓它永遠(yuǎn)霸占你的內(nèi)存。 再看看java,看完了又看,看完了再看,呵呵! 啥也不說(shuō)了,誰(shuí)老大肯定有人知道。
出處:向明空間
責(zé)任編輯:moby
◎進(jìn)入論壇Flash專欄版塊參加討論
|