[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 596
  • Last Modified:

Increment variable from within MovieClip

I would like to check some syntax and procedure to get on the right path.

In simple terms I have a scene (Level A) with a movieclip (Level B) and inside that MC six more MCs (Level C). Also on level B above the MC is another MC with buttons that look exactly like the 6 movieclips. These buttons trigger the 6 MCs play each and then displays a greyed out button for ones that have completed. I have a hidden NEXT button that should show once all the clips have been played and I want to the 6 MCs to increment a counter to display the NEXT button.

See the sample in action at the URL given.

http://www.1000ml.co.za/Flash/PGCA/choices01d.html

My thinking is that I have a specific syntax problem or it's in the pathing - the buttons being 2 levels deeper than the Var and the button I want to unhide when the counter reaches 6.

Here is the codel:
Level A:
On the last frame where I add the 6 MCs inside their level B parent:
stop();
var Counter:Number = 0; 
if(Counter == 6){ 
 _root.ButtonContinue._visible = true;    
}else{ 
_root.ButtonContinue._visible = false; 
} 
 
Then on each of the buttons in Level C:
on (release) {
	_root.FlyPastExp.play();
	_root.FlyPastExp._visible=true // Unhide the MC and play it
	_root.FlyButtons._visible=false // Buttons are hidden while MCs play
	_global.Counter=Counter++ // increment the counter
}
Or their respective hide and play targets.
 
The 0 (Zero) in the sample page (see URL sample) is the variable Counter that I'm displaying to the stage to see if the counter increments but as you can see it does not. 

Open in new window

0
Gerano
Asked:
Gerano
  • 3
  • 2
  • 2
2 Solutions
 
crooksy88Commented:
var and _global are two different types of variable.

You should use either/or.

_global.Counter  = 0;
if(_global.Counter == 6){

_global.Counter = Counter++

----
or
---
var Counter:Number = 0;
if(Counter == 6){

_root.Counter = _root.Counter++ // assuming you initiated the Counter var on the _root timeline.


0
 
blue-genieCommented:
i also have a suspicion that when you refer to levelA, levelB etc, you're refering to Layers and not levels - are you refering to the layers on the timeline, or have you actually loaded items into different levels, they are not the same thing.

0
 
GeranoAuthor Commented:
No, my reference to levels are the different parent child levels.

I'm not using the correct terminology for this my apologies so let me state it this way which will hopefully make it more clear. I will also stay with my reference to A, B and C above so as not to confuse the ocde I posted.
Level A = a frame on root (scene) timeline with var code
Level A = 6 layers each with a movieclip called CardFly1 , CardFly2, etc.
Level A = a movieclip called FlyButtons
Leve B = 6 buttons inside FlyButtons that trigger 6 MCs on level A, hide FlyButtons MC and also have to increment the counter.
Note that the last frame of each of the 6 MCs on level A sets FlyButton visible = true, hides the button that was clicked and shows the greyed out button for that clicked button.

Wow, just writing that out made it a lot more clear in my mind. After days of this you lose track of everything you tried or did.

I tried the code that crooksy88 posted but the button that should be hidden until all six buttons are clicked shows from the start and the variable dynamic text stays on 0
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
crooksy88Commented:
I've just spotted a typo on my part

_global.Counter = Counter++

should be:

_global.Counter = _global.Counter++

If you are using this _global method you need to check that all instances of your original Counter var are changed to _global.Counter
0
 
GeranoAuthor Commented:
Nope, this is still not doing anything.

Don't know if this is relevant but while these buttons are cllicked the scene remains static on the timeline, so there is no next frame where something can be checked as one would with a preloader.
0
 
blue-genieCommented:
hey Crooks if i can jump in.
gerano, i have no idea what your movieclip setup is in terms of your LevelA and LevelB, help us out, most of us are old and decrepit and geeks, so speak the correct geek to us.
you're only going to confuse yourself and others more.
in terms of which clip does what, i am clueless till I see it, but the counter thing, is as simple as the following.

on your main timeline where you're declaring your variable

var Counter:Number = 0;
as crooks said, you haven't declared that as a global.
you don't need a global in this case.

in your button all you need to do is.

on(release) {
//all the other stuff
_root.Counter++;
}

and you'll see that increments by 1 each time you click it.

(ps if you're going to be developing flash into the future, stop the habit now of putting code onto your objects)

i.e. instead of selecting your button and putting onRelease code directly on it, give your button an instance name and put the code all in one central location (if not external files) then at least on the timeline

buttonName.onRelease = function() {
//blah;
}



0
 
GeranoAuthor Commented:
Thanks for the pointing me in the right direction, I made it all go on the timeline. Also, the tip about not assigning anything directly on the elements was a great help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now