• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Call a function if String number is inferior to 0

Contributor ,
Feb 01, 2014 Feb 01, 2014

Copy link to clipboard

Copied

Hi all,

I've got a movieclip named toolbar which is linked to Toolbar class (Tollbar.as).

In this movieclip, there is a dynamic text field named "argent".

I've got an this in my Puzzle.as :

public function blabla:void{

stageRef.dispatchEvent(new Event("checkingMoney"));

}

And in my Toolbar.as :

public class Toolbar extends MovieClip{


private var stageRef:Stage;

                    private var money:int;

 

                    public function Toolbar(stageRef:Stage){

 

                              this.stageRef = stageRef;

                              

                               money = 9999; 

argent.text = money.toString();

                              stageRef.addEventListener("checkingMoney", checkMoney, false, 0, true);

public function checkMoney(event):void{

                              trace("checking");

                    if (money < 0){

        trace("dangerous"); 

}

}

I can't see where the problem is. The function checkMoney is called (as I see the trace "checking"), but the

  if (money < 0){

        trace("dangerous");

doesnt' work. Yet, the number is far below 0....

Do you know what could be the problem ?

Thank you very much.



TOPICS
ActionScript

Views

779

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 01, 2014 Feb 01, 2014

i don't see a problem with anything in message 2, but there's nothing in message 2 related to the problem in message 1.

in particular, you are not changing the variable money.

possibly you want to do something like:

public function checkMoney(event):void{
                              trace("checking");
                    if (Number(argent.text) < 0){
        trace("dangerous"); 
}
}

Votes

Translate

Translate
Community Expert ,
Feb 01, 2014 Feb 01, 2014

Copy link to clipboard

Copied

it's not less than zero from the code you showed. 

use the trace function to confirm money is still 9999:

public function checkMoney(event):void{
                              trace("checking",money);
                    if (money < 0){
        trace("dangerous"); 
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 01, 2014 Feb 01, 2014

Copy link to clipboard

Copied

You're right. The money is still 9999. Can you tell me what's wrong on my dropMoney function please ?

private function dropMoney(e:MouseEvent):void{

toolbar.argent.text = String( Number(toolbar.argent.text ) - 100 );

(note : "argent" is the dynamic text field in my movieclip "toolbar")

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2014 Feb 01, 2014

Copy link to clipboard

Copied

i don't see a problem with anything in message 2, but there's nothing in message 2 related to the problem in message 1.

in particular, you are not changing the variable money.

possibly you want to do something like:

public function checkMoney(event):void{
                              trace("checking");
                    if (Number(argent.text) < 0){
        trace("dangerous"); 
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 01, 2014 Feb 01, 2014

Copy link to clipboard

Copied

Exactly ! THANK YOU

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2014 Feb 01, 2014

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines