Skip to main content
May 26, 2008
Answered

Old var Number trick isn't working anymore

  • May 26, 2008
  • 5 replies
  • 583 views
So here's the setup, in AS 2, I used a Number variable to help create a navigation scheme that checked to see what button was clicked, and moved accordingly on the timeline. You'll see it in the attached AS. Essentially, all I did was set a new number variable to 0, and when a specific button was clicked, it would change the value to 1. A function would then check to see which one set the value to "1" and then move the play head to the designated frame label (then resetting the variable to avoid looping problems). It doesn't work and I'm geting the error message:

"Access on undefined property onRelease througha reference with static type flash.display:SimpleButton"

In other words, it ain't working. The only things I changed from the AS2 version of my script was the syntax of creating the variable, and using a button rather than a movie clip.

I hope this makes sense, because I would really not want to have to rebuild this in AS2 just to get it to work. I've separated the AS out by frame/labels in the hopes that what I'm trying to do is a bit more clear. Help!
This topic has been closed for replies.
Correct answer
GAH!

I finally figured it out.

The problem was that on the main time line I also had an event listener for the entire instance of mcWhat to go to the "start" frame label. Because that AS was on the main time line, it superseded any other event listeners contained within the instance of mcWhat. The solution was to put an invisible button in a layer above mcWhat on the main time line that triggers the gotoAndPlay("start"), and thus frees up both btnSkills and btnHome (both on the mcWhat time line), and allows the event listeners to execute their functions.

So in a nutshell, the problem wasn't the AS in the movie clip, it was the event listener for the movie clip that was causing conflicts.

Good lord, have I got a lot to learn about smart AS coding.

Thanks to all who pitched in.

5 replies

kglad
Community Expert
Community Expert
May 31, 2008
you're welcome.
kglad
Community Expert
Community Expert
May 31, 2008
if that code is attached to the timeline that you want to control, your code should work (unless the timeline is already on the skills or exit frame).
May 31, 2008
Okay, this works now, by itself as a movieclip, but when it is pulled as an instance to the stage (called mcWhat), it does not work. Should I just pull this all to the main timeline and save myself the trouble?
Correct answer
May 31, 2008
GAH!

I finally figured it out.

The problem was that on the main time line I also had an event listener for the entire instance of mcWhat to go to the "start" frame label. Because that AS was on the main time line, it superseded any other event listeners contained within the instance of mcWhat. The solution was to put an invisible button in a layer above mcWhat on the main time line that triggers the gotoAndPlay("start"), and thus frees up both btnSkills and btnHome (both on the mcWhat time line), and allows the event listeners to execute their functions.

So in a nutshell, the problem wasn't the AS in the movie clip, it was the event listener for the movie clip that was causing conflicts.

Good lord, have I got a lot to learn about smart AS coding.

Thanks to all who pitched in.
kglad
Community Expert
Community Expert
May 29, 2008
what's "..not quite firing"?

btnHomeF is being called, correct?
May 31, 2008
Yes it's being called and after testing it with a trace function, it does register the CLICK, but it does not perform the gotoAndPlay. Code is attached. What it does instead is just replay the animation contained in the "start" frame label.

I'm not sure I'm making any more sense, I'll try to find a place to link my file so you can take a look if all else fails...
kglad
Community Expert
Community Expert
May 26, 2008
there are so many differences it's amazing you got anything done without running into compiler errors.

but in the code you showed, you have onRelease() methods applied to buttons. that is as2 code.

in as3, you apply eventlisteners:

btnHome.addEventListener(MouseEvent.CLICK, btnHomeF);

and the listeners call functions (btnHomeF):

function btnHomeF(e:MouseEvent){
Nav2 = 1;
gotoAndPlay("skills_out");
}
May 29, 2008
Still not quite firing. I tried reducing it to a single variable to see if that was causing the problem, but it is still not advancing past the "start" label.

I changed the following in the AS:
Single number variable instead of 3 (now just "JumpNav")
When clicked, depending on the button clicked, the variable gets changed to "1," "2," or "3"
kglad
Community Expert
Community Expert
May 26, 2008
publish for as2, if you're using as2 code. if you want to publish for as3, you need to use as3 code.
May 26, 2008
When I do that I get twice as many errors, since I'm using AS3 everwhere else in the FLA, so I guess I would need to re-script this little doodad in AS3, but I'm a little lost as to where the changes in syntax should occur. Any pointers?