Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash








Adding Or Subtracting 1 Or Any Number To Your Variable.


_level0.book.gotoAndStop(_level0.page++);

I have my input field called page that I type a number into it and it will make the book movie instance goto that frame number thats in the page input field. Problem is that the frame it goes to is 1 less than the frame i want it to go to.

If I type in 5 in the input field, it makes the book movie go to frame 5 but I want it to go to frame 6 so I am trying to add 1 to it.

Also how would I make it go 1 less.

Also what ever number less or more I want it to go to. Like 6 more than whats type in the page input field.

Thanks




DevShed > Flash Help
Posted on: May 6th, 2008, 11:15 AM


View Complete Forum Thread with Replies

Sponsored Links:

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?

View Replies !    View Related
Subtracting X Pos To An Always Positive Number
I need to compare the x position of two movie clips on the stage for an if statement, but the clips can go anywhere (with a positive or negative ._x value).

I want to compare how far they are and if they are close to each other than execute code, but the problem is the value can be either positive or negative because the right object can move to the left of the left object. I don't want to clutter the code with multiple if statements if I can avoid it.

Is there a Math method or to always return a positive number or to intervert a negative into a positive?

Is there some other way that I could accomplish my goal of determining if two objects are the specified distance?


Code:
leftPosition=10;
rightPosition=20;
comparePosition= leftPosition -= rightPosition;// returns a negative number
trace(comparePosition);//-10
//
if (comparePosition>9){// the if statement should determine the max pixels they are apart regardless of the object's relative position
//do something
}
else{
trace("Need to make positive");
}

View Replies !    View Related
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

View Replies !    View Related
Adding & Subtracting
Hello.
I'm trying 2 write a script that on a button press adds 70 to a variable with the option to add as may 70's as ilke and on another button press subtracts 70 to that same variable again subtract as many as i like.


does anyone have any suggestions??????????

View Replies !    View Related
Adding And Subtracting
I have a button and a dynamic text box. I want it so that when i click that button it adds 1 to the total. It works for me but the problem is that when I click it it adds 1 but when i click it again it doesnt add again. Heres my code:

on (release) {
item =+1;
}

I want it so EVERY time you click the button it adds 1.

View Replies !    View Related
Adding A Number To Make A Variable
Hello,


I've got a small problem and its annoying me because i dont know what to do!


ActionScript Code:
var xmlName1 = "number1"
var xmlName2 = "number2"
var xmlName3 = "number3"

var NameNumber = 2


something_txt.text = xmlName+NameNumber

instead of reading out, "number2" i get NaN, i know why, just i dont know what else to do to make it work.

Can somebody help!!!!!!!!!!

Thankyou

View Replies !    View Related
Adding A Variable Number To A Mc Path
I extarcted a number that I want to add on to a instance name to find the x of that mc

Code:
function checkHomePos() {
if (_root.pannelDrag) {
this.whatPanel = _root.currentPanelView;
n = Number(this.whatPanel.substring(1));

this.homeX=_root["bgP"+n]._x;
trace("BGP :" +_root["bgP"+n]);
trace("N :"+n);
trace("HOMEX :" +this.homeX);
}
}
_root.createEmptyMovieClip("menuChecker1", _root.depth++);
menuChecker1.onEnterFrame = checkHomePos;
Ok I have a variable n which holds a number. Now I want to find the x position of the mc bgPn
All my bgP clips are named bgP1 to bgP20 so I want to be able to us the number in n to add on to the end of bgP so it will represent the bgP clip I need.

