actionscript using variables - need help

  • mrvix
  • Newbie
  • Newbie
  • mrvix
  • Posts: 7
  • Loc: Hong Kong

Post 3+ Months Ago

I need some actionscripting help with this. I am using variables to determine number of frames in my movie so when a button is hit, the movie will jump to specific frames. Below is the (wrong) code i am using, I have no problem setting up the variables but I have no clue how to pass the value of my variable onto the gotoAndPlay. Any help ?

Code: [ Select ]
on (release) {

var frames = this._totalframes;
var myFrames = frames/20;

if (this.scrubTargetState == "play") {
    gotoAndPlay(myFrames*6);
} else {
    gotoAndStop(myFrames*6);
}
}
  1. on (release) {
  2. var frames = this._totalframes;
  3. var myFrames = frames/20;
  4. if (this.scrubTargetState == "play") {
  5.     gotoAndPlay(myFrames*6);
  6. } else {
  7.     gotoAndStop(myFrames*6);
  8. }
  9. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ishkabible
  • Born
  • Born
  • ishkabible
  • Posts: 2
  • Loc: Johnstown PA

Post 3+ Months Ago

I see a couple of possible problems and suggestions for you.

1. though I don't understand the "frames/20", make sure that the value that it is returning is a whole number. Unless you file is either 20, 40, 60... frames, this code will not work.

2. I have not used "scrubTargetState", but unless "play" refers to the command "play()", I would change the name. Avoid using command words as labels or variables... It can make flash do strange things.

I would use your code reference and make sure your calculations kick out a whole number by using "Math" or "Number" values like round, or max or whatever you like... as long as it is not a decimal value passed to the gotoAndStop or gotoAndPlay
  • mrvix
  • Newbie
  • Newbie
  • mrvix
  • Posts: 7
  • Loc: Hong Kong

Post 3+ Months Ago

thanks for your reply. Really what I am asking is how to apply my variable to the action gotoAndPlay. I already have my variables set up the way the need to be and have checked it with a trace. My problem is with the later part of my code. Maybe this will simplify my question:

on (release) {
var frames = this._totalframes;
var myFrames = frames/20;


gotoAndPlay(myFrames*6);
}

What I am trying to do here is take my variable value assigned to "myFrames" and then apply it in an equation so on release the movie will go to and play the value of myFrames multiplied by 6.

My problem now is the scripting is faulty as I dont believe I can execute this function scripted as it is. Is there anyway to assign my variable to a gotoAndPlay action to achieve my desired out come?
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

the point is that if you trace your variable you'll either get a decimal number (no such frame) or your getting NAN (meaning the variable isn't a number). Your actually passing the variable correctly but it doesn't work because flash prob doesn't know what to do with the variable your passing. Read ishkabible 's post and then in addition I also see that your getting the number of frames in your button/movie clip instead of the root which you probably want.

try
Code: [ Select ]
_root._totalFrames;
instead.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 17 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.