A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Forcing a method to be static

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    120

    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]

  2. #2
    Senior Member
    Join Date
    Jan 2001
    Posts
    120
    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


  3. #3
    Senior Member
    Join Date
    Nov 2001
    Posts
    667
    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).

  4. #4
    Senior Member
    Join Date
    Jan 2001
    Posts
    120
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center