Topic: Variables from input text (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=11223" title="Pages that link to Topic: Variables from input text (Page 1 of 1)" rel="nofollow" >Topic: Variables from input text <span class="small">(Page 1 of 1)</span>\

 
kretsminky
Maniac (V) Inmate

From: A little lower... lower... ahhhhhh, thats the spot
Insane since: Jun 2000

IP logged posted posted 09-25-2001 18:24 Edit Quote

I've been playing around with creating motion with ActionScript that is dependent on numbers entered by a user.

Apparently there is some rule that I don't know about and I haven't been able to find anything that explains it.

For instance, lets say I have a field that asks for a velocity and is named velX.

Why can't I just put that straight into the movement function like:

code:
if (object._x < 350) {  
object._x += velX;
} else {
stop ();
}



I've noticed that I have to do "something" with that variable, even something as simple as multiplying by 1 just to get it to work.

Whats the trick here that I am missing?


Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

IP logged posted posted 09-25-2001 19:10 Edit Quote

Uh - sorta skimping on the details, eh?

I assume you have made an input text field, and named that field (in the "variable" field of the text palette) with the variable you want - for example velX.

So the user inputs a number - then what? Do they click a button to activate the motion? Was there a stop action prior to the input?

First step in debugging is to do what I suggested yesterday:
trace(velX);

if you get a blank window, the script isn't getting the input and you have to ask yourself at which point did the communication flow break down.

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

IP logged posted posted 09-25-2001 19:53 Edit Quote

http://people.ne.mediaone.net/s-nelson/ozone/mover.html

Fig
Paranoid (IV) Mad Scientist

From: Houston, TX, USA
Insane since: Apr 2000

IP logged posted posted 09-25-2001 20:08 Edit Quote

Cool stuff Steve...

*fig searches for spare time to play with actionscript*

chris


KAIROSinteractive

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

IP logged posted posted 09-25-2001 20:08 Edit Quote

Do you get what happened? Me neither. I mean I know what, just not why. The input value is being treated as a string, not a numeric value. So if the object starts at 22 and you input 5 into the text field, it concatenates the two numbers, instead of adding them: object's x becomes 225! on the first loop instead of 27.

How did I figure this out? My friend trace();

Using the Number() function is a hack. I'm sure there is a cleaner, better way. I just haven't figured it out yet, and Number() works, so go for it!

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

IP logged posted posted 09-25-2001 20:52 Edit Quote

Okay. Quick consult w/ the almighty Moock.

Data derived from user input text fields is always of the string data type.

There are several ways to deal with this. One I showed you: Number(x) converts x from a string to a numeric value.

parseInt(x) also converts x to a number with the advantage of dropping any non-numeric info, so if some wise acre put in "6 miles per hour", parseInt() would ignore anything not a number. It will also discard any decimals, so parseInt("10.8 mph") would return 10.

parseFloat() would keep a floating point number: parseFloat("10.95 US Dollars") would return 10.95 - obviously useful if the input was currency, but also useful for keeping any decimal data.

You got it straight now?

kretsminky
Maniac (V) Inmate

From: A little lower... lower... ahhhhhh, thats the spot
Insane since: Jun 2000

IP logged posted posted 09-25-2001 21:02 Edit Quote

Ahhhhhhhhhhhhhhhh, muchas gracias once again.

Once I saw your example I was good. I had mine set up exactly like you have yours except for the Number(velX). I was wondering if you could parse integers like in JS yesterday at work I just forgot to go look when I had the time.

It was really frustrating me that var velocity = velX; didn't work but I could put var velocity = 1*velX and it would work!

Geez I've got a lot to learn.

Thanks again. I'm going to owe Steve my first born if I keep going at this rate.

kretsminky
Maniac (V) Inmate

From: A little lower... lower... ahhhhhh, thats the spot
Insane since: Jun 2000

IP logged posted posted 09-25-2001 21:04 Edit Quote

Yep, just tried it, works beautifully now as does your suggestion on incrementing my time (t) variable.

The Poo-Canon might just live on after all!

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

IP logged posted posted 09-25-2001 21:12 Edit Quote

Ugggh.
What is the difference between your first born and a poo-cannon?


Heh. Keep the kid. I've got enough already.
Glad it worked. As usual, I learned something too.
Now that you've got velocity down, get to work on acceleration!

[This message has been edited by Steve (edited 09-25-2001).]

kretsminky
Maniac (V) Inmate

From: A little lower... lower... ahhhhhh, thats the spot
Insane since: Jun 2000

IP logged posted posted 09-25-2001 21:27 Edit Quote

he he I guess you've got a point there Steve.

Just to show you that I am actually doing something with this, here is what I was trying to accomplish....
http://www.krets.net/misc/pootest.html

Next I just need to do a little something to make the motion smoother as the instantaneous velocity increases within each time increment.


he he As you can tell from the Go button I was getting a little frustrated at one point.


[This message has been edited by kretsminky (edited 09-25-2001).]



Post Reply
 
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
 
Your Text:
Loading...
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu