-
How to create "Static" methods and properties
edit
How do you create a "Static" method or property in Flash, meaning you don't have to instanciate the class to access it's methods eg. Math.abs();
In the example, you didn't have to invoke the Math constructor eg. myMath = new Math(); myMath.abs();
Is there a way of doing this in Flash, or do all custom classes have to be instanciated
[Edited by traden24 on 06-27-2002 at 01:13 PM]
-
Well, I figured it out, but it's weird. You have to use prototype to define Class lvl variables, but you still have to instanciate an object to access them...very odd.
MyClass.prototype.classLvlProperty = "value";
new MyClass().classLvlProperty;
vs.
MyClass.classLvlProperty
-
Math isn't a class, it's a global instance of the genaric Object class in flash with meathods assigned to it.
ie. Math.abs() could have been defined as:
Code:
_global.Math = new Object();
Math.abs = function(value) {
if (value < 0) {
return -value;
}
return value;
};
You could then call Math.abs() from anywhere in your flash movie by typing Math.abs(value).
-
That makes sense in a MX sort of way. When F5 was first out, it look just like every Math method was static like it is in Java. Thanks for the reply
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|