GotoAndStop On Variable Number
Hey there fellers.
I'm having a problem getting a gotoAndStop() action to work on my movie clip. I'm trying to have the movie clip stop on a frame based on a variable.
For example: myMC.gotoAndStop(VariableNumber)
In other words, myMC would goto and stop on the frame that corresponds to the VariableNumber.
The movie clip loads up the frame I want just fine when I input a number instead of a variable, so I think there's a problem in telling flash that the variable name is the number of the frame.
I hope there's a quick fix.
Thanks for any help.
ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)
Posted on: 06-05-2005, 07:52 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Random Number Variable That's Different From Previous Number
I have this line of code in my game that works great. However it would work even better if when it the code was executed the next random number was not the same as the one before it. For example if "speech" is on frame 6 when the code is executed I would like the random number to be between 2 and 12 but not 6. (I don't want the same frame to come up as it confuses the kindergarteners and preschoolers using the program.) Here's the code that's working for me now.
ActionScript Code:
speech.gotoAndStop(Math.floor(Math.random()*11)+2);
Use Variable In GotoAndStop
hey !
can i use a variable in a gotoAndStop statement ?
something like this:
myVar = xxx;
_root.myMc.gotoAndStop("myVar");
?
i could solve it with a lot of if statemenst but this
would be so much easier
/ j
[F8] GotoAndStop - Using A Variable
hi, this will be a very easy one that i just cant figure out. i need to tell my movie clip to gotoAndStop at a frame label using a variable but i cant seem to concatinate the string together to get it to gotoAndStop.
this is what i have at the mo, but its not working - just loops through the mc
PHP Code:
hours_mc.gotoAndStop('"'+hours+'"')
any help is appreciated
[F8] Variable.gotoAndStop()
I have one button on _root and an invisible movieClip on _root. I would like to have button goto another movie clip's second frame when the movieClip's _y is changed. Heres the button's code:
PHP Code:
on (press) {
_root.starting = "yes";
if (_root.starting == "yes") {
var new_empty_mc:MovieClip = this.createEmptyMovieClip("empty_mc" + _root.number, _root.number);
_root.new_empty_mc._x = 35.8;
_root.new_empty_mc._y = 12;
_root.new_empty_mc.attachMovie("uc_id", "uc_mc", 1);
_root.selectedNote = "empty_mc" + _root.number + ".uc_mc";
trace("_root.selectedNote = " + _root.selectedNote);
startDrag(new_empty_mc,true);
_root.number = _root.number + 1;
}
}
And here's the invisible movie's code:
PHP Code:
onClipEvent (enterFrame) {
if (_root.empty_mc1._y >= 50) {
_root.selectedNote.gotoAndStop(1);
}
else if (_root.empty_mc1._y <= 50) {
_root.selectedNote.gotoAndStop (2);
}
}
It doesn't go to the second frame. Can anyone help me?
*edit: added tags
gparis
[F8] Variable.gotoAndStop()
I have to go a nested movieclip's second frame. Here's the code:
Code:
on (release) {
var oneArray:Array = new Array("_root.", "my_mc", ".", "uc_mc");
_root.oneArray[0]+oneArray[1]+oneArray[2]+oneArray[3].gotoAndStop(2);
trace(oneArray[0]+oneArray[1]+oneArray[2]+oneArray[3]._target);
}
This doesn't work. It outputs:
Code:
_root.my_mc.undefined
Can anyone help me?
GotoAndStop To A Variable
I have a variable called "map" and it is equal to a number that obviously varies at different times. I want to write gotoAndStop() to the number that "map" equals. But i dont kno how to write it :P
is it like:
gotoAndStop([map])?
GotoAndStop At A Variable
how to you format this statement, I have an anray that get set a variable and I'd like to use that variable in a goto statement but I don't know how to format it.
myArray = [];
for(i=1;i<25;i++) {
myArray.push("page_" + (1 + i));
if (frameLabel == "intro") {
gotoAndStop("page_1");
}
}
shifted = myArray.shift();
trace(shifted);
for(i=0;i<myArray.length;i++) {
if(y==x) {
gotoAndStop(shifted);
}
}
if(y!=x) {
_root.page_MC.nextFrame();
}
Shifted = page_2....how do I get the statement to read page_2
been at it since 4:00am any ideas
jef
GotoAndStop(variable) --- I'm Lost
i feel like a schmuck, but this is just not happening for me. i'm trying to test a MC so that it moves the playhead of a different timeline to a specific frame, and i'm using a variable to get that frame. like this:
tellTarget ("/tabs/tabContentGen") {
gotoAndStop (itemColorIndex + 10);
}
"itemColorIndex" is defined like this:
itemColorIndex = 7;
this isn't working, and i've staring at the same 5 lines for 2 hours trying to figure this out. if both the items in the expression are literals (like "gotoAndStop(7+10)"), everything works fine. anybody have an idea?
Movieclip.gotoAndStop(variable)
Hi,
i've got a problem with the movieclip.gotoAndStop(variable)command.
I have a movieclip(movie1) in which other movieclips(say 2,3 and 4) are on the timeline.
Inside the movieclips(2,3,4) I use the command _parent.gotoAndStop(variable. the variable is of course 2,3 or 4.
The problem is that the command only works at the last frame of the movieclip 2,3 or 4.
Does anyone know why this is and why I can't use this command in any other frame in the movieclip?
It seems flash just ignores the command unless it's at the last frame of the movie's timeline...
I know it's a vague problem but it drives me crazy !!
Leadman
_level[variable].gotoAndStop(2) ? HOW?
Hi - need little help! :-)
I have a presentation with movies at several levels...
I know the possibility to stop a level with this:
_level5.gotoAndStop(2)
e.g.
BUT - I want to have a varible in level0 with a number....
I think its something like that:
_level[_root.number].gotoAndStop(2);
But that doesn't work!!! :-( Anybody knows how to solve my problem?
Thanks
TUHH
GotoAndStop Variable Problem
Hi,
Background:
---------------------------------
I have a clip using 2 levels, _level0 is a basic template with links that load SWF's to _level1 using loadMovieNum.
One of the movies loaded is PROJECTS.SWF containing 7 frames - first containing the project list, 2 to 7 showing individual projects. Selecting a project loads a dynamic gallery by replacing _level1 (project page).
Requirement:
---------------------------------
There is a requirement to store last-visited project, so when user decides to return to project list from gallery, it goes to the correct frame of PROJECTS.SWF.
Problem:
---------------------------------
I attempted handling this by writing a variable to _level0.
The "projectFrame" variable is set by button click on PROJECTS.SWF and holds the last-visited frame number (2 to 7):
on (release) {
_level0.projectFrame = 2;
}
This method of variable storage works well in every case, except when I try to forward to desired PROJECTS.SWF frame with the following code on Frame 1 of the PROJECTS.SWF:
gotoAndStop(_level0.projectFrame);
When the PROJECTS.SWF movie gets loaded from the GALLERY.SWF the _level0.projectFrame variable is stored correctly - I can display it in a text box, but using it in gotoAndStop is problematic. I get no errors.
I tried using this.gotoAndStop(_level0.projectFrame), setting the frame number variables to "2" instead of 2, and just about anthing else logical I could come up with. I have been stuck on this problem for a long time and would appreciate help with this.
Thank you in advance.
GotoAndStop Variable Problem
Hi,
Background:
---------------------------------
I have a clip using 2 levels, _level0 is a basic template with links that load SWF's to _level1 using loadMovieNum.
One of the movies loaded is PROJECTS.SWF containing 7 frames - first containing the project list, 2 to 7 showing individual projects. Selecting a project loads a dynamic gallery by replacing _level1 (project page).
Requirement:
---------------------------------
There is a requirement to store last-visited project, so when user decides to return to project list from gallery, it goes to the correct frame of PROJECTS.SWF.
Problem:
---------------------------------
I attempted handling this by writing a variable to _level0.
The "projectFrame" variable is set by button click on PROJECTS.SWF and holds the last-visited frame number (2 to 7):
on (release) {
_level0.projectFrame = 2;
}
This method of variable storage works well in every case, except when I try to forward to desired PROJECTS.SWF frame with the following code on Frame 1 of the PROJECTS.SWF:
gotoAndStop(_level0.projectFrame);
When the PROJECTS.SWF movie gets loaded from the GALLERY.SWF the _level0.projectFrame variable is stored correctly - I can display it in a text box, but using it in gotoAndStop is problematic. I get no errors.
I tried using this.gotoAndStop(_level0.projectFrame), setting the frame number variables to "2" instead of 2, and just about anthing else logical I could come up with. I have been stuck on this problem for a long time and would appreciate help with this.
Thank you in advance.
Pass Variable To GotoAndStop();
I am using Flash 5 (not MX).
I have a movie clip 60 frames long, containing a shape tween that changes the color of the graphics.
I put an instance of the clip in the main movie. Depending on the cursor position (detected by onClipEvent(mouseMove) I want to do a gotoAndStop(n) on the clip, where n is some computed value between 0 and 60;
For some reason, in the OnClipEvent(mouseMove) handler, it will not work if I call gotoAndStop(n), but works if I put a literal number in, such as gotoAndStop(60) - or any number between 0 and 60.
This works:
onClipEvent (mouseMove)
{
d2 = _root._xMouse;
if (d2 < 300)
{
gotoAndStop(0);
}
else
{
gotoAndStop(60);
}
}
This doesn't:
onClipEvent (mouseMove)
{
d2 = _root._xMouse;
if (d2 < 300)
{
this.a = 0;
gotoAndStop(this.a);
}
else
{
this.b = 60;
gotoAndStop(this.b);
}
}
strangely, if I call gotoAndStop(n) where n is a variable from the mouseDown() handler, the clip goes to the frame identified by the number n.
Any idea what's happening here?
Thanks,
Carl
ActionScript Code:
onClipEvent (mouseMove)
Variable Decides GotoAndStop(15);
Hey, im building a game right now.
But im having some trouble.
I have a variable, saying that Points are 0
and points can be collected throughout the game.
and i want the level change to happen when the points are greater that some number. IE: 30 points.
i thought i could write something like
if (_root.poeng == 30) {
gotoAndStop(15);
}
or
if (_root.poeng <= 30) {
gotoAndStop(15);
}
dont remember what way i set the bracket, but greater. you get the point
dont worry about me spelling Points wrong. It's norwegian, and the exact same as the variable name.
How do i write this ?
If my explaination of this problem is weak, just tell me, and i will try to explain better!
On advance, thank you for any help
GotoAndStop With Variable Problem?
I'm updating someones elses file and this is causing a headache -
if (_root.career_pointer == null) {
loadMovie("career_main.swf", "emptyClip");
} else {
trace(_root.career_pointer);
this.gotoAndStop(_root.career_pointer);
}
stop();
it traces 112, which is correct but it won't gotoAndStop(112)!
Anyone??
GotoAndStop Using A Variable? Arrghhhh
Ive got a frame with a gotoAndStop action. I want it to gotoandstop to a scene defined by a variable.
ie
gotoAndStop("_root.variablename", 1);
so if the variable was 5 for example it would goto the scene called 5
Is this possible!! i cant seem to get it working
Variable Number = Frame Number#$%@&*
I have a movie Clip called “percentage bar” and a variable text box called “percentage”.
Now I get a number from VB and this number is = to the value of ”percentage” (my variable txt box).
The Movie Clip has a 100 frames… here it comes I need to have whatever the variable number (“percentage”) is to determine which frame the movie clip (“percentage bar”) is standing on.
This has to be possible, don’t it?
Variable Number = Frame Number ?
Here's an easy one for anyone who knows actionscript...
I have a variable text box called "percentage" and a movieClip called "progressbar" (100 frames).
I want the number in my variable txt box "percentage" to tell "progressbar" to go to the corresponding frame number.
for instance if the number in the txt box is 15 the movieclip has to go to frame 15.
Thanks
- a Designer, forced to be a programmer.
Load Movie Gotoandstop(variable)
hithere
since days i am trying to solve this problem...and nothing is really working...
i have a mc that is loaded on the _root in my mainmovie.
with in this mc i have a button object mc that checks how long the mc is.
with this number sent to every button as "link" i weant to gotoandstop within this mc.
the problem is that flash seemes to know the "link"-variable because it is moving to that frame but just never stops...flash doesnt care about stop marks also...what am i doing wrong, or am i blind?!
code:
__________________________________________________ _____________
on (release) {
_parent.gotoAndStop(Number(link));
}
on the mc that contains the button:
__________________________________________________ ______________
_parent.frames = _parent._totalFrames;
for (g=1; g<_parent.frames; g++) {
_parent.boxel.duplicateMovieClip("box"+g, g);
boxnam = "box"+g;
_parent[boxnam].link = g;
_parent[boxnam]._x = g*16;
}
}
here is an example:
http://www.cebes.de/00_test/db/modul_flash/test.html
go to portfolio fotografie and the blue typeline
http://www.cebes.de/00_test/db/modul_flash/test.html
Variable Based Target Of GotoAndStop
I am trying to evaluate the following code and I get a syntax error which I guess is because it starts with an open square bracket.
[passed_Section_Mc].gotoAndStop(passed_Destination);
Basically I have seen others use syntax such as
_parent[passed_Section_Mc].gotoAndStop(passed_Destination);
BUT I do not want to have _parent infront of mine as passed_Section_Mc is on same timeline that the code is being called.
Basically "passed_Section_MC" is a variable representing the name of a movie clip containing the label / marker "passed_Destination"
The code [passed_Section_Mc].gotoAndStop(passed_Destination) is being called from the timeline containing the movie clip "passed_Section_Mc"
GotoAndStop (framelabel) Not Working Correctly If Label Is A Variable
Somebody please explain this to me. And quick, 'cause this needs to be done by 4pm today:) Or at least it did.
I have a scene with 9 keyframes. the last 8 have a frame label corresponding to a direction- NORTH, NORTHEAST, EAST, etc. The first one decides which direction to face.
I have the following code:
trace(directions[dir]);
gotoAndStop(directions[dir]);
the first line of code correctly prints out the name of the direction. the second line of code is supposed to bring me to the frame which has the corresponding frame label. Instead, it brings me to the frame IMMEDIATELY FOLLOWING that frame label. Let's say that frame 2 is NORTH (which has actionscript that traces the word "north"), and frame 4 is the next key frame, NORTHEAST, meaning that frame 3 will show whatever's in the NORTH framelabel as well. My movie goes to and stops at frame 3; it displays whatever's on the screen, but it doesn't display the trace from the actionscript in frame 2.
However, if I replace
gotoAndStop(directions[dir]);
with
gotoAndStop("NORTH");
everything works just fine; the movie goes to and stops on frame 2.
This is seriously whacked. Can anybody explain this to me? Can I get some flash experts to weigh in on this? I know I can work around this by accounting for this and having all the important stuff on the frame immediately following the framelabel, but any errors I leave in there now will be very hard to fix.. in a few days, there will be about 100 scenes just like this one, and I don't want to have to go through each scene to fix it.
Please, can I get a sanity check. Is this a flash bug, or is there a better way to do this?
I can't use frame numbers as I'm not sure which number will be where.. and of course if this is edited later on... eeek. That's a lot of updating of gotos.
Liam Morley
lmorley@gdc.wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
AS3 Creating A Button GotoAndStop Error #1065: Variable Is Not Defined.
I am building a flash website that has buttons to access other pages, ie: Photos, Contact, etc. The code below only seams to work for my Contact button. Both buttons have an instance name assigned to them on the properties tab and is reflected in the code, ie: Contact1, Photos1. For some reason I keep getting Error #1065: Variable Photos1 is not defined.
stop();
function oncontactClick(evt:MouseEvent):void {
gotoAndStop("Contact");
}
Contact1.addEventListener(MouseEvent.CLICK, oncontactClick);
function onphotoClick(evt:MouseEvent):void {
gotoAndStop("Photos");
}
Photos1.addEventListener(MouseEvent.CLICK, onphotoClick);
Number Variable With XML?
Hi,
I am a beginer in importing XML into flash, and I need a little help. I would like to write a number in an XML document and use this number as a variable in AactionScript. Is there a way that it can be done?
Thanks.
If (variable < Number) { //help }
Okay, I'm trying to make a lives system. Here's what I have:
if (_root.lives < 1) {
gotoAndPlay("gameover")
}
It needs to go to frame labeled gameover, but it's not working. Anyone have any idea what the problem is? NOTES:
'lives' is defined as 3 at the start of the game.
Lives system is fully working except for this one little flaw.
Variable + Number
ahhhhhhhhhh how do you do..
Code:
var temp = 6;
temp2 = temp+6;
without it answering 66!!! instead 12!!
Cannot Get Number From Variable
So I have a variable decalred as a number like this:
Code:
function foo(index:Number) {
index = 1;
..}
but when I try to call it like this:
Code:
trace([index] - 1);
...it returns NaN.
Why? I am pulling my hair out, as it is standing in the way of me completing a project.
Set Variable To Be A Number?
I have a Flash movie that pulls a variable from a text file. I need it to add that value to a value within the movie.
My actionscript is something like:
Code:
_level0.team1 = _level0.team1 + _level0.prize;
team1 is a score that starts at 0 within the movie. I want it to increase by the value of the "prize" variable.
So far, it changes the value from 0 to 0100. It is just attaching the value to the zero, not adding them? What do I need to do?
Frame Number As Variable...
hi everybody,
Can the frame number be used in the movie as a variable?
(but not using the name of the frame because i need to type a lot of frame name in the movie.)
Any help is welcomed.Thank you~
Getting Number Variable From Txt File
I'm using the following chunk of code to read a txt file and try to get a number out of it.
loadVariablesNum ("tt_distance.txt", 0);
the .txt file contains one line - &distanceran=99
It reads in the number as an "undefined" data type I stuffed into the variable "distanceran".
Problem is, I cannot seem to set it to an integer or number type. I can see the variable fine (it's text, of course), display it, etc, but I just can't use it for any type of math function (attempts to convert it end up as NaN using parseFloat). It's driving me nuts.
Any help out there?
My Variable Is A String When I Want A Number?
Hi I have mc's named Day0, Day1, Day2 etc. I use this to extract the number from teh name
Fetch = _name.substring(3, _name.length);
it seems I end up with flash regarding Fetch as a string because when I do this to check
ArrayPos = Fetch+2;
flash puts the 2 onto Fetch as a string rather than doing addition.
How do I change this so that Fetch is a number?
thanks mark
_root. .. Variable + Number. _x/y?
I have code getting a number (all this in an MC).
I want to get the x and y values of an MC on the main timeline with the name of "box_" + the number. How can I do this?...
Please Help, How Do I Get The Frame Number A MC Is On To Set As A Variable?
I have some buttons that I want to trigger a remote rollover effect on. So far it works, but I want to do more with it to make it look good. Let me explain what i am trying to do...
I have a movie clip (the instance is called "vault", as in a vault door opening or closing) and it contains the following:
frame 1: stop action, graphics for vault doors are closed
frame 2-15: no action, vault doors remain closed
frame 16: no action, vault doors begin to open
frame 26: stop action, vault doors finish opening.
frame 27: no action, vault doors start to close.
frame 33: stop action, vault doors finish closing.
this is the code I am using on a button, it also loads a photo under the vault doors, but that works fine so it is not important.
Code:
on(rollOver){
vault.gotoAndPlay(2);
_root.photos.loadMovie("goutton.jpg");
}
on(rollOut){
vault.gotoAndPlay(27);
_root.photos.unloadMovie("goutton.jpg");
}
It works, but the reason i have that delay in frame 2-15 is because i want the user to be able to settle on a button to choose before they begin to open. The problem is, if you mouse over and out fast, it slams shut without opening.
So what I want to do is make some kind of code like: IF vault is on frame 16-26 (opening or opened), then play the close animation. Obviously i don't need it to play the close animation if it never got to the open state, it just looks bad.
So, if someone can tell me if this is possible, and how to do it, that would be great! I am guessing i need to make some kind of variable and set the current movie clip frame number (upon rollOut) to that variable, and then i can say if it is between a certain frame number, do the close action (and if not, nothing). but i don't know if that is possible. if there's another way to do it let me know too. thanks.
Subtracting A Variable From A Number
Okay, first off I'm fairly new to this sort of actionscripting, so go easy
I'm having a mental block with this and I'm sure I'm just missing something really simple.
I'm trying to build a dynamic graphic scroller from scratch. Now I've gotten the buttons to shift the graphic up and down by increments - no problems there. My issue comes when I try to set limits on the distance that the graphic scrolls to. The minimum scroll down is no problem; that's just the start co-ordinates of the graphic. The maximum scroll value though is giving me a headache. I basically don't want to have to input a different value for each object being scrolled.
So this is what I figured; if I can subtract the _height of the graphic, from the depth of the bottom edge mask (which is 338px down the stage), it should produce the maximum scroll position in pixels for the graphic. I can set these values manually and the buttons work, so the problem isn't there.
The best I've managed yet is...
_root.maximumScroll = (_root.content._height - 338)
This works providing the _root.content._height bit is less than 338, but everything goes weired when it spits out a negative number.
Can anyone show me where I'm going wrong?
Random Number Using A Variable
Hello Folks,
I'm trying to generate a random number. I want the limit of the random number generated to be defined by a variable. For some reason I just can't get this to work.
here's the code I've been using:
test = Math.floor(Math.random()*_root.number)+1
_root.number is the variable and movie recognises it everywhere except in this code. Any help would be greatly appreciated.
[F8] Help Me I Need To Add A Number To A Variable Dynamically
Please help me to figure out if this is possible...
ActionScript:
//Set the number of aircraft used on the stage (Each aircraft MUST have an instance name of aircraft1_mc, aircraft2_mc... and so on)
var numberAircraft:Number = 5;
//Define variable for each aircraft movieClip as set by numberAircraft
for (var i:Number = 1; i <= numberAircraft; i++) {
var aircraft & i = aircraft & i & _mc.aircraftLabel_mc;
}
I also tried the following...
ActionScript:
//Define variable for each aircraft movieClip as set by numberAircraft
for (var i:Number = 1; i <= numberAircraft; i++) {
var aircraft + i = aircraft + i + _mc.aircraftLabel_mc;
}
Variable Into Frame Number?
Hello everyone - I have a quick question..
What I am doing is building an e-card that the user can customize and mail to a friend. Here is my problem..
I have the user selecting different backgrounds.. and my actionscript is such that if the user clicks "background 1" then var BackGround gets set to "1" etc..
on the other end of the thing, when the ecard is being reconstructed from my text file it is reading variable "BackGround" - Here is my question - I dont want to have to do a bunch of "if" statements (if BackGround = whatever, gotoAndPlay (whatever)
I would like flash to just interpret "BackGround" as a number and go to the appropriate frame. What is the correct way to do this? Am I way off? I thank you in advance for any help!
Variable Not Showing As Number
So I have a variable decalred as a number like this:
Code:
function foo(index:Number) {
index = 1;
..}
but when I try to call it like this:
Code:
trace([index] - 1);
...it returns NaN.
Why? I am pulling my hair out, as it is standing in the way of me completing a project.
Adding A Number At End Of Variable Name
Hey all,
i hope that this is a really easy problem to sort out. I want to be able to add a number dynamically at the end of a variable. This code work fine at the moment;
_root.orderItem1 = _root.itemTitle[0]
_root.orderPrice1 = _root.itemPrice[0]
orderItem1 and orderPrice1 are displayed in a text box. However I want to be able to add a number at the end of the variable name based on another variable named _root.orderNumItems
so the 1 and [0] values i want replaced with the number stored in _root.orderNumItems (the 0 will obviously be _root.orderNumItems-1)
I thought i could just write
_root.orderItem[_root.orderNumItems] = _root.itemTitle[_root.orderNumItems-1]
but flash doesnt like it, please help me as i dont want to just write the code hundreds of times over for each number,
cheers
griff
Variable Not Recognized As A Number
can someone please tell me why these variables are not being recognized as numbers?
calculateplayingenergy = elapsedS*0.16 + elapsedD*3.84;
calculatestandbyenergy = elapsedS*0.02 + elapsedD*0.14;
calculateplayingcost = elapsedS*0.03 + elapsedD*0.72;
calculatestandbycost = elapsedS*0.0000003 + elapsedD*0.00072;
ActionScript Code:
//initial variables
var timing:Boolean = false;
var paused:Boolean = false;
var remaining:Number;
var elapsedTime:Number;
var elapsedHours: Number;
var elapsedD:Number;
var elapsedS:Number;
var elapsedH:Number;
var startTime:Number;
var remaining:Number;
var minutes:String;
var seconds:String;
var calculate_playingenergy = String;
var calculate_standbyenergy = String;
var calculate_playingcost = String;
var calculate_standbycost = String;
_root.onEnterFrame = function() {
if (timing) {
//calculate values
elapsedTime = getTimer()-startTime;
//hours
elapsedHours = Math.floor(elapsedTime/3600000);
remaining = elapsedTime-(elapsedHours*3600000);
//minutes weeks
elapsedD = Math.floor(remaining/24000);
remaining = remaining-(elapsedD*24000);
//seconds
elapsedS = Math.floor(remaining/1000);
remaining = remaining-(elapsedS*1000);
//hundredths
elapsedH = Math.floor(remaining/10);
//output to text box
//add a 0 on the front of the numbers if the number is less than 10
if (elapsedD<10) {
minutes = "00"+elapsedD.toString();
} else if (elapsedD<100){
minutes = "0"+elapsedD.toString();
} else {
minutes = elapsedD.toString();
}
if (elapsedS<10) {
seconds = "0"+elapsedS.toString();
} else {
seconds = elapsedS.toString();
}
if (elapsedH<10) {
hundredths = "0"+elapsedH.toString();
} else {
hundredths = elapsedH.toString();
}
_root.timer_txt = +minutes+":"+seconds;
} if (_root.currentframe == 1) {
calculateplayingenergy = elapsedS*0.16 + elapsedD*3.84;
calculatestandbyenergy = elapsedS*0.02 + elapsedD*0.14;
calculateplayingcost = elapsedS*0.03 + elapsedD*0.72;
calculatestandbycost = elapsedS*0.0000003 + elapsedD*0.00072;
}
}
_root.onLoad = function() {
if(!_root.timing) {
if (_root.paused) {
_root.startTime = getTimer() - _root.elapsedTime;
} else {
_root.startTime = getTimer();
}
//start timer
_root.paused = false;
_root.timing = true;
_root.cost = calculateplayingcost+calculatestandbycost;
}
}
_root.stop_btn.onPress = function() {
//stop the timer
_root.timing = false;
//reset the paused variable
_root.paused = false;
//reset the display textbox
_root.timer_txt = "000:00";
_root.cost = "000.00";
_root.energy = "000.00";
}
_root.pause_btn.onPress = function() {
//only pause if the timer is actually going
if(_root.timing) {
_root.timing = false;
_root.paused = true;
}
}
_root.lightswitch.onPress = function() {
if (_root.lightswitch._currentframe == 1) {
_root.lightswitch.gotoAndStop(2)
_root.timing = false
_root.paused = true
}
else if (_root.lightswitch._currentframe == 2) {
_root.lightswitch.gotoAndStop(1)
_root.timing = true
_root.paused = false
}
}
_root.power_btn.onPress = function() {
if (_root.power_btn._currentframe == 1) {
_root.power_btn.gotoAndStop(2)
_root.timing = false
_root.paused = true
}
else if (_root.power_btn._currentframe == 2) {
_root.power_btn.gotoAndStop(1)
_root.timing = true
_root.paused = false
}
}
Min And Max Values For A Number Variable?
Hi, this is hopefully a simple question.
Is there any way to set a minimum and maximum value for a number variable, preferably when it's being created?
Thanks for your help.
Check Variable Is A Number
Hi Reader,
In ASP you can do:
Code:
If IsNumeric(Values(1)) Then
But I cannot find a way to do it in ActionScript, do you have any idea.
Basically the user enters some data and I need to check that a part of it is a number. Resctricting the text field to only allow numbers is no use in this situation.
Thank you for your time.
Leah
Frame Number Into Variable
Does anyone know how to get the frame number from a movie and insert the number into a variable that is located in a different movie.
Add Number To Global Variable?
Hey there all,
just a quickie.
If I have
_global.gCost = 0;
on the main timeline
and then later on i want to increase gCost by a number (say 5), how do I do that, cause
_global.gCost +5;
doesn't work.
Thanks in advance.
Frame Number Variable
Hello
Is there a system variable that tells me what frame the movie is currently at ?
(I simply want to display the percentage of the movie that has played, in a dynamic text box - maybe there's a simple way ?)
Thank you
Highest Number Variable?
oh this should be sooo easy but i just cant work it out. Check the code:
Code:
var myCategory1 = 3;
var myCategory2 = 6;
var myCategory3 = 10;
var myArray = Array(myCategory1, myCategory2, myCategory3);
myArray.sortOn(18);
trace(myArray[0]);
So as we (all) know Flash will trace the number 10 (highest number in the array), but i need to know what variable 10 came from? eg. did 10 come from myCategory1, myCategory2, myCategory3?
Tom
|