0

i would simply like to encapsulate a function in it's own .as file, but i can't quite get it.

package
{
public class NumberAdd
    {
    public function NumberAdd()
        {
        public static function myNumber(val:Number):Number
            {
            return val + 2;
            }
        }
    }
}

this i would call it like this:

var myNum:Number = NumberAdd.myNumber(2);
trace(myNum); //traces 4

what is my mistake?

1
  • move the method out of the constructor and you should be fine.. Commented Jun 14, 2010 at 21:27

1 Answer 1

1
package
{
    public class NumberAdd
    {
       public static function myNumber(val:Number):Number
       {
           return val + 2;
       }
    }
}

try this

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.