關於AS 1.0、AS 2.0和java

來源:互聯網
上載者:User
關於ActionScript 1.0、ActionScript 2.0、java的區別與聯絡——基於一個執行個體的討論

問題:建立兩個位置大小顏色各不同的可拖拽的矩形。

方法一: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.0

var 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;

此方法必須得有一個Rectangle.as與之同路徑。Rectangle.as內容如下:

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);        //這裡就不需要手動delete了,因為java有記憶體回收行程,它會自動清除。    }}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;    }}

  通過比較不難發現,ActionScript 1.0最靈活、最簡單、最容易理解。但重複類似的操作時也會最繁瑣。如果要畫1000個位置大小顏色各不同的矩形的話,不累死也會被笑死! ActionScript 2.0則非常系統,單獨用Rectangle.as定義了一個矩形類,使用時new即可,爽!有點小小的遺憾的是有幾行delete,當然你也可以不加,讓它永遠霸佔你的記憶體。再看看java,看完了又看,看完了再看,呵呵! 啥也不說了,誰老大肯定有人知道。



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。