关于AS1.0、AS2.0和java
2008-04-02 11:03:56来源:互联网 阅读 ()
问题:创建两个位置大小颜色各不同的可拖拽的矩形。
方法一: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,看完了又看,看完了再看,呵呵! 啥也不说了,谁老大肯定有人知道。
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇: Flash实例学习:随机射线效果
下一篇: 寓教于乐猫捉老鼠Flash小游戏自己做
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash