actionscript 3 - Call a function if String number is inferior to 0? -
i've got code in toolbar.as :
var money = 9999; argent.text = string(money); trace(money); how do say
if (money < 0){ callfunction(); } ?
thank answers
edit
i've tried everything.
here's did :
var money:int = 9999; argent.text = money.tostring(); trace(money); stageref.addeventlistener("checkingmoney", checkmoney, false, 0, true); i've add eventlistner in order check money (as nothing triggering condition if money<0 before).
and :
public function checkmoney(event):void{ var money; trace("checking"); if (parseint(money) < 0){ trace("dangerous"); } } so function triggered (the trace "checking" on), number under 0 (-4600), trace "dangerous" not appear.. don't understand.
i don't this, i'm posting second answer because edit drastically different posted. future reference, please post entire code relevant. seemed have missed context , forced solve wrong problem (don't me wrong, still needed fixed not issue @ hand)
so seeing scope issue. basically, object declared in object (be class, function, loop, or conditional) available within object , within child objects. additionally, all objects declared in top-level scope of class must have access modifier (public, private, internal, protected, etc).
so let's assume class structure:
public class classname { public function classname(); public function checkmoney(); } an object declared in constructor (classname()) not available in checkmoney(). need 1 of 2 things:
declare object in top-level scope:
public class classname { private var money:int; public function classname(){ money = 9999; checkmoney() } public function checkmoney() { // have access money } } or pass object function:
public class classname { public function classname(){ var money:int = 9999; checkmoney(money); } public function checkmoney(value:number) { // check "value" here. note numbers , strings not passed reference, changing value not change original variable } }
Comments
Post a Comment