|
首页 | 名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
关于ActionScript 1.0、ActionScript 2.0、java的区别与联系――基于一个实例的讨论
问题:创建两个位置大小颜色各不同的可拖拽的矩形。 方式一:method1.fla //ActionScript 1.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 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,看完了又看,看完了再看,呵呵! 啥也不说了,谁老大肯定有人知道。
返回类别: Flash教程 上一教程: Flash视频教程:制作透视文字 下一教程: 轻松把文档文件转为FLASH动画 您可以阅读与"关于AS 1.0、AS 2.0和java"相关的教程: · 关于 Fscommand 和 Javascript 的配合 · 如何屏遮Flash中的"设置""关于" · FLASH -- 关于变量的问题FLASH -- 关于变量的问题 · Flash与Java Servlet结合实现网上对战 · Flash中关于过场的一些想法和简朴的教程 |
快精灵印艺坊 版权所有 | 首页会员中心在线印刷在线编辑付款方式索取样品设计指南连锁门店 |