how can i inject a static value?
because a static function will use...
[Inject] public static var myself:UserVO;
public static function getTip(level:uint):void
{ if(level >myself.level) ........ }
Comments are currently closed for this discussion. You can start a new one.
2 Posted by krasimir on 28 Feb, 2011 09:47 AM
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.
3 Posted by Michal Wroblewski on 28 Feb, 2011 09:50 AM
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
4 Posted by halley on 28 Feb, 2011 09:58 AM
so great speed~thanks for krasimir,Michal Wroblewski .
in china i will not get an answer so fast
5 Posted by krasimir on 28 Feb, 2011 10:00 AM
You are welcome :)
6 Posted by halley on 28 Feb, 2011 10:37 AM
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?
7 Posted by Michal Wroblewski on 28 Feb, 2011 11:00 AM
It should work correctly. Maybe bagData == null or it's not an Array. Try to debug mapping part.
8 Posted by halley on 28 Feb, 2011 11:02 AM
you are right ~thanks~
Stray closed this discussion on 02 Mar, 2011 11:11 AM.