In Flash 9, you are able to associate all timelines with classes, including the root timeline. Movie clip timelines are associated with classes the same way as ActionScript 2 using the linkage dialog. The root timeline can be given a class association through the property inspector or through the publish settings (in ActionScript settings).
If you do not associate a timeline with a class, one is automatically created for that timeline by Flash. When this happens, variables become class variables, all named functions (declared using function functionName(){}) become methods of that class, and all scripts within the frames associated with methods that are automatically called when that frame is reached (minus the variable and method definitions). Because of this, you can only declare variables and named functions of any specific name for a function once. Variables you can redefine, but not redeclare. Functions (methods) are locked. Note: You cannot mix classes associated with timelines and timeline scripts.
The following timeline script in Flash 9
ActionScript Code:
var num:Number = 1;
function showNum():void {
trace(num);
}
showNum();
essentially becomes the following AS3 class that gets associated with that timeline:
ActionScript Code:
package {
class TimelineClass extends MovieClip {
public var num:Number = 1;
public function showNum():void {
trace(this.num);
}
public function frame1():void {
showNum();
}
}
}
0 评论:
发表评论