工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 3765|回复: 31

[有点内容了]FLASH ActionScript

[复制链接]
发表于 2006-8-10 23:32 | 显示全部楼层 |阅读模式
虽然在学C++,但还是对AS熟点
先发个空支票......
================================

8.16

AS 中的变量

        变量申明:  var  varName:DataType;

        不同于其它语言,AS里的 var 是真正的可变(variable)类型.
        申明 数字类型时不是   Number  accountOfSubject;
         AS3.0里将有 int 类型

       类实例(instance,即对象的申明?) var instanceName:ClassName;

    ( 其实类的概念创建就是一个新的"变量类型",这在其它语言中也是一样的,可以把类名直接当做个个类型 )

注意!变量的申明不要省略!  
AS2.0的类型检查(dataType checking) is an "opt-in" system ( opt-in不知道怎么译,是optional? )
如果不对变量类型申明,如:
var x=10;
trace(x.fun());  //输出 undefine


对没申明类型的变量,编译时会试图将其进行转换,不管成不成功,都不会给你提示.

  1. var x = 10;
  2. x = "helloWorld!";
  3. trace( x );           //输出 helloWorld!
  4. trace(x.fun());    //输出 undefined
  5. trace( typeof(x) )//输出 String   类型已转换
复制代码


如果把上面的 var x = 10;  换为 var x:Number = 10; 上面的语句将不能运行.

9.20
   开始用FLEX写AS3.0,有代码提示,方便

9.26
           关于 setInterval

  1. class Test{
  2.   private var a:Number;
  3.   public function Test(){
  4.     a=1;
  5.     setInterval(aa,1000);
  6.   }
  7.   private function aa()
  8.   {
  9.     trace(a);
  10.   }
  11. }
复制代码

在一个fla上帧AS:
var test:Test=new Test();

CTRL+ENTER  输出却是  undefined

解决方法:
setInterval那句改为 setInterval(this,"aa",1000);

原因是:在自定义类里面的setInterval不能正确确定函数的范围  setInterval(this,"aa",1000);相当于 setInterval(this.aa,1000); 但不是说这句是可以正确执行的!!只是举例说明范围,事实上,你用了this 也无用因为this.aa的前头会给setInterval再加上其它东西,那aa里面的变量都是其它范围里的变量了

[ 本帖最后由 iptton 于 2006-9-26 00:42 编辑 ]
发表于 2006-8-13 20:24 | 显示全部楼层
发现AS3.0与AS2.0完全不可同日而语……

AS正处于发展期,不像JAVA C++

要考虑考虑深入学不学AS2.0,3.0以后应该会稳定点了

FLASH 9。0 要07年才发布正式版

正在有ALPHA版可下(要已装了8.0版 的用户才可以用)
回复

使用道具 举报

发表于 2006-8-13 22:19 | 显示全部楼层
原帖由 onttpi 于 2006-8-13 20:24 发表

要考虑考虑深入学不学AS2.0,3.0以后应该会稳定点了


这样想似乎不对吧?
那JAVA的框架发展如此之快,都不用学了.
EJB3.0似乎很先进,可我还是不得不学2.1的.
回复

使用道具 举报

 楼主| 发表于 2006-8-13 23:27 | 显示全部楼层
JAVA是框架变……

本质的语言没有变

而AS是语言,语法变

AS1。0跟2.0的区别是天地之差了,几乎,而3.0又要废除2.0中的一些API 函数 关键字……
回复

使用道具 举报

发表于 2006-8-15 14:11 | 显示全部楼层
楼主...小子...居然学我乱发空头支票...
回复

使用道具 举报

 楼主| 发表于 2006-8-15 14:19 | 显示全部楼层
是空白支票……
回复

使用道具 举报

发表于 2006-8-15 16:33 | 显示全部楼层
出来混,迟早要还的
回复

使用道具 举报

发表于 2006-8-15 21:31 | 显示全部楼层
wool带坏头. TJJTDS

