- 浏览: 24945 次
- 性别:
- 来自: 现在沈阳
最新评论
-
252831020:
未完。 就不要整上来了。。
Android动态壁纸开发 -
dafei2599:
<div class="quote_title ...
Eclipse结合SVN进行版本控制在执行更新时遇到的问题 -
huajuande:
我怎么加了也不好使啊??是不是还有什么地方需要修改啊??谢谢啦 ...
Eclipse结合SVN进行版本控制在执行更新时遇到的问题
原文地址:http://www.kirupa.com/forum/showthread.php?t=223798
原文作者:senocular
原文目录:
1. Change the frame rate of your movie
2. Abstract Classes
3. Deep Object Copies with ByteArray
4. Determine Instance Class or Superclass
5. Multiple Arguments in trace()
6. Loading Text and XML with URLLoader
7. Get Sound Spectrum Information
8. Garbage Collection: Reference Counting & Mark and Sweep
9. Weak References
10. MXMLC: SWF Metadata Tag
11. TextField.appendText()
12. Access to stage and root
13. No More Color Class; Use ColorTransform
14. Array.indexOf (Array.lastIndexOf())
15. System.totalMemory
16. Closing Net Connections
17. AVM2 (AS3) to AVM1 (AS2/AS1) Communication via LocalConnection
18. Class member enumeration
19. Key.isDown in AS3
20. Scale and Alpha Ranges
21. Available ActionScript packages
22. Numeric Calculations: Number vs. int Speed
23. Getting Around globally accessible _root and _global
24. ActionScript 2 to ActionScript 3 Converter
25. Accessing FlashVars and HTML Parameters
26. ActionScript Speed Through Typing
27. LivePreview and the LivePreviewParent class
28. Flex Component Kit for Flash CS3
29. Loading URL encoded Variables
30. Interactive Masks
31. No _lockroot
General:
1. 动态改变帧频:
// change frame rate to 12 fps:
stage.frameRate = 12;
2. Abstract Classes
as3不支持抽象类,但有几个内置的抽象类
DisplayObject
InteractiveObject
DisplayObjectContainer
Graphics
as3中这意味着不能实例化这些类,也不能继承他们 ,以下为错误操作:
// 错误1
var myObj:InteractiveObject = new InteractiveObject(); // ERROR
// 错误2
package {
import flash.display.DisplayObject;
public class MyDisplay extends DisplayObject{
public function MyDisplay (){
// ERROR
}
}
}
3. Deep Object Copies with ByteArray
as3中很容易使用(flash.utils.ByteArray)类来进行对象的深拷贝,深拷贝不只拷贝引用,而是拷贝整个相关对象,
例如一个array里包含一个object引用,这个object也将被拷贝
注意:这个方法通常用来拷贝一般的object
拷贝函数:
function clone(source:Object):* {
var copier:ByteArray = new ByteArray();
copier.writeObject(source);
copier.position = 0;
return(copier.readObject());
}
使用方法:
newObjectCopy = clone(originalObject);
4. Determine Instance Class or Superclass
as3中可以很容易的获取某个实例所属的类和父类的类名,使用这两个方法
getQualifiedClassName (flash.utils.getQualifiedClassName).
getQualifiedSuperclassName (flash.utils.getQualifiedSuperclassName)
var sprite:Sprite = new Sprite();
trace(getQualifiedClassName(sprite)); // "flash.display::Sprite
trace(getQualifiedSuperclassName(sprite)); // "flash.display::DisplayObjectContainer"
你甚至可以由字符串获得类的引用,使用这个方法
getDefinitionByName (flash.utils.getDefinitionByName).
getDefinitionByName("flash.display::Sprite")); // [class Sprite]
5. Multiple Arguments in trace()
as3
trace(value1, value2, value3);
as1,as2
trace([value1, value2, value3]);
6. Loading Text and XML with URLLoader
var loader:URLLoader;
// ...
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, xmlLoaded);
var request:URLRequest = new URLRequest("file.xml");
loader.load(request);
//...
function xmlLoaded(event:Event):void {
var myXML:XML = new XML(loader.data);
//...
}
7.Get Sound Spectrum Information
(flash.media.SoundMixer)类的computeSpectrum静态方法可以把正在播放的声谱信息转成ByteArray,由此你可以想到办法把声谱可视化显示出来
// play sound...
var spectrumInfo:ByteArray = new ByteArray();
SoundMixer.computeSpectrum(spectrumInfo);
// spectrumInfo is now a byte array with sound spectrum info
具体可视化的方法可以看swfdong那里的教程 :)
8. Garbage Collection: Reference Counting & Mark and Sweep
垃圾回收机制包含两个关键:
(1)Reference Counting (引用数) :
引用数就是在内存中引用同一个object的变量多少,每增加一个变量引用该object,引用数就+1
var a:Object = new Object(); // new Object in memory given reference count of 1
var b:Object = a; // Object now has reference count of 2
无论什么时候,当没有变量引用该object的时候,垃圾回收就会把他们回收了
delete a; // Object has reference count of 1
delete b; // Object has reference count of 0, removed from memory
注意delete只能删除非成员变量,而且删除的是引用该object的变量而不是将object从内存中删除,那是垃圾回收器要做的事
看下边这种情况:
var a:Object = new Object(); // reference(a) count 1
var b:Object = new Object(); // reference(b) count 1
a.b = b; // reference(b) count 2
b.a = a; // reference(a) count 2
delete a; // reference(a) count 1
delete b; // reference(b) count 1
虽然a和b变量被删除了,而且我们再也不能用程序访问到他们了,但他们仍然存留在内存中~这种情况下垃圾回首器就没有办法了吗?错!这是记号清理要做的!
(2)Mark and Sweep (记号清理):
Mark and Sweep简单来说就是一种扫描机制,如下图,从root开始,扫到对象就mark一下,并扫描这个对象,等待全扫描完了,没有mark的自然是没有用的了,就会被从内存中删掉了.
[root] <- scan...
[objectRef (marked)] <- scan...
[objectRef (marked)] <- scan...
[objectRef (marked)] <- scan...
[objectRef (marked)] <- scan...
[objectRef (marked)] <- scan...
...
[delete all objects not marked]
当然这种扫描是昂贵的,需要很长时间才能发生一次,所以不要指望他了,编程的时候多注意引用数就可以了
9. Weak References
使用弱引用来引用对象,不会被垃圾回收器视为有效的引用数。这样可以帮助垃圾回收器的工作
所以使用弱引用这是一种比较好的编程习惯,使你不会在不经意间错误的引用到了某个object导致这个object不能被从内存中卸载~~~
但不是哪里都可以使用弱引用的,as3中有两处可以使用:
(1)在Directionary类的构造函数中传入true
var dict:Dictionary = new Dictionary(true); // use weak references as keys
var obj:Object = new Object();
dict[obj] = true;
delete obj; // 虽然dict中有引用到obj,但并不是一个有效引用,所以obj仍然会被垃圾回收
(2)在EventDispatcher的addEventListener 的第5个参数指定true
// addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
addEventListener(MouseEvent.CLICK, clickHandler, false, 0 true); // use weak references
10. MXMLC: SWF Metadata Tag
如果你用mxmlc编译swf的话,可以使用swf metadata tag来指定swf的一些属性
支持以下属性:
width
height
frameRate
backgroundColor
例子:
package {
[SWF(width="500", height="450", frameRate="24", backgroundColor="#FFFFFF")]
public class MyApp extends Sprite {
}
}
11.TextField.appendText()
(flash.text.TextField)类多了一个appendText()方法
var my_tf = new TextField();
my_tf.text = "Hello";
my_tf.appendText(" world!"); // my_tf.text == "Hello world!"
相当于以前的my_tf.text+=" world!" ,只是效率提高了
12. Access to stage and root
* 在as3中,当swf被loaded到player中时 stage object 是最顶端的容器,所有其他东西都在它里边,包括root在内
* 一个application中只有一个stage,却可以有若干个 root ,比如有外部内容被Loader类加载近来的时候
* 所有的DisplayObject (flash.display.DisplayObject)都有 stage 和 root 属性,但只有当他们被直接或间接的加入到display list 中的时候才有值,否则他们都为 null 。
* stage 属性 如果有值,那么他一直指向 stage 对象 , root 却不同 ,具体哪不同,下边懒得翻引用原话 - -b
引用
For the stage, root always references the stage
For the main timeline of the SWF and all display objects within it, root references the main timeline
If an object is added directly to the stage from any timeline, the root property for it and its children references the stage
For display objects in loaded SWF files, root references the main timeline of that SWF file
For loaded bitmap images, root references the Bitmap instance of the image loaded
Loader objects used to load external SWFs and images follow the rules of all other display objects within the SWF it is being used
* 在as1 ,as 2中所有类都是在时间轴上创建的,这使的所有东东都能访问_root ,在as3中就不同了,如果你不是DisplayObject的话,访问root(或stage)会很困难,你需要一些技巧
技巧1: 写一个TopLevel类,让Document类继承它,通过TopLevel类访问stage
package {
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
public class TopLevel extends MovieClip {
public static var stage:Stage;
public static var root:DisplayObject;
public function TopLevel() {
TopLevel.stage = this.stage;
TopLevel.root = this;
}
}
}
package {
public class MyDocumentClass extends TopLevel {
public function MyDocumentClass() {
// code
}
}
}
package {
public class RandomClass {
public function RandomClass() {
trace(TopLevel.stage); // [object Stage]
}
}
}
当然这很不oo也很不雅观~~~如果别人的Document类没继承TopLevel类就会有问题出现
技巧2 : 传递引用
类似这样通过构造函数将stage传进去
package {
import flash.display.Stage;
public class CustomObject {
private var stage:Stage;
public function CustomObject(stageRef:Stage) {
// stage access through
// constructor argument
stage = stageRef;
}
}
}
作者给了一个 StageDetection 类
地址:http://www.senocular.com/flash/actionscript.php?file=ActionScript_3.0/com/senocular/events/StageDetection.as
好象是用于检测某个display object 的 stage 或 root 属性是否存在,然后才能把stage的引用传给非display object
(N神注:作者可能用的老版本flex?貌似现在的版本只要监听DisplayObject 的 addedToStage 或removedFromStage 事件就可以检查是stage和root的存在,不需要这个自定义的StageDetection 类吧...还请明人指点)
13. No More Color Class; Use ColorTransform
as3 中彻底没了flash8就不推荐使用了的 Color类 改用 ColorTransform类
注意ColorTransform 的rgb属性已经改名为color
// creates a red square
var square:Shape = new Shape();
square.graphics.beginFill(0x000000);
square.graphics.drawRect(0, 0, 100, 100);
var colorTransform:ColorTransform = square.transform.colorTransform;
colorTransform.color = 0xFF0000;
square.transform.colorTransform = colorTransform;
addChild(square);
14. Array.indexOf (Array.lastIndexOf())
Array类多了两个方法 indexOf 和 lastIndexOf
AS3 function indexOf(searchElement:*, fromIndex:int = 0):int
AS3 function lastIndexOf(searchElement:*, fromIndex:int = 0x7fffffff):int
跟String类的同名方法差不多 ,返回指定元素位置,如果没有返回 -1
var sprite:Sprite = new Sprite();
var object:Object = new Object();
var boolean:Boolean = true;
var number:Number = 10;
var array:Array = new Array(sprite, object, number);
trace(array.indexOf(sprite)); // 0
trace(array.indexOf(number)); // 2
trace(array.indexOf(boolean)); // -1
15. System.totalMemory
System 类 (flash.system.System) 有一个新属性叫做 totalMemory,返回当前flash player占用的内存
var o:Object = new Object();
trace(System.totalMemory); // 4960256
var o:MovieClip = new MovieClip();
trace(System.totalMemory); // 4964352
16. Closing Net Connections
as1,2时候,当loading开始后,你就不能关闭这个连接了,在as3世界里,即使loading开始了,你也可以停止它
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest("image.jpg");
loader.load(request);
addChild(loader);
// 如果3秒钟还没loading完,就关闭连接
var abortID:uint = setTimeout(abortLoader, 3000);
// abort the abort when loaded
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, abortAbort);
function abortLoader(){
try {
loader.close();
}catch(error:Error) {} //注意这里有可能抛出IOError
}
function abortAbort(event:Event){
clearTimeout(abortID);
}
17. AVM2 (AS3) to AVM1 (AS2/AS1) Communication via LocalConnection
由于as3与as1,2虚拟机的不同导致as1,2 与as3不能直接沟通,如果需要的话必须要间接的使用
LocalConnection AS2
http://livedocs.macromedia.com/flash/8/main/00002338.html
LocalConnection AS3 (flash.net.LocalConnection)
http://livedocs.macromedia.com/flex/2/langref/flash/net/LocalConnection.html
在as2中
// ActionScript 2 file, AS2animation.fla
// one movie clip animation named animation_mc on the timeline
// local connection instance to receive events
var AVM_lc:LocalConnection = new LocalConnection();
// stopAnimation event handler
AVM_lc.stopAnimation = function(){
animation_mc.stop();
}
// listen for events for "AVM2toAVM1"
AVM_lc.connect("AVM2toAVM1");
as3中
// ActionScript 3 file, AS3Loader.fla
// local connection instance to communicate to AVM1 movie
var AVM_lc:LocalConnection = new LocalConnection();
// loader loads AVM1 movie
var loader:Loader = new Loader();
loader.load(new URLRequest("AS2animation.swf"));
addChild(loader);
// when AVM1 movie is clicked, call stopPlayback
loader.addEventListener(MouseEvent.CLICK, stopPlayback);
function stopPlayback(event:MouseEvent):void {
// send stopAnimation event to "AVM2toAVM1" connection
AVM_lc.send("AVM2toAVM1", "stopAnimation");
}
as3 movie把as2的movie加载进来然后调用as2的stopAnimation
18. Class member enumeration
as3中只有dynamic class 中的dynamic definitions才可以被枚举(就是for in ),例如下边的class就没有可枚举的成员
package {
public class EnumerateClass {
public var variable:String = "value";
public function method():void {}
}
}
var example:EnumerateClass = new EnumerateClass();
for (var key:String in example) {
trace(key + ": " + example[key]); // 没有输出
}
即使上边的class改成dynamic的,也是没有输出,为什么呢?
因为里边的变量和方法是他们自己的,而并不是动态(dynamic)填加的,只有动态填加的属性可以被for in
Object类有个 setPropertyIsEnumerable方法,可以控制某个属性是否可枚举,但它只对dynamic属性有效
package {
public dynamic class EnumerateClass {
public var variable:String = "value";
public function method():void {}
public function EnumerateClass(){
this.dynamicVar = 1;
this.dynamicVar2 = 2;
this.setPropertyIsEnumerable("dynamicVar2", false);
}
}
}
上边的dynamic类有两个dynamic属性, dynamicVar 和 dynamicVar2 ,满足条件,都应该是可枚举的
但调用 setPropertyIsEnumerable("dynamicVar2", false);阻止了枚举 dynamicVar2
var example:EnumerateClass = new EnumerateClass();
for (var key:String in example) {
trace(key + ": " + example[key]); // dynamicVar: 1
}
propertyIsEnumerable方法可以测试某一属性是否可枚举
trace(example.propertyIsEnumerable("variable")); // false
trace(example.propertyIsEnumerable("dynamicVar")); // true
trace(example.propertyIsEnumerable("dynamicVar2")); // false
19. Key.isDown in AS3
在as1,2时代,尤其是游戏中经常会用到 Key.isDown ,但到了as3,Key类已经不存在了,但我们可以通过些技巧实现这个类
package {
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
/**
* The Key class recreates functionality of
* Key.isDown of ActionScript 1 and 2. Before using
* Key.isDown, you first need to initialize the
* Key class with a reference to the stage using
* its Key.initialize() method. For key
* codes use the flash.ui.Keyboard class.
*
* Usage:
* Key.initialize(stage);
* if (Key.isDown(Keyboard.LEFT)) {
* // Left key is being pressed
* }
*/
public class Key {
private static var initialized:Boolean = false; // marks whether or not the class has been initialized
private static var keysDown:Object = new Object(); // stores key codes of all keys pressed
/**
* Initializes the key class creating assigning event
* handlers to capture necessary key events from the stage
*/
public static function initialize(stage:Stage) {
if (!initialized) {
// assign listeners for key presses and deactivation of the player
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
stage.addEventListener(Event.DEACTIVATE, clearKeys);
// mark initialization as true so redundant
// calls do not reassign the event handlers
initialized = true;
}
}
/**
* Returns true or false if the key represented by the
* keyCode passed is being pressed
*/
public static function isDown(keyCode:uint):Boolean {
if (!initialized) {
// throw an error if isDown is used
// prior to Key class initialization
throw new Error("Key class has yet been initialized.");
}
return Boolean(keyCode in keysDown);
}
/**
* Event handler for capturing keys being pressed
*/
private static function keyPressed(event:KeyboardEvent):void {
// create a property in keysDown with the name of the keyCode
keysDown[event.keyCode] = true;
}
/**
* Event handler for capturing keys being released
*/
private static function keyReleased(event:KeyboardEvent):void {
if (event.keyCode in keysDown) {
// delete the property in keysDown if it exists
delete keysDown[event.keyCode];
}
}
/**
* Event handler for Flash Player deactivation
*/
private static function clearKeys(event:Event):void {
// clear all keys in keysDown since the player cannot
// detect keys being pressed or released when not focused
keysDown = new Object();
}
}
}
20.Scale and Alpha Ranges
值得注意一下的是,as3中好多属性值的范围变化了,有些值原来范围是0 到 100 ,现在变成了0 到 1 ,例如下边几个,要留心一下
ActionScript 2.0 | ActionScript 3.0
_xscale: 0 - 100 | scaleX: 0 - 1
_yscale: 0 - 100 | scaleY: 0 - 1
_alpha: 0 - 100 | alpha: 0 - 1
21. Available ActionScript packages
AS3 package 概要
* flash 包 (player的核心类包,永远可用)
* mx 包 (flex 专用类包,flex 的组件们需要)
* fl 包 (flash 专用类包,flash组件等)
* adobe 包 (flash 专用类包,绘图工具扩展等)
更多详细包内容,看文档
Flex: http://livedocs.adobe.com/flex/201/langref/
Flash: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/
Apollo: http://livedocs.adobe.com/apollo/1.0/aslr/
注意: Apollo相关的类在 flash和mx包里
22. Numeric Calculations: Number vs. int Speed
比较Number类型和新出现的int类型速度
*只有在用到 bitwise operations (<<, >>, &, ^, and |) 的时候 int 类型比较快,例如
var valueN:Number = 10;
result = valueN << 2; // not so fast
var valueI:int = 10;
reesult = valueI << 2; // Fast!
*其他情况下声明为Number比较快
23. Getting Around globally accessible _root and _global
as1 ,2中任何地方都能访问到_root ,_global ,这样可以很简单的保存变量或函数到这里,但在as3中已经没有_global了,root 也只有Disobject在显示列表里时才会得到,如果你非要这么做的话,应该自己写一个glo类,里边用一个静态变量bal指向一个Object,下边是代码
package {
public class glo {
public static var bal:Object = new Object();
}
}
现在可以把 gol.bal 当成以前的_root或_global用了
trace(glo.bal.foo); // undefined
glo.bal.foo = "bar";
trace(glo.bal.foo); // bar
24. ActionScript 2 to ActionScript 3 Converter
Patrick Mineault(http://www.5etdemi.com/blog/) 用php写了一个as2 -->as3 转换器,不是百分之百准确但也不错
online 版本 :http://www.5etdemi.com/convert
下载 :http://www.5etdemi.com/convert/convert.zip
25. Accessing FlashVars and HTML Parameters
你可以用HTML中的 object/embed 代码向镶入的SWF传递变量。
有两种方法:
1。在swf的url后边加变量(query string)
<!-- URL Variables -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="640" height="500" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="flashMovie.swf?myVar=1" />
<param name="quality" value="high" />
<param name="bgcolor" value="#EFF7F6" />
<embed src="flashMovie.swf?myVar=1" quality="high" bgcolor="#EFF7F6" width="640" height="500" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
2.使用FlashVars
<!-- FlashVars -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="flashMovie.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<param name="FlashVars" value="myVar=1" />
<embed src="flashMovie.swf" FlashVars="myVar=1" quality="high" bgcolor="#FFFFFF" width="550" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
在as2中这些变量会被简单的声明到_root上,但在as3中有所改变。现在这些变量被放到了root下的parameters对象下,上边HTML传的值可以这样访问:
root.loaderInfo.parameters.myVar;
26. ActionScript Speed Through Typing
考虑到效率,尽量把你的变量声明类型,如果可能的话避免使用dynamic class
27. LivePreview and the LivePreviewParent class
as2 的组件使用_global下的isLivePreview属性来判断是否是在Flash IDE中预览,as3中这个属性不见了,取而代之的是你可以检查这个组件的parent是否为 LivePreviewParent 类的实例
var isLivePreview:Boolean = (parent != null && getQualifiedClassName(parent) == "fl.livepreview::LivePreviewParent");
( N神注:as2时代的isLivePreview这个属性偶也没用过,不清楚这个翻译的对不对 - -b )
28. Flex Component Kit for Flash CS3
Flex Component Kit for Flash CS3(在Adobe Labs里) 允许把flash中做的交互内容,在Flex中当成Flex comonnet来用
现在可以很容易的使Flash symbol继承我们的新 UIMovieClip 类
从而使
* flash 组件放在一个Flex container里,所有layout会很好的工作
* flash 的帧标签被完全转换为 Flex 的state和 transition
* 只要简单的填加个 SWC 到 library path里Flex Builder就可以有flash组件的语法提示了
* Simple JSFL commands are available to set up new documents as well as publish the Flex-enabled SWC (这句没看明白- -b)
29. Loading URL encoded Variables
URLLoader类(flash.net.URLLoader) 在as3中用来读外部文本文件.当一个外部文件被load后,它的内容会被存储在URLLoader实例的data属性里,一般情况下无论外部文件是什么格式,都会被以raw text形似读取,如果读变量可能需要改一下dataFormat属性
URLLoader类的dataFormat属性决定被加载数据的格式。 dataFormat属性的可选值在 URLLoaderDataFormat 类中(flash.net.URLLoaderDataFormat)
可选值为:
BINARY - 指定按2禁止数据接受
TEXT - 指定当成文本接受
VARIABLES - 指定当作 URL-encoded变量接受
指定URLLoaderDataFormat.VARIABLES 作为 URLLoader的 dataFormat属性, 被加载的数据将被当作一组变量,而不是字符串
data属性将为包含被加载变量的一个 URLVariables 类 (flash.net.URLVariables)的实例
ActionScript 代码:
var loader:URLLoader = new URLLoader();
// specify format as being variables
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, varsLoaded);
// vars.txt contents: foo=bar&foo2=bar2
loader.load(new URLRequest("vars.txt"));
function varsLoaded (event:Event):void {
trace(loader.data is URLVariables); // true
trace(loader.data.foo); // bar
trace(loader.data.foo2); // bar2
}
30. Interactive Masks
默认情况下,当一个对象 mask 另一个对象的时候,前者(这个遮照)将失去它的交互性,例如,一个sprite有一个 click事件,但当这个sprite成为一个遮照的时候,这个click事件就不起作用了
如果你想让一个对象作为遮照的时候也拥有交互性,就指定它的buttonMode属性为true
ActionScript Code:
maskInstance.buttonMode = true;
31. No _lockroot
ActionScript 3 没有 _lockroot属性了.
_lockroot 属性是在Flash Player 7 引入近来的,_lockroot属性原本用来确保被load进来的movie的_root属性始终引用它自己而不是主swf在 ActionScript 3 中, 所有的root引用永远指向文件本身的root 就像_lockroot已经在那了一样。( N神注:想引用原来主swf的root应该用stage了)
原文作者:senocular
原文目录:
1. Change the frame rate of your movie
2. Abstract Classes
3. Deep Object Copies with ByteArray
4. Determine Instance Class or Superclass
5. Multiple Arguments in trace()
6. Loading Text and XML with URLLoader
7. Get Sound Spectrum Information
8. Garbage Collection: Reference Counting & Mark and Sweep
9. Weak References
10. MXMLC: SWF Metadata Tag
11. TextField.appendText()
12. Access to stage and root
13. No More Color Class; Use ColorTransform
14. Array.indexOf (Array.lastIndexOf())
15. System.totalMemory
16. Closing Net Connections
17. AVM2 (AS3) to AVM1 (AS2/AS1) Communication via LocalConnection
18. Class member enumeration
19. Key.isDown in AS3
20. Scale and Alpha Ranges
21. Available ActionScript packages
22. Numeric Calculations: Number vs. int Speed
23. Getting Around globally accessible _root and _global
24. ActionScript 2 to ActionScript 3 Converter
25. Accessing FlashVars and HTML Parameters
26. ActionScript Speed Through Typing
27. LivePreview and the LivePreviewParent class
28. Flex Component Kit for Flash CS3
29. Loading URL encoded Variables
30. Interactive Masks
31. No _lockroot
General:
1. 动态改变帧频:
// change frame rate to 12 fps:
stage.frameRate = 12;
2. Abstract Classes
as3不支持抽象类,但有几个内置的抽象类
DisplayObject
InteractiveObject
DisplayObjectContainer
Graphics
as3中这意味着不能实例化这些类,也不能继承他们 ,以下为错误操作:
// 错误1
var myObj:InteractiveObject = new InteractiveObject(); // ERROR
// 错误2
package {
import flash.display.DisplayObject;
public class MyDisplay extends DisplayObject{
public function MyDisplay (){
// ERROR
}
}
}
3. Deep Object Copies with ByteArray
as3中很容易使用(flash.utils.ByteArray)类来进行对象的深拷贝,深拷贝不只拷贝引用,而是拷贝整个相关对象,
例如一个array里包含一个object引用,这个object也将被拷贝
注意:这个方法通常用来拷贝一般的object
拷贝函数:
function clone(source:Object):* {
var copier:ByteArray = new ByteArray();
copier.writeObject(source);
copier.position = 0;
return(copier.readObject());
}
使用方法:
newObjectCopy = clone(originalObject);
4. Determine Instance Class or Superclass
as3中可以很容易的获取某个实例所属的类和父类的类名,使用这两个方法
getQualifiedClassName (flash.utils.getQualifiedClassName).
getQualifiedSuperclassName (flash.utils.getQualifiedSuperclassName)
var sprite:Sprite = new Sprite();
trace(getQualifiedClassName(sprite)); // "flash.display::Sprite
trace(getQualifiedSuperclassName(sprite)); // "flash.display::DisplayObjectContainer"
你甚至可以由字符串获得类的引用,使用这个方法
getDefinitionByName (flash.utils.getDefinitionByName).
getDefinitionByName("flash.display::Sprite")); // [class Sprite]
5. Multiple Arguments in trace()
as3
trace(value1, value2, value3);
as1,as2
trace([value1, value2, value3]);
6. Loading Text and XML with URLLoader
var loader:URLLoader;
// ...
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, xmlLoaded);
var request:URLRequest = new URLRequest("file.xml");
loader.load(request);
//...
function xmlLoaded(event:Event):void {
var myXML:XML = new XML(loader.data);
//...
}
7.Get Sound Spectrum Information
(flash.media.SoundMixer)类的computeSpectrum静态方法可以把正在播放的声谱信息转成ByteArray,由此你可以想到办法把声谱可视化显示出来
// play sound...
var spectrumInfo:ByteArray = new ByteArray();
SoundMixer.computeSpectrum(spectrumInfo);
// spectrumInfo is now a byte array with sound spectrum info
具体可视化的方法可以看swfdong那里的教程 :)
8. Garbage Collection: Reference Counting & Mark and Sweep
垃圾回收机制包含两个关键:
(1)Reference Counting (引用数) :
引用数就是在内存中引用同一个object的变量多少,每增加一个变量引用该object,引用数就+1
var a:Object = new Object(); // new Object in memory given reference count of 1
var b:Object = a; // Object now has reference count of 2
无论什么时候,当没有变量引用该object的时候,垃圾回收就会把他们回收了
delete a; // Object has reference count of 1
delete b; // Object has reference count of 0, removed from memory
注意delete只能删除非成员变量,而且删除的是引用该object的变量而不是将object从内存中删除,那是垃圾回收器要做的事
看下边这种情况:
var a:Object = new Object(); // reference(a) count 1
var b:Object = new Object(); // reference(b) count 1
a.b = b; // reference(b) count 2
b.a = a; // reference(a) count 2
delete a; // reference(a) count 1
delete b; // reference(b) count 1
虽然a和b变量被删除了,而且我们再也不能用程序访问到他们了,但他们仍然存留在内存中~这种情况下垃圾回首器就没有办法了吗?错!这是记号清理要做的!
(2)Mark and Sweep (记号清理):
Mark and Sweep简单来说就是一种扫描机制,如下图,从root开始,扫到对象就mark一下,并扫描这个对象,等待全扫描完了,没有mark的自然是没有用的了,就会被从内存中删掉了.
[root] <- scan...
[objectRef (marked)] <- scan...
[objectRef (marked)] <- scan...
[objectRef (marked)] <- scan...
[objectRef (marked)] <- scan...
[objectRef (marked)] <- scan...
...
[delete all objects not marked]
当然这种扫描是昂贵的,需要很长时间才能发生一次,所以不要指望他了,编程的时候多注意引用数就可以了
9. Weak References
使用弱引用来引用对象,不会被垃圾回收器视为有效的引用数。这样可以帮助垃圾回收器的工作
所以使用弱引用这是一种比较好的编程习惯,使你不会在不经意间错误的引用到了某个object导致这个object不能被从内存中卸载~~~
但不是哪里都可以使用弱引用的,as3中有两处可以使用:
(1)在Directionary类的构造函数中传入true
var dict:Dictionary = new Dictionary(true); // use weak references as keys
var obj:Object = new Object();
dict[obj] = true;
delete obj; // 虽然dict中有引用到obj,但并不是一个有效引用,所以obj仍然会被垃圾回收
(2)在EventDispatcher的addEventListener 的第5个参数指定true
// addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
addEventListener(MouseEvent.CLICK, clickHandler, false, 0 true); // use weak references
10. MXMLC: SWF Metadata Tag
如果你用mxmlc编译swf的话,可以使用swf metadata tag来指定swf的一些属性
支持以下属性:
width
height
frameRate
backgroundColor
例子:
package {
[SWF(width="500", height="450", frameRate="24", backgroundColor="#FFFFFF")]
public class MyApp extends Sprite {
}
}
11.TextField.appendText()
(flash.text.TextField)类多了一个appendText()方法
var my_tf = new TextField();
my_tf.text = "Hello";
my_tf.appendText(" world!"); // my_tf.text == "Hello world!"
相当于以前的my_tf.text+=" world!" ,只是效率提高了
12. Access to stage and root
* 在as3中,当swf被loaded到player中时 stage object 是最顶端的容器,所有其他东西都在它里边,包括root在内
* 一个application中只有一个stage,却可以有若干个 root ,比如有外部内容被Loader类加载近来的时候
* 所有的DisplayObject (flash.display.DisplayObject)都有 stage 和 root 属性,但只有当他们被直接或间接的加入到display list 中的时候才有值,否则他们都为 null 。
* stage 属性 如果有值,那么他一直指向 stage 对象 , root 却不同 ,具体哪不同,下边懒得翻引用原话 - -b
引用
For the stage, root always references the stage
For the main timeline of the SWF and all display objects within it, root references the main timeline
If an object is added directly to the stage from any timeline, the root property for it and its children references the stage
For display objects in loaded SWF files, root references the main timeline of that SWF file
For loaded bitmap images, root references the Bitmap instance of the image loaded
Loader objects used to load external SWFs and images follow the rules of all other display objects within the SWF it is being used
* 在as1 ,as 2中所有类都是在时间轴上创建的,这使的所有东东都能访问_root ,在as3中就不同了,如果你不是DisplayObject的话,访问root(或stage)会很困难,你需要一些技巧
技巧1: 写一个TopLevel类,让Document类继承它,通过TopLevel类访问stage
package {
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
public class TopLevel extends MovieClip {
public static var stage:Stage;
public static var root:DisplayObject;
public function TopLevel() {
TopLevel.stage = this.stage;
TopLevel.root = this;
}
}
}
package {
public class MyDocumentClass extends TopLevel {
public function MyDocumentClass() {
// code
}
}
}
package {
public class RandomClass {
public function RandomClass() {
trace(TopLevel.stage); // [object Stage]
}
}
}
当然这很不oo也很不雅观~~~如果别人的Document类没继承TopLevel类就会有问题出现
技巧2 : 传递引用
类似这样通过构造函数将stage传进去
package {
import flash.display.Stage;
public class CustomObject {
private var stage:Stage;
public function CustomObject(stageRef:Stage) {
// stage access through
// constructor argument
stage = stageRef;
}
}
}
作者给了一个 StageDetection 类
地址:http://www.senocular.com/flash/actionscript.php?file=ActionScript_3.0/com/senocular/events/StageDetection.as
好象是用于检测某个display object 的 stage 或 root 属性是否存在,然后才能把stage的引用传给非display object
(N神注:作者可能用的老版本flex?貌似现在的版本只要监听DisplayObject 的 addedToStage 或removedFromStage 事件就可以检查是stage和root的存在,不需要这个自定义的StageDetection 类吧...还请明人指点)
13. No More Color Class; Use ColorTransform
as3 中彻底没了flash8就不推荐使用了的 Color类 改用 ColorTransform类
注意ColorTransform 的rgb属性已经改名为color
// creates a red square
var square:Shape = new Shape();
square.graphics.beginFill(0x000000);
square.graphics.drawRect(0, 0, 100, 100);
var colorTransform:ColorTransform = square.transform.colorTransform;
colorTransform.color = 0xFF0000;
square.transform.colorTransform = colorTransform;
addChild(square);
14. Array.indexOf (Array.lastIndexOf())
Array类多了两个方法 indexOf 和 lastIndexOf
AS3 function indexOf(searchElement:*, fromIndex:int = 0):int
AS3 function lastIndexOf(searchElement:*, fromIndex:int = 0x7fffffff):int
跟String类的同名方法差不多 ,返回指定元素位置,如果没有返回 -1
var sprite:Sprite = new Sprite();
var object:Object = new Object();
var boolean:Boolean = true;
var number:Number = 10;
var array:Array = new Array(sprite, object, number);
trace(array.indexOf(sprite)); // 0
trace(array.indexOf(number)); // 2
trace(array.indexOf(boolean)); // -1
15. System.totalMemory
System 类 (flash.system.System) 有一个新属性叫做 totalMemory,返回当前flash player占用的内存
var o:Object = new Object();
trace(System.totalMemory); // 4960256
var o:MovieClip = new MovieClip();
trace(System.totalMemory); // 4964352
16. Closing Net Connections
as1,2时候,当loading开始后,你就不能关闭这个连接了,在as3世界里,即使loading开始了,你也可以停止它
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest("image.jpg");
loader.load(request);
addChild(loader);
// 如果3秒钟还没loading完,就关闭连接
var abortID:uint = setTimeout(abortLoader, 3000);
// abort the abort when loaded
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, abortAbort);
function abortLoader(){
try {
loader.close();
}catch(error:Error) {} //注意这里有可能抛出IOError
}
function abortAbort(event:Event){
clearTimeout(abortID);
}
17. AVM2 (AS3) to AVM1 (AS2/AS1) Communication via LocalConnection
由于as3与as1,2虚拟机的不同导致as1,2 与as3不能直接沟通,如果需要的话必须要间接的使用
LocalConnection AS2
http://livedocs.macromedia.com/flash/8/main/00002338.html
LocalConnection AS3 (flash.net.LocalConnection)
http://livedocs.macromedia.com/flex/2/langref/flash/net/LocalConnection.html
在as2中
// ActionScript 2 file, AS2animation.fla
// one movie clip animation named animation_mc on the timeline
// local connection instance to receive events
var AVM_lc:LocalConnection = new LocalConnection();
// stopAnimation event handler
AVM_lc.stopAnimation = function(){
animation_mc.stop();
}
// listen for events for "AVM2toAVM1"
AVM_lc.connect("AVM2toAVM1");
as3中
// ActionScript 3 file, AS3Loader.fla
// local connection instance to communicate to AVM1 movie
var AVM_lc:LocalConnection = new LocalConnection();
// loader loads AVM1 movie
var loader:Loader = new Loader();
loader.load(new URLRequest("AS2animation.swf"));
addChild(loader);
// when AVM1 movie is clicked, call stopPlayback
loader.addEventListener(MouseEvent.CLICK, stopPlayback);
function stopPlayback(event:MouseEvent):void {
// send stopAnimation event to "AVM2toAVM1" connection
AVM_lc.send("AVM2toAVM1", "stopAnimation");
}
as3 movie把as2的movie加载进来然后调用as2的stopAnimation
18. Class member enumeration
as3中只有dynamic class 中的dynamic definitions才可以被枚举(就是for in ),例如下边的class就没有可枚举的成员
package {
public class EnumerateClass {
public var variable:String = "value";
public function method():void {}
}
}
var example:EnumerateClass = new EnumerateClass();
for (var key:String in example) {
trace(key + ": " + example[key]); // 没有输出
}
即使上边的class改成dynamic的,也是没有输出,为什么呢?
因为里边的变量和方法是他们自己的,而并不是动态(dynamic)填加的,只有动态填加的属性可以被for in
Object类有个 setPropertyIsEnumerable方法,可以控制某个属性是否可枚举,但它只对dynamic属性有效
package {
public dynamic class EnumerateClass {
public var variable:String = "value";
public function method():void {}
public function EnumerateClass(){
this.dynamicVar = 1;
this.dynamicVar2 = 2;
this.setPropertyIsEnumerable("dynamicVar2", false);
}
}
}
上边的dynamic类有两个dynamic属性, dynamicVar 和 dynamicVar2 ,满足条件,都应该是可枚举的
但调用 setPropertyIsEnumerable("dynamicVar2", false);阻止了枚举 dynamicVar2
var example:EnumerateClass = new EnumerateClass();
for (var key:String in example) {
trace(key + ": " + example[key]); // dynamicVar: 1
}
propertyIsEnumerable方法可以测试某一属性是否可枚举
trace(example.propertyIsEnumerable("variable")); // false
trace(example.propertyIsEnumerable("dynamicVar")); // true
trace(example.propertyIsEnumerable("dynamicVar2")); // false
19. Key.isDown in AS3
在as1,2时代,尤其是游戏中经常会用到 Key.isDown ,但到了as3,Key类已经不存在了,但我们可以通过些技巧实现这个类
package {
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
/**
* The Key class recreates functionality of
* Key.isDown of ActionScript 1 and 2. Before using
* Key.isDown, you first need to initialize the
* Key class with a reference to the stage using
* its Key.initialize() method. For key
* codes use the flash.ui.Keyboard class.
*
* Usage:
* Key.initialize(stage);
* if (Key.isDown(Keyboard.LEFT)) {
* // Left key is being pressed
* }
*/
public class Key {
private static var initialized:Boolean = false; // marks whether or not the class has been initialized
private static var keysDown:Object = new Object(); // stores key codes of all keys pressed
/**
* Initializes the key class creating assigning event
* handlers to capture necessary key events from the stage
*/
public static function initialize(stage:Stage) {
if (!initialized) {
// assign listeners for key presses and deactivation of the player
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
stage.addEventListener(Event.DEACTIVATE, clearKeys);
// mark initialization as true so redundant
// calls do not reassign the event handlers
initialized = true;
}
}
/**
* Returns true or false if the key represented by the
* keyCode passed is being pressed
*/
public static function isDown(keyCode:uint):Boolean {
if (!initialized) {
// throw an error if isDown is used
// prior to Key class initialization
throw new Error("Key class has yet been initialized.");
}
return Boolean(keyCode in keysDown);
}
/**
* Event handler for capturing keys being pressed
*/
private static function keyPressed(event:KeyboardEvent):void {
// create a property in keysDown with the name of the keyCode
keysDown[event.keyCode] = true;
}
/**
* Event handler for capturing keys being released
*/
private static function keyReleased(event:KeyboardEvent):void {
if (event.keyCode in keysDown) {
// delete the property in keysDown if it exists
delete keysDown[event.keyCode];
}
}
/**
* Event handler for Flash Player deactivation
*/
private static function clearKeys(event:Event):void {
// clear all keys in keysDown since the player cannot
// detect keys being pressed or released when not focused
keysDown = new Object();
}
}
}
20.Scale and Alpha Ranges
值得注意一下的是,as3中好多属性值的范围变化了,有些值原来范围是0 到 100 ,现在变成了0 到 1 ,例如下边几个,要留心一下
ActionScript 2.0 | ActionScript 3.0
_xscale: 0 - 100 | scaleX: 0 - 1
_yscale: 0 - 100 | scaleY: 0 - 1
_alpha: 0 - 100 | alpha: 0 - 1
21. Available ActionScript packages
AS3 package 概要
* flash 包 (player的核心类包,永远可用)
* mx 包 (flex 专用类包,flex 的组件们需要)
* fl 包 (flash 专用类包,flash组件等)
* adobe 包 (flash 专用类包,绘图工具扩展等)
更多详细包内容,看文档
Flex: http://livedocs.adobe.com/flex/201/langref/
Flash: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/
Apollo: http://livedocs.adobe.com/apollo/1.0/aslr/
注意: Apollo相关的类在 flash和mx包里
22. Numeric Calculations: Number vs. int Speed
比较Number类型和新出现的int类型速度
*只有在用到 bitwise operations (<<, >>, &, ^, and |) 的时候 int 类型比较快,例如
var valueN:Number = 10;
result = valueN << 2; // not so fast
var valueI:int = 10;
reesult = valueI << 2; // Fast!
*其他情况下声明为Number比较快
23. Getting Around globally accessible _root and _global
as1 ,2中任何地方都能访问到_root ,_global ,这样可以很简单的保存变量或函数到这里,但在as3中已经没有_global了,root 也只有Disobject在显示列表里时才会得到,如果你非要这么做的话,应该自己写一个glo类,里边用一个静态变量bal指向一个Object,下边是代码
package {
public class glo {
public static var bal:Object = new Object();
}
}
现在可以把 gol.bal 当成以前的_root或_global用了
trace(glo.bal.foo); // undefined
glo.bal.foo = "bar";
trace(glo.bal.foo); // bar
24. ActionScript 2 to ActionScript 3 Converter
Patrick Mineault(http://www.5etdemi.com/blog/) 用php写了一个as2 -->as3 转换器,不是百分之百准确但也不错
online 版本 :http://www.5etdemi.com/convert
下载 :http://www.5etdemi.com/convert/convert.zip
25. Accessing FlashVars and HTML Parameters
你可以用HTML中的 object/embed 代码向镶入的SWF传递变量。
有两种方法:
1。在swf的url后边加变量(query string)
<!-- URL Variables -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="640" height="500" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="flashMovie.swf?myVar=1" />
<param name="quality" value="high" />
<param name="bgcolor" value="#EFF7F6" />
<embed src="flashMovie.swf?myVar=1" quality="high" bgcolor="#EFF7F6" width="640" height="500" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
2.使用FlashVars
<!-- FlashVars -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="flashMovie.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<param name="FlashVars" value="myVar=1" />
<embed src="flashMovie.swf" FlashVars="myVar=1" quality="high" bgcolor="#FFFFFF" width="550" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
在as2中这些变量会被简单的声明到_root上,但在as3中有所改变。现在这些变量被放到了root下的parameters对象下,上边HTML传的值可以这样访问:
root.loaderInfo.parameters.myVar;
26. ActionScript Speed Through Typing
考虑到效率,尽量把你的变量声明类型,如果可能的话避免使用dynamic class
27. LivePreview and the LivePreviewParent class
as2 的组件使用_global下的isLivePreview属性来判断是否是在Flash IDE中预览,as3中这个属性不见了,取而代之的是你可以检查这个组件的parent是否为 LivePreviewParent 类的实例
var isLivePreview:Boolean = (parent != null && getQualifiedClassName(parent) == "fl.livepreview::LivePreviewParent");
( N神注:as2时代的isLivePreview这个属性偶也没用过,不清楚这个翻译的对不对 - -b )
28. Flex Component Kit for Flash CS3
Flex Component Kit for Flash CS3(在Adobe Labs里) 允许把flash中做的交互内容,在Flex中当成Flex comonnet来用
现在可以很容易的使Flash symbol继承我们的新 UIMovieClip 类
从而使
* flash 组件放在一个Flex container里,所有layout会很好的工作
* flash 的帧标签被完全转换为 Flex 的state和 transition
* 只要简单的填加个 SWC 到 library path里Flex Builder就可以有flash组件的语法提示了
* Simple JSFL commands are available to set up new documents as well as publish the Flex-enabled SWC (这句没看明白- -b)
29. Loading URL encoded Variables
URLLoader类(flash.net.URLLoader) 在as3中用来读外部文本文件.当一个外部文件被load后,它的内容会被存储在URLLoader实例的data属性里,一般情况下无论外部文件是什么格式,都会被以raw text形似读取,如果读变量可能需要改一下dataFormat属性
URLLoader类的dataFormat属性决定被加载数据的格式。 dataFormat属性的可选值在 URLLoaderDataFormat 类中(flash.net.URLLoaderDataFormat)
可选值为:
BINARY - 指定按2禁止数据接受
TEXT - 指定当成文本接受
VARIABLES - 指定当作 URL-encoded变量接受
指定URLLoaderDataFormat.VARIABLES 作为 URLLoader的 dataFormat属性, 被加载的数据将被当作一组变量,而不是字符串
data属性将为包含被加载变量的一个 URLVariables 类 (flash.net.URLVariables)的实例
ActionScript 代码:
var loader:URLLoader = new URLLoader();
// specify format as being variables
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, varsLoaded);
// vars.txt contents: foo=bar&foo2=bar2
loader.load(new URLRequest("vars.txt"));
function varsLoaded (event:Event):void {
trace(loader.data is URLVariables); // true
trace(loader.data.foo); // bar
trace(loader.data.foo2); // bar2
}
30. Interactive Masks
默认情况下,当一个对象 mask 另一个对象的时候,前者(这个遮照)将失去它的交互性,例如,一个sprite有一个 click事件,但当这个sprite成为一个遮照的时候,这个click事件就不起作用了
如果你想让一个对象作为遮照的时候也拥有交互性,就指定它的buttonMode属性为true
ActionScript Code:
maskInstance.buttonMode = true;
31. No _lockroot
ActionScript 3 没有 _lockroot属性了.
_lockroot 属性是在Flash Player 7 引入近来的,_lockroot属性原本用来确保被load进来的movie的_root属性始终引用它自己而不是主swf在 ActionScript 3 中, 所有的root引用永远指向文件本身的root 就像_lockroot已经在那了一样。( N神注:想引用原来主swf的root应该用stage了)
相关推荐
tag=flash)和NShen博客(http://www.nshen.net/blog/default.asp?cat=16):这两个个人博客分享了ActionScript的开发经验和技巧。 17. FlexCoders(http://www.flexcoders.cn/):虽然名字中带有Flex,但这个社区...
CodingBlog程序员的私房极简博客系统 极简静态博客系统 安装方法 下载到本地 git clone https://github.com/nshen/coding-blog.git myBlog 进入目录 cd myBlog 安装节点依赖 cnpm install或npm install 编译并打开...
id-生成器-java Java实现的ID生成器 格式: T |64| * L |6| R|4| 否 |12| * S |10| * ID = TLRNS,96 位 T 时间戳,以毫秒为单位,64 位 l 逻辑区域,如分区或ISP,6bits,容量为64个区域 R 保留位,4 位,容量 ...
Tobit与Probit模型Stata实现代码-最新发布.zip
Jupyter-Notebook
红警单机版(单机游戏)
SwiftUI编写的贪吃蛇小游戏讲解
1996-2020年中国文化旅游统计年鉴-最新数据发布.zip
Jupyter-Notebook
omwfa1hxz_1.apk
2001-2023年上市公司大数据应用指数数据集(6.1万样本,5600家企业,含原始数据、代码及结果,最新).zip
Jupyter-Notebook
Typora(version 1.2.3)导出 pdf 自定义水印的 frame.js 文件,详情可以查看:
量产部落sm2263xt开卡工具,支持b16b17颗粒
中国1公里分辨率月降水数据-最新全集.zip
云平台VPC.vsdx
CPA注会考试最新教材资料-最新发布.zip
分省最低工资标准面板数据最新集.zip
内容概要:本文档是一份详尽的Java面试题集,涵盖了许多常见的Java面试问题及详细的解答。内容涉及Java基础语法、面向对象编程、集合框架、网络编程、Spring框架等多个方面。每个问题不仅提供了答案,还解释了其背后的原理和技术细节。 适合人群:即将参加Java岗位面试的技术人员,特别是工作经验1-3年的软件工程师。 使用场景及目标:适用于准备Java面试,加深对Java核心技术的理解和掌握。通过练习这些问题,帮助面试者更好地理解和应对面试官的问题。 阅读建议:建议结合实际项目经验来阅读和练习这些问题,以便更好地理解和应用所学的知识点。同时,对于复杂的问题,可以通过编写代码来验证答案的正确性和理解深度。