View Replies !    View Related
Adding/Subtracting Calculator
I am creating a calculator in flash that lets the end user type in 3 separate amounts (qty1_txt, qty2_txt, qty3_txt) that while you are typing it is being added up into the amount category (priceTotal_txt) and in another amount category (qty4_txt).
OK, now this is where it gets tricky... Along with (qty4_txt) there is another input area (qty5_txt) that will let you SUBTRACT this amount from (qty4_txt) and gives you a new amount in a new area (priceTotal_txt2). These amounts need to be added and subtracted while the person is typing. How can I get the amount ((qty4_txt) to Subtract (aty5_txt) separtately?
The client doesn't want a "Calculate" button... I wish they did because I can get that to work with no issues!
This is what I have so far.

var input1 = 1;
var input2 = 1;
var input3 = 1;

//Calculate quantity times price
this.onEnterFrame = function() {
priceTotal_txt.text = Number(qty1_txt.text)*Number(input1)+Number(qty2_t xt.text)*Number(input2)+Number(qty3_txt.text)*Numb er(input3);
qty4_txt.text = Number(qty1_txt.text)*Number(input1)+Number(qty2_t xt.text)*Number(input2)+Number(qty3_txt.text)*Numb er(input3);

};

Also, if anyone knows how I can make this thing keep the zeros after the decimal points, I would greatly appreciate it. (e.g. $49.50) Its showing up as $49.5
thanks!

View Replies !    View Related
Adding/Subtracting Numbers
Can anyone direct me to tutorials explaining how to determine numeric values and either add or subtract them using dynamic text boxes and input text boxes?

Thanks in advance! Missmetz

View Replies !    View Related
Adding And Subtracting In MX 2004
Hi Guys,

I am a moderate flash user. I can handle Actionscript. Actually what I need is... I need to add and subtract in flash. I am creating a flash, where there is a car and users can add color and extra components to the car....so whenever they add or remove a componment we should show the amount for that component added to the total...or subtracted from the total if they remove a component.....to be more appropriate please visit this site...

http://www.hummer.com/

I came across this cool site while browing. I need to create a flash similar to this.....Somebody please help in how to go about creating this kind of flash......

Appreciate your help.

Kind Regards,
Anthony.

View Replies !    View Related
Dynamic Adding And Subtracting
I basically have a dynamic text field that has a var of r1c1
and two buttons that change the value +1 or -1

But I want to set the value from 0 to 9 and if you go below 0 it goes to 9

Can anyone help?

basically right now on the two buttons I have

r1c1++ and r1c1--

Thanks guys

View Replies !    View Related
Adding And Subtracting Should Be Simple
I'm trying to have a dollar amount appear in a text field that also up or down based on their answer; in short a score.

But the initial amount will not display at any point in the txtBudget field nor will it add or subtract correctly based on what the trace statements are telling me. I'm missing something here and I can't quite put my finger on it. Any help would be appreciated. Thanks!








Attach Code

//FRAME 1
var Budget:Number = 100000;

txtBudget.text = "$" + Budget;
//trace(Budget);

//FRAME 2 (repeats in similar fashion in rest of main time line)
function AnswerTree1()
{
//you can ignore the AnswerPath value for now, they are a part of something else)
if(AnswerPath == -1)
{
//ignore the ._visible changes too, they are also a part of something else
mcProgress.n1b._visible = true;
mcProgress.n3._visible = true;
Budget - 25000;
UpdateBudget();
}
if(AnswerPath == 1)
{
mcProgress.n1a._visible = true;
mcProgress.n2._visible = true;
Budget + 25000;
UpdateBudget();
}
}

function UpdateBudget()
{
txtBudget.txt = Budget;
}

trace(Budget);

View Replies !    View Related
Animation Adding And Subtracting?
Couldnt think of a name for what I want to do so Ill explain...

THIS is a quote engine for a client who specialises in digital print.

The user basically chooses their required print job specs and eventually they'll get emailed their quote.

In the space top right I want to add some animations that play on each button rollOver...which I can do no problem, except for when it comes to choosing the quantity, if possible, can I have say 4 boxes appear when then hover over 400, then when they move to 300 can one of them boxes be animated out (like you're taking it away, or if the hover over say 500, another box animates in to join the original 4 if that makes sense. I gather it is possible but Im unsure how to go about it......have each box as a separate MC but what AS would make them add and subtract themselves?

Hope that makes sense!

Andy

View Replies !    View Related
Flash Adding And Subtracting Gives Crazy Figures
HI all,

i have had this problem before, adding and subtracting values in a shopping cart, but cant remember how i solved it!!

i am merely adding and subtracting values on the basis of press a "+" button to increase an amount of an item by one in your shopping cart and press the "-" button to decrease the amount by one.

I have a total box that adds up all the individual total sections

standard so far and indeed the code on the buttons is very simple

"+" button
//=============
on (release) {
subtotal = subtotal + 9.99
}
//=============

"-" button
//=============
on (release) {
subtotal = subtotal - 9.99
}
//=============

As you can see, simple stuff - the problem occurs when i click the add button 3 items or more and then the subtract button to get back to zero items, when i click to reduce from 9.99 to 0 i get a negative number -3.5527.

adding 1 item and then taking away 1 item gives subtotal 0
adding 2 items and then taking away 2 item gives subtotal 0
adding 3 items and taking away 3 items gives subtotal -3.5527

Can anyone tell me why this is ?

Does flash suddenly not know how to subtract 9.99 from 9.99

????

Thanks in advance

gilesb

View Replies !    View Related
I Need Some Help With Simple Adding And Subtracting Wifh Actionscipt
In a collision i need to learn how to subtract or add with a text field i made. This is a two player game, so i need two sets for health and amo. And i also need to lean that if it reaches zero that it would go on to any other scene. I would appreciat if anyone could help me out.

View Replies !    View Related
Variable Subtracting
how would i do this?


PHP Code:



on(release){
    set("variable", current value - 1?);


View Replies !    View Related
Problem Subtracting One Variable From Another
Hi guys,
I'm having some problems subtracting one variable from another.
Both are number variables.
The 1st variable comes from a getTimer, when the Space bar is hit
the 2nd variable also from a getTimer, the time when a movie is at a certain coordinate.
CameraView is a car movie, and collision is basically a movie that the user has to break (hit Spacebar), and their reaction time is measured.
I just know I've done something silly!
Any help would be greatly appreciated

Here is the code:

obstacle = function(){
zposition = cameraView.z;
xposition = cameraView.x;

if (cameraView.x >=-450 and cameraView.x <=450 and cameraView.z >=3000 and camera.z <=3500){
collision.x = 0;
collision.z = 3500;
collision.y = 20;

if (collision.x==0 and collision.z==3500){
var timercollision:Number =getTimer();
obstacle = timercollision;
var diff:Number = (timer - timercollision);
difference.text = diff;
}
}

}
cameraView.onEnterFrame = obstacle;

View Replies !    View Related
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);

View Replies !    View Related
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?

View Replies !    View Related
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.

View Replies !    View Related
Adding A Number To A Value
hi , im trying to set a variable like so :

xPlace = _root.musicPlayer.volumeChanger.volScaler._x + 2.4

however ,istead of getting a nubmer i get a string : -4.44089209850063e-16

now since the X of the element im using is 2.4 i expcted xPlace to be a zero,
i noticed that i can use such statement with true numbers however not with numbers like 2.5 and 5.6 ...

how DO i write it down so it will calculate the experssion currecly ?

View Replies !    View Related
Adding 1 To A NUMBER
Hi. I want to be able to add/subtract 1 to a number that is in a dynamic text box, when the user presses the up or down arrows (up to add down to subtract). I know how to control the up and down arrows, my problem is adding 1. I can't seem to mathematically add 1... I can make it so that when the user clicks the up arrow, it adds a 1 to whatever was in it before, so basically, if the contents was 02 before, it would turn into 021... But I want it to go from 02 to 03, or 02 to 01! HOW CAN I DO THIS?!?!
Any help is GREATLY appreciated!!

Thanks,
Sportzguy933

View Replies !    View Related
Adding Number
i want a textbox to start out with the number 100000
and then on frame 2 it adds 1 to the number
so everytime i go back to frame 2 it adds another number...

also, does the textbox need to be dynamic, static, or input???

View Replies !    View Related
Number Adding Issues :/
y is it that with this code:
var x = 2;
var y = 2;
var z = x+y;
output.text=z;

the number in the output.text field will b 22
and how do i fix it so that it says 4?

View Replies !    View Related
Adding Number Vars
Code:
function loadIssueBody( section:Number ) {
trace ("section "+section);
for (i=0; i<issueSectionContent.length; i++) {
this.txt.htmlText += "<a href="asfunction:loadIssueBody,"+(Number(section)+1)+"">Next Page</a>";
}

Quote:




Not working. Its actually just appending teh number - like 1 becomes 11. or 0 becomes 01. Any ideas?




works. (Number(section) did it.

View Replies !    View Related
Adding With A Number Array
I have an array, strictly numbers, how could I add...
say array[0](value=2)+array[1](value=1) to equal 3? What I come up with is an undefined error, or not a number...


Thanks


-TJ

View Replies !    View Related
Number Variables Not Adding Up
Hi



I’m using loadText function to grab some variables from a php file, the problem is the variables are coming in as strings and so when I try and use them in an addition they’re just sticking them on the end rather than adding the two values together?



Is it possible to declare a _global variable as a number?



Cheers

View Replies !    View Related
Adding With A Number Array
I have an array, strictly numbers, how could I add...
say array[0](value=2)+array[1](value=1) to equal 3? What I come up with is an undefined error, or not a number...


Thanks


-TJ

View Replies !    View Related
How Do I Convert A String Variable Into A Number Variable?
How do I convert a string variable into a number variable?

Thanks in advance.

Garry

View Replies !    View Related
Adding Child At Certain Frame Number
Dear users,
I want to addChild at certain frame say 130.
And I used the following format

var btn1:Button = new Button();
gotoAndPlay(1);
addings();
function addings():void
{
if(MovieClip(theRoot).currentFrame == 130)
{
trace(" Frame 130");
addChild(btn1);
}
}


And I can't get the output and even I can't get the trace result
Please help me how to add childs at any frame number I want

View Replies !    View Related
Adding And Substracting Number Variables?
hi, I've got a question
If I want to add or substract number variables, how can I name them to indicate they are numbers and how can I do basic math with them?

If I try adding common variables like
_root.answer = _root.var1+_root.var2;
and if var 1 is = 1
and var 2 is = 2
The answer is 12 not 3

so... ? help!

View Replies !    View Related
Adding And Substracting Number Variables?
hi, I've got a question
If I want to add or substract number variables, how can I name them to indicate they are numbers and how can I do basic math with them?

If I try adding common variables like
_root.answer = _root.var1+_root.var2;
and if var 1 is = 1
and var 2 is = 2
The answer is 12 not 3

so... ? help!

View Replies !    View Related
Adding An Automated Version Number On Compile
Hi there,

I'm currently working on a Flash based internet application that customers subscribe to. We have been looking into possible ways of adding a version no. to the application at compile time - this way we can track which version people are currently using.

Has anyone got any ideas on how this could be possible? Most things that I have tried change on run-time and we really do need something that will be set in concrete (at least until a developer next compiles a new version).

I'm trying to get away from having to manually add a version number (as most developers will probably forget to change it each time) - keeping it automated would be so much better.

Any suggestions would be great.

cheers

the whippet

View Replies !    View Related
Adding A Text Field To A Number Of FLA Files
I have a number of SWF and now I need to add an entry text field to all of
them.
I do not want to find myself creating a text field in every single FLA
I wonder if I can create in, say, in an .AS file using something like
createEmptyMovieClip and then include it into relevant FLA?
Or what other solutions are available?

View Replies !    View Related
Adding Unknown Number Of Files To An Array
Hi,

I'm wanting to populate an array with all files in a specific folder without knowing the file names or how many files there are.
Is this possible?

thx

View Replies !    View Related
Simple Rookie Question: Adding Variables To Number
hi,

this might seem to simple for anyone to ask but i just dont know it:


i have to gather a few numbers from several input-textfields and add them together to get the total number.

but if one or more input-fields are not filled out, the value of that field turns to 'undefined' and i cant add them values anymore.

how can i add only the number together and leave the undefined fields out of this equation?



ActionScript Code:
var minQuantity:Number = Number(sizeXS + sizeS + sizeM +sizeL + sizeXL + size2XL + size3X);

trace(minQuantity);

please help me out

View Replies !    View Related
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.

View Replies !    View Related
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.

View Replies !    View Related
Variable + Number
ahhhhhhhhhh how do you do..


Code:
var temp = 6;

temp2 = temp+6;
without it answering 66!!! instead 12!!

View Replies !    View Related
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.

View Replies !    View Related
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?

View Replies !    View Related
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~

View Replies !    View Related
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?

View Replies !    View Related
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

View Replies !    View Related
_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?...

View Replies !    View Related
FLASH 5 How Do I Set The Variable Number?
how do i set the variable number so it will stop when it hits zero? this will be used in a game i am making, and i need it for ammunitional purposes. thanks.

View Replies !    View Related
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.

View Replies !    View Related
Can You Use The Frame Number As A Variable
if a mc is stoped somewhere, is there anyway of retrieving it's frame number and using it as a variable?

View Replies !    View Related
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.

View Replies !    View Related
[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;
}

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved