how can i inject a static value?

halley's Avatar

halley

28 Feb, 2011 09:45 AM

because a static function will use...

[Inject] public static var myself:UserVO;

public static function getTip(level:uint):void
{ if(level >myself.level) ........ }

  1. 1 Posted by krasimir on 28 Feb, 2011 09:47 AM

    krasimir's Avatar

    Hi,

    if there is no any specific reason of using static variables and methods I'll suggest you to map this class as a singleton. Then you will have only one instance of it.

  2. 2 Posted by Michal Wroblews... on 28 Feb, 2011 09:50 AM

    Michal Wroblewski's Avatar

    You can't inject to static fields.

    Try to map a value first with injector, you'll probably need named mapping:

    var myself:UserVO = new UserVO();
    injector.mapValue(UserVO, myself, 'myself')

    then you can inject that value e.g. in one of your commands.

    [Inject(name="myself")] public var myself:UserVO

  3. 3 Posted by halley on 28 Feb, 2011 09:58 AM

    halley's Avatar

    so great speed~thanks for krasimir,Michal Wroblewski .
    in china i will not get an answer so fast

  4. 4 Posted by krasimir on 28 Feb, 2011 10:00 AM

    krasimir's Avatar

    You are welcome :)

  5. 5 Posted by halley on 28 Feb, 2011 10:37 AM

    halley's Avatar

    another problem

    var myself:UserVO = new UserVO();
    injector.mapValue(UserVO, myself, 'myself'); //it's ok
    injector.mapValue(Array, myself.bagData, 'myBag');//missing a rule

    i want

    [Inject(name="myself")] public var myself:UserVO;
    [Inject(name="myBag")] public var bag:Array;

    how can i do?

  6. 6 Posted by Michal Wroblews... on 28 Feb, 2011 11:00 AM

    Michal Wroblewski's Avatar

    It should work correctly. Maybe bagData == null or it's not an Array. Try to debug mapping part.

  7. 7 Posted by halley on 28 Feb, 2011 11:02 AM

    halley's Avatar

    you are right ~thanks~

  8. Stray closed this discussion on 02 Mar, 2011 11:11 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac