A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Static function call through type reference

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    10

    Static function call through type reference

    I'm attempting to call a static member function of a class without instantiating it via a type reference as returned by getDefinitionName.

    Code:
    var typeRef:Class = getDefinitionByName(__class) as Class;
    var width:int = typeRef.getWidth();
    This isn't working, I'm getting a syntax error:

    1061: Call to a possibly undefined method getWidth through a reference with static type Game.GameLogicisplayObject

    I've googled quite a bit and I'm not seeing anything relating to this, is this even possible?

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    try:

    width = __class(typeRef).getWidth()

  3. #3
    Junior Member
    Join Date
    Jun 2008
    Posts
    10
    Quote Originally Posted by neznein9
    try:

    width = __class(typeRef).getWidth()
    Code:
    var typeRef:Class = getDefinitionByName(__class) as Class;
    var width:int = DisplayObject(typeRef).getWidth();
    Code:
    var typeRef:Class = getDefinitionByName(__class) as Class;
    var width:int = __class(typeRef).getWidth();
    Both of those produce syntax errors.

  4. #4
    Junior Member
    Join Date
    Jun 2008
    Posts
    7
    If you change your function to a public static getter in your class it should work:
    Code:
    public static function get someWidth():int
    {
    return _someWidth;
    }
    Code:
    var typeRef:Class = getDefinitionByName(__class) as Class;
    var width:int = typeRef.someWidth;
    TS
    Last edited by duodiscus; 06-22-2008 at 02:51 AM.

  5. #5
    Junior Member
    Join Date
    Jun 2008
    Posts
    10
    Success! Thanks

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