开发者

ActionScript Encapsulating a Static Function

开发者 https://www.devze.com 2023-01-03 06:56 出处:网络
i would simply like to encapsulate a function in it\'s own .as file, but i can\'t quite get it. package

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;
   开发者_StackOverflow         }
        }
    }
}

this i would call it like this:

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

what is my mistake?


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

try this

0

精彩评论

暂无评论...
验证码 换一张
取 消