首页 | 手机版 | 三国演义 | 三国志 | 史将 | 背景 | 藏书阁
首页 -> 精彩文章 -> 测试版...

测试版...

作者3599013 标签flash 阅读次数:60
ActionScript 3 Tips and Tricks(猫粮)



ActionScript 3 Tips and Tricks(1)
Change the frame rate of your movie

在你的影片中动态改变帧率


--------------------------------------------------------------------------------



Using ActionScript 3, you can dynamically change the frame rate of your movie using the Stage class.


使用ActionScript3,你可以在影片中使用Stage类动态地改变帧速。

The Stage class (flash.display.Stage) is the class

assigned to the stage object which

is accessible from your main movie sprite/movie clip (or others within the same security sandbox)

using the stage property.

Stage这个类(flash.display.Stage)指向在你影片中所有可以用stage属性可以被访问到的影片对象。(或者其他位于相同的安全砂箱的对象)

The stage object has a frameRate property which can contain any value between 0.01 and 1000 and determines the frame rate at which the Flash player plays back your movie. Changing this value lets you change the frame rate at runtime.

Stage对象有一个frameRate属性可以被赋值从0.01到1000的任意一个数,这个就是flash播放器播放你影片时候的帧率。你可以在运行时改变这个属性从而达到动态改变帧率的目的。

下面是代码:

代码

// 把帧率改变成12fps:
stage.frameRate = 12;
==========================================
ActionScript 3 Tips and Tricks(2)
Class scope is now bound to class methods

类作用域现在和类方法绑定在一起了


--------------------------------------------------------------------------------

ActionScript 3 is entirely class-based.

ActionScript 3 是一个完全基于类的语言。

When you create classes, you create variables and functions (methods) which relate to and work with that class and instances of that class.

当你创建类的时候,你除了创建这个类的实例外,同时也创建了和这个类相关的变量和方法。

Unlike ActionScript 2, methods in ActionScript 3 now retain their class scope when called, even if assigned to another object and called from that object, or if used with Function.call and Function.apply.

和ActionScript 2不同,在ActionScript 3中的类中的方法的作用域仍然保留在这个类里面,而不管是不是其他的类调用这个方法。可能有点难以明白,看代码吧(即使看了代码也不明白的)
大概就是想说 保持this的指向吧

Example:

代码:

package {
  import flash.display.Sprite;
  
  public class ClassScope extends Sprite {
    
    public function ClassScope() {   
      traceThis(); //输出: "Class Instance"
      
      var obj:Object = new Object();
      obj.traceThis = traceThis;
      obj.traceThis(); //输出: "Class Instance"
      
      traceThis.call(new Sprite()); //输出: "Class Instance"
    }

    public override function toString():String {
      return "Class Instance";
    }
    
    public function traceThis():void {
      trace(this);
    }
  }
}

==========================================
ActionScript 3 Tips and Tricks(3)
Graphics Object and the Drawing API

图形对象和绘图API


--------------------------------------------------------------------------------

Like ActionScript 1 and 2, ActionScript 3 also has a drawing API that allows you to draw vector lines and shapes dynamically in movie clips and sprites.

 

和ActionScript 1、2一样,ActionScript 3同样拥有一个绘图的API。这个API同样可以让你的movie clips 和 sprites中动态地生成出矢量的线和形状。

 

With ActionScript 3, however, the drawing API is now used off of an object within display objects (movie clips, sprites, etc.) defined as graphics (flash.display.Graphics).

 

然而在ActionScript 3中,绘图API,被单独定义成graphics (flash.display.Graphics),不再和显示对象(movie clips, sprites, 等等)有什么联系。

 

This graphics property represents the dynamic drawing layer where drawing API drawings exist.

 

图形对象拥有各种绘图方法用来在内部绘制图形。 //FlashseerBBS

 

Like before, it is placed below all children of the target object.

 

和以前一样,新添加的绘图对象位于所有显示的对象之下

 

Also, in ActionScript 3, you have new methods that help you more easily create rectangles, circles, and even rounded rectangles.

 

在ActionScript 3中,你也有新的方法来更方便地创建矩形,圆形,甚至圆角矩形。

 

These include:

 

API包含:

drawCircle(x:Number, y:Number, radius:Number):void
drawEllipse(x:Number, y:Number, width:Number, height:Number):void
drawRect(x:Number, y:Number, width:Number, height:Number):void
drawRoundRect(x:Number, y:Number, width:Number, height:Number, ellipseWidth:Number, ellipseHeight:Number):void

Example:

例子:

ActionScript Code:

// draw a blue rounded rectangle:

//绘制一个蓝色的圆角矩形
var square:Sprite = new Sprite();
square.graphics.beginFill(0xFF);
square.graphics.drawRoundRect(0, 0, 100, 50, 10, 10);
square.graphics.endFill();
addChild(square);

==========================================
ActionScript 3 Tips and Tricks(4)
New Variable Types

新的变量类型


--------------------------------------------------------------------------------

ActionScript 3 supports a wide range of variable types including some which were not present in previous versions of ActionScript. Basic types for AS3 include:



ActionScript 3支持和很多变量类型。基本类型包括:


Primitive:

 

简单类型

Boolean
int
null
Number
String
uint
undefined
Complex:

 

复杂类型

Object
Array
Date
Error
Function
RegExp
XML
XMLList
 


Additional types also exist that relate to their classes; ex: Matrix (flash.geom.Matrix), Shape (flash.display.Shape), URLRequest (flash.net.URLRequest), etc.



另外还有一些类型是和他们自己的类有联系的。例如:Matrix (flash.geom.Matrix), Shape (flash.display.Shape), URLRequest (flash.net.URLRequest), 等等。

 

Things to note:

 

有事要注意哦

The special Void type has changed in AS3 to be lowercase (void not Void)
在AS3中Void类型变成了void(从大写到小写)
There's a new * type that is used to represent any data type. This should be used instead of ommitting typing information for your variables.
有一个新的数据类型叫*,它是用来描述任意的数据类型。如果你不想为你的变量指定任何的数据类型,用它没错。
ActionScript Code:

var anything:*;

The XML type is not the same as the XML type in ActionScript 1 and 2. The old XML type (object) is now defined as XMLObject. XML now references the new E4X-based XML object.
XML类型和ActionScript 1 、2的XML类型是不同的。以前的XML类型现在被改名为XMLObject。现在的XML是指新的基于E4x的XML对象。
int and uint are new primitive number data types for integer (numbers without decimal values) and unsigned integer (numbers without decimal values that also cannot be negative). These can be useful for values which are not supposed to have decimal values such as loop iterators. The int data type will provide a small perfomance boost when used over Number in most cases, but uint should only be used when necessary such as with color values.
Int 和uint是新简单数据类型,他们分别代表了整数和无符号整数。这样对于不需要小数点的运算是很有利的,例如做循环的计数器。大多数情况下,使用int数据代替Number类型会有一小点的性能提升,但是对于unit,有必要的时候再使用它,例如显示没有负值的颜色值.
==========================================
ActionScript 3 Tips and Tricks(5)
Display Objects

显示对象


--------------------------------------------------------------------------------

ActionScript 3 now has a new collection of "display objects" which includes those objects that can be seen on the screen or added to the "display list."

AS3有一个新的集合:显示对象。这个集合包含了所有可以在舞台上看到或者可以被添加到显示列表中的对象。

 

This goes beyond the simple movie clip, button, and text field objects that ActionScript had access to before.

包括以前的MovieClip,button和textField对象。AS3的显示对象有:(FlashseerBBS)

 

AS3 display objects include

AVM1Movie
Bitmap
Loader
MorphShape*
MovieClip
Shape
SimpleButton
Sprite
StaticText*
TextField
Video
*Are for referencing pre-existing objects existing on the timeline; you cannot create them via AS.

AVM1Movie represents a movie created with ActionScript 1 or 2.

AVM1Movie指的是用ActionScript 1 或者 2创建的影片。

 

Those movies use ActionScript Virtual Maching 1 where AS3 movies use AVM2. AVM2 movies can play AVM1 movies, but cannot interact with them (their ActionScript) using AS3.

这些影片使用的是ActionScript虚拟机1(AVM1),然而AS3的影片是使用ActionScript虚拟机2(AVM2)。AVM2可以显示AVM1的影片,但是不能和他们进行交互。


Bitmaps are bitmap objects. You can specify their imagery with BitmapData objects or they can be bitmaps from files.

Bitmaps是bitmap对象。你可以使用BitmapData对象来创建或者是修改他们,他们也可以

从bitmap文件中加载。





Loader objects are display objects that load external content into them. This content can be images or other SWF movies.

Loader对象可以把外来的文件加载进去。外来的文件可以是图像或者是SWF影片。


MorphShapes are shape tweens created in the timeline.

MorphShapes是在时间轴上创建的图形。(FlashseerBBS)

 

Though you cannot create them in ActionScript, you can access those that exist on the timeline already using ActionScript and they are of the type MorphShape.

尽管你不能用ActionScript创建他们,但是你可以用ActionScript访问和控制他们。


MovieClips are the movie clips you know and love.

MovieClips就是以前你熟悉的movie clips。


Shapes are stripped down movie clips that essentially only contain a graphics object for drawing in with the vector drawing API.

Shapes是一个仅仅包含graphics对象的movie clips,它一个是用于绘矢量图的图形容器。

 

Using Shapes instead of MovieClips or Sprites can help conserve memory

使用Shapes代替MovieClip或者Sprites可以节省内存。


Sprite objects are essentially movie clips without timelines. This is your most common display object in AS3 and usually the one extended when creating your own display object subclasses.

Sprite对象本质上就是一个没有时间轴的movie clips。在AS3中这个是最常见的显示对象。

而且,当你创建自己的显示对象的时候,它是最有机会被继承的。

 

StaticText, like MorphShapes, cannot be created with ActionScript instead referening static text objects that are pre-existing on the Flash timeline.

StaticText和MorphShapes一样不能用ActionScript创建


TextField objects include dynamic and input text.

TextField 对象包括动态和输入的内容


Video objects represent Flash video.

Video对象指Flash video


好的习惯
blogging,sleep before 12 o'clock,drink a cup of milk are good habits..but i can't follow.
i just want to post aritcles,in my poor english.something serious happend and that change my mind..i accept it and begin to follow..i just want more more money and freedom.the other is not important. i would not do the unnecessary from now on.
严重自卑阶段,勿扰。


浙ICP备06020153号-1