PS:还是希望IP尽快补上.毕竟空白不索很好.
回复

使用道具 举报

发表于 2006-8-15 23:08 | 显示全部楼层
想知道在碰撞检测方面有什么进步否。。。。。
回复

使用道具 举报

 楼主| 发表于 2006-8-16 15:05 | 显示全部楼层
碰撞测试没有进步了...

见13F……

[ 本帖最后由 iptton 于 2006-8-26 19:52 编辑 ]
回复

使用道具 举报

发表于 2006-8-17 19:44 | 显示全部楼层
碰撞还是四方形的检测吗.

以前为了稍微精确点的碰撞, 要在对象上面设置关键点来检测....烦到死了.
回复

使用道具 举报

 楼主| 发表于 2006-8-17 20:44 | 显示全部楼层
BTW 我有一本 电子书 AS3.0  REFERENCE  (英文的)

需要的PM 留EMAIL给我……
回复

使用道具 举报

 楼主| 发表于 2006-8-17 21:57 | 显示全部楼层

碰撞测试有进步了!

AS3.0  已很接近一种规范的语言了(网上有人说可以和JAVA平起平坐,甚至有些方面比JAVA还优……)

AS3.0里  hitTest  在  flash.Display.Shape类里(是Shape类的一个成员函数)

以下是摘自我手中的参考

hitTestObject () method   

public function hitTestObject(obj:DisplayObject):Boolean
Evaluates the display object to see if it overlaps or intersects with the obj display object.

Parameters  obj:DisplayObject — The display object to test against.  


Returns  Boolean — true if the display objects intersect; false if not.  

Example
The following code creates three Shape objects and shows the result of calling the hitTestObject() method:

  1. import flash.display.Shape;

  2. var circle1:Shape = new Shape();
  3. circle1.graphics.beginFill(0x0000FF);
  4. circle1.graphics.drawCircle(40, 40, 40);
  5. addChild(circle1);

  6. var circle2:Shape = new Shape();
  7. circle2.graphics.beginFill(0x00FF00);
  8. circle2.graphics.drawCircle(40, 40, 40);
  9. circle2.x = 50;
  10. addChild(circle2);

  11. var circle3:Shape = new Shape();
  12. circle3.graphics.beginFill(0xFF0000);
  13. circle3.graphics.drawCircle(40, 40, 40);
  14. circle3.x = 100;
  15. circle3.y = 67;
  16. addChild(circle3);

  17. trace(circle1.hitTestObject(circle2)); // true
  18. trace(circle1.hitTestObject(circle3)); // true
  19. trace(circle2.hitTestObject(circle3)); // true
复制代码

hitTestPoint () method   

public function hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):Boolean
Evaluates the display object to see if it overlaps or intersects with the point specified by the x and y parameters. The x and y parameters specify a point in the coordinate space of the Stage, not the display object container that contains the display object (unless that display object container is the Stage).

Parameters  x:Number — The x coordinate to test against this object.  
  
y:Number — The y coordinate to test against this object.  


  

shapeFlag:Boolean (default = false) — Whether to check against the actual pixels of the object (true) or the bounding box (false)
.

  


Returns  Boolean — true if the display object overlaps or intersects with the specified point; false otherwise.  

See also

opaqueBackground

Example
The following code creates a Shape object and shows the result of calling the hitTestPoint() method, using different points as parameters. The globalToLocal() method converts the point from Stage coordinates to the coordinate space of the shape:

  1. import flash.display.Shape;
  2. import flash.geom.Point;

  3. var circle:Shape = new Shape();
  4. circle.graphics.beginFill(0x0000FF);
  5. circle.graphics.drawCircle(40, 40, 40);
  6. circle.x = 10;
  7. addChild(circle);

  8. var point1:Point = new Point(0, 0);
  9. trace(circle.hitTestPoint(point1.x, point1.y, true)); // false
  10. trace(circle.hitTestPoint(point1.x, point1.y, false)); // false
  11. trace(circle.globalToLocal(point1)); // [x=-10, y=0]

  12. var point2:Point = new Point(10, 1);
  13. trace(circle.hitTestPoint(point2.x, point2.y, true)); // false
  14. trace(circle.hitTestPoint(point2.x, point2.y, false)); // true
  15. trace(circle.globalToLocal(point2)); // [x=0, y=1]

  16. var point3:Point = new Point(30, 20);
  17. trace(circle.hitTestPoint(point3.x, point3.y, true)); // true
  18. trace(circle.hitTestPoint(point3.x, point3.y, false)); // true
  19. trace(circle.globalToLocal(point3)); // [x=20, y=20]
复制代码

[ 本帖最后由 iptton 于 2006-8-19 12:53 编辑 ]
回复

使用道具 举报

 楼主| 发表于 2006-8-17 23:58 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2006-8-18 14:46 | 显示全部楼层
AS3.0 变化 摘 自http://www.flashseer.org/bbs/vie ... &extra=page%3D1

1.在语言中,没有了原来习惯的mc.onPress等,即onPress(),onRelease,onRollOver已经被事件所代替,flash.events.MouseEvent 中的MOUSE_DOWN,MOUSE_UP.MOUSE_OVER等.

2.我们经常用到的getDepth也已经消失,由于as3.0中使用了addChild(),将显示对象增加到显示列表中,所以现在相应的getDepth()被flash.display.DisplayObjectContainer.getChildIndex()所替代

3.原来的MovieClip._width,MovieClip._xmouse,_MovieClip._xscale,MovieClip._x,MovieClip._visible,MovieClip._alpha,MovieClip._rotation等,已经被flash.display.DisplayObject中的width,mou***,scaleX,x,visible,alpha,ratation等属性取代.(其实就是变个写法)

4.原来的loadMovie等将要全部通过flash.display.Loader类来实现.

5.在as3.0中增加了E4X,这样以后解析xml更加方便

6.如果要实现LoadVars等功能,在as3.0 中要通过flash.net.URLLoader/URLRequest等来实现.1.在发布的Flash 9 preview中可以看到,在新的IDE中增加了Document Class设置http://bbs.blueidea.com/thread-2641925-1-1.html

7.拥有更多的Runtime exceptions,可以方便的进行debug.

8.可以使用正则表达式,方便控制字符串.

9.拥有更多的数据类型int,uint,Number等

[ 本帖最后由 iptton 于 2006-8-18 19:15 编辑 ]
回复

使用道具 举报

发表于 2006-8-18 23:57 | 显示全部楼层
那个hitTest跟之前不是一样么...
回复

使用道具 举报

发表于 2006-8-18 23:59 | 显示全部楼层
上个例子看看吧, N久没做过Flash了....最上一次是做了一个后院版个人所得税计算器...
回复

使用道具 举报

 楼主| 发表于 2006-8-19 11:27 | 显示全部楼层
确实还和2.0一样……

[ 本帖最后由 iptton 于 2006-8-19 12:52 编辑 ]
回复

使用道具 举报

发表于 2006-8-19 17:19 | 显示全部楼层
不管actionscript再怎么发展,其也只不过是一门ECMAScript标准下的基于prototype, 解释型的语言. 效率上和真正编程语言的差别仍然是无法比较的. 所以它也只能叫actionscript, 而不是actionlanguage. 呵呵, 罢了, 现在玩RPG鸟...
回复

使用道具 举报

 楼主| 发表于 2006-8-20 12:46 | 显示全部楼层
楼上这么说就好像有点对AS的发展不那么了解了

JAVA不也是解释型语言吗?

语言的"高级"不是靠一方面的功能来说的吧……

  JAVA 有JVM  AS  现在也有 AVM了,而且仔细看AS3.0,  和JAVA是那么

相像(当然语法不能说明什么.但毕竟它们的应用层次不同,功能彼有此无,不能说哪个就高级吧....)


RPG??什么来的?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2025-5-15 13:23

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表