Reputation: 18097
I am learning actionscript 3. And If I want to create packages and classes i have to create another .as
extension file. In which i have to put the package/class code. Which is fine but annoying, and frustrating mainly because i don't understand why it has to be done this way.
Why would code like this:
package {
public class a{
function a(){ trace('Hey'); }
}
}
won't work in fla file, but will work in separate .as file in the same folder.
Upvotes: 0
Views: 131
Reputation: 586
The timeline and frames are the properties of MovieClip class instance, so when writing code in frames you add it to the main-application-class, which is automatically created by Flash IDE. I.e. you are operating with single class, which is generated by the editor.
There is no way to declare packages and classes in frame-script. You also can not declare more than one externally visible definition (class or function) within one .as file. These are compiler limitations.
Note that you may declare functions, and create instances of other classes, manipulate with display-list objects in frame-scripts, so your abilities are not severely limited.
There is also a way, that works on timeline, to extend class behavior using Object's prototype property:
MovieClip.prototype.summ = function ():void {
trace ('this function extends movieclip class');
}
var instance:MovieClip = new MovieClip();
instance.summ(); // will trace this function extends movieclip class
Upvotes: 1