Solved

as2 increment error

Posted on 2011-03-07
13
352 Views
Last Modified: 2012-05-11
hello
i am having trouble incrementing correct values in a score. i have 8 coin mc's on the stage with the following code and i am trying to add 5 to the score for each time the char hits the coin. but what is happening is that the first hit generates 5 then on the next hit instead of 10 it becomes 55 then 555 etc. where am i going wrong with this? thanks
STAGE VARS

score.text = 0;
// _root.score is set to 0
health.text = 100;
-----------------------------------------------------

COIN MC's

onClipEvent (enterFrame) {
	if (this.hitTest(_root.char)) {
		// if this hits the char (_root.char)
		_root.score.text+=5;
		// _root.score goes up 5
		unloadMovie(this);
		// this movie clip is unloaded
	}
}

Open in new window

0
Comment
Question by:peter_coop
  • 7
  • 6
13 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35055923
Try this:
 
onClipEvent (enterFrame) {
        if (this.hitTest(_root.char)) {
                // if this hits the char (_root.char)
                _root.score.text+=5;
                // _root.score goes up 5
                delete this.onEnterFrame;
                unloadMovie(this);
                // this movie clip is unloaded
        }
}

Open in new window


Warm Regards
Deepanjan Das
0
 

Author Comment

by:peter_coop
ID: 35056548
hi still the same. the first hit == 05 the second hit == 055 etc.thanks
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35056706
Opps I am sorry.
Do this:
 
//stage vars:
STAGE VARS
var scoreInt:Number = 0;
score.text = scoreInt;
// _root.score is set to 0
health.text = 100;


onClipEvent (enterFrame) {
        if (this.hitTest(_root.char)) {
                // if this hits the char (_root.char)
                _root.scoreInt+=5;
                _root.score.text = _root.scoreInt;
                // _root.score goes up 5
                delete this.onEnterFrame;
                unloadMovie(this);
                // this movie clip is unloaded
        }
}

Open in new window


Warm Regards
Deepanjan Das
0
 

Author Comment

by:peter_coop
ID: 35059174
hi. what is happening is that the score is being added on the first coin but not on the others. still stays at 5. i have placed the code in all my coin mc's. thanks
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35063722
Kindly share your fla for debug.

Warm Regards
Deepanjan Das
0
 

Author Comment

by:peter_coop
ID: 35068296
here you go. bear in mind this is just a tutorial file i downloaded to get started. thanks
platformgame.fla
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Expert Comment

by:deepanjandas
ID: 35069644
Place this way:  
//stage vars:
scoreInt = 0;
score.text = scoreInt;
// _root.score is set to 0
health.text = 100;


onClipEvent (enterFrame) {
 
        if (this.hitTest(_root.char)) {
                // if this hits the char (_root.char)

                // _root.score goes up 5
                delete this.onEnterFrame;//this might not work as its AS1.0
                unloadMovie(this);
                // this movie clip is unloaded
        } else {
            _root.scoreInt += 5;
        }
         _root.score.text = _root.scoreInt;
}

Open in new window


Warm Regards
Deepanjan Das
0
 

Author Comment

by:peter_coop
ID: 35070020
hi. that just creates a timer in the score. it just keeps incrementing. thanks
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35077314
I am lost on what you are looking forward to.
SO you want the score to increment on every hitTest and then stop.

Warm Regards
Deepanjan Das
0
 

Author Comment

by:peter_coop
ID: 35081454
ok. let me try to explain further. as an example lets assume i have a mc on the stage which is the coin which as the following as attached. the code for the coin will increment the score by 1 on a hit. that works. what dosen't work is if i try to increment by any other value, say 5 or 2. so if coin 1 had an inc value of 5 then when hit the score becomes 5. if i place another coin on the stage and hit both it should be 10 but instead it is 55. it is not adding to the numebrs. the score is a dynamic text field with an instance name of score. thanks and i hope that is clearer.
COIN MC CODE

onClipEvent (enterFrame) {
	if (this.hitTest(_root.char)) {
		// if this hits the char (_root.char)
		_root.score.text++;
		// _root.score goes up 1
		unloadMovie(this);
		// this movie clip is unloaded
	}
}

Open in new window

0
 
LVL 17

Accepted Solution

by:
deepanjandas earned 250 total points
ID: 35085090
This worked for me:

On the first frame:
_root.scoreInt = 0;
root.score.text = _root.scoreInt;

Open in new window


On the coin:
onClipEvent (enterFrame) {
        if (this.hitTest(_root.char)) {
                // if this hits the char (_root.char)
               _root.scoreInt += 5;
	       _root.score.text = _root.scoreInt;
                // _root.score goes up 1
                unloadMovie(this);
                // this movie clip is unloaded
        }
}

Open in new window



Warm Regards
Deepanjan Das
0
 

Author Comment

by:peter_coop
ID: 35088775
thank you deepanjandas. works well. thanks for all your help.
0
 

Author Closing Comment

by:peter_coop
ID: 35088779
thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
quadtree image segmentation search 24 339
I want to have a video play on my users devices regardless of what they're using 6 54
black magic design 1 125
VOB to mp3 8 61
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now