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

Hey, im having some trouble with my code

New Here ,
May 29, 2013 May 29, 2013

I'm trying to make a object be worth points. Here is the code im using, but it doesnt make the score increase, it just makes the 0 vanish after clicking on the item. Then you click on the item again and it says 00, then nothing, then 0 and repeat. Any ideas?

----------------------------------------------------

var currentScore:int;

init(); // this line goes directly beneath the variables

function init():void{ // call once to set everything up

     currentScore = 0; //start with 0 score

     MoneyBtn.addEventListener(MouseEvent.CLICK, addScore ); // clicking on +1

     

            }

function updateScoreText():void

{

     scoretxt.text = (""+ currentScore); // set the text property of the txtScore

     trace("Score text updated");

     }

     updateScoreText(); // finally, update the text field

          

           function addScore(e:MouseEvent):void{

     currentScore += 25; // add points to the score

     updateScoreText(); // update the textfield

}

TOPICS
ActionScript
580
Translate
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 ,
May 29, 2013 May 29, 2013

there's no problem with the code you showed.  in particular, that code would not cause the problem you are seeing.

Translate
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
New Here ,
May 29, 2013 May 29, 2013

then what is the problem. instead of adding 25 points, it just changes the score to blank, then 00, then blank.

Translate
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
New Here ,
May 29, 2013 May 29, 2013

Fixed it. the text wasnt embeded. FML lol

Translate
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
New Here ,
May 29, 2013 May 29, 2013

New problem sorry, if i was to make multiple objects worth points. How would i change the value on each one? For example. MoneyBtn is worth 25, and im trying to make ShirtBtn worth 50, how exactly would i change it so they dont use the same properties = 25.

---------------------------------------

var currentScore:int;

init(); // this line goes directly beneath the variables

function init():void{ // call once to set everything up

     currentScore = 0; //start with 0 score

     MoneyBtn.addEventListener(MouseEvent.CLICK, addScore );

           ShirtBtn.addEventListener(MouseEvent.CLICK, addScore );

    

            }

function updateScoreText():void

{

     ScoreTxt.text = ("Score: "+ currentScore); // set the text property of the txtScore

     trace("Score text updated");

     }

     updateScoreText(); // finally, update the text field

         

           function addScore(e:MouseEvent):void{

     currentScore += 25; // add points to the score

     updateScoreText(); // update the textfield

           

}

Translate
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 ,
May 30, 2013 May 30, 2013
LATEST

either use movieclip button's:

var currentScore:int;

init(); // this line goes directly beneath the variables

function init():void{ // call once to set everything up

     currentScore = 0; //start with 0 score

ShirtBtn.points=50;

MoneyBtn.points=25;

     MoneyBtn.addEventListener(MouseEvent.CLICK, addScore );

           ShirtBtn.addEventListener(MouseEvent.CLICK, addScore );

    

            }

function updateScoreText():void

{

     ScoreTxt.text = ("Score: "+ currentScore); // set the text property of the txtScore

     trace("Score text updated");

     }

     updateScoreText(); // finally, update the text field

         

           function addScore(e:MouseEvent):void{

     currentScore += e.currentTarget.points; // add points to the score

     updateScoreText(); // update the textfield

           

}

or, use a dictionary instance:

var currentScore:int;

var dictionary:Dictionary;

init(); // this line goes directly beneath the variables

function init():void{ // call once to set everything up

dictionary=new Dictionary(true);

dictionary[MoneyBtn]=25;

dictionary[ShirtBtn]=50;

     currentScore = 0; //start with 0 score

     MoneyBtn.addEventListener(MouseEvent.CLICK, addScore );

           ShirtBtn.addEventListener(MouseEvent.CLICK, addScore );

    

            }

function updateScoreText():void

{

     ScoreTxt.text = ("Score: "+ currentScore); // set the text property of the txtScore

     trace("Score text updated");

     }

     updateScoreText(); // finally, update the text field

         

           function addScore(e:MouseEvent):void{

    currentScore += dictionary[e.currentTarget]; // add points to the score

     updateScoreText(); // update the textfield

           

}

Translate
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