Random Insanity Alliance Forum, Mark V
Cactuar Zone => Random lnsanity => Topic started by: KingRanter on November 06, 2008, 02:44:12 pm
-
I've got like 3 things i have to do in flash for 2morrow at school. im gonna be doing this all day. i need help though with some of the actionscript, as i am not sure what to do about it. I am requesting the help of the RIA to fix my stupid little issue with one of them.
the smallest thing is, i have to have 2 textboxes, one input and one dynamic. I need to make the input texbox have a number in it and the dynamic, on button press (or release) to show that numbers absolute value. I have the following code on the button:
[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']on (release)
{
if (i.text >= 0)
{
a.text = i.text
} else if (i.text < 0)
{
a.text = i.text / -1
} else if (i.text >= "a" and a.text <= "z")
{
a.text = "NaN"
} else if (i.text >= "A" and a.text <= "Z")
{
a.text = "NaN"
}
}
i = initial value (input textbox)
a = absolute value (dynamic textbox)
its supposed to take the number and put it in the dynamic textbox, if its less than 0 then it divides it by -1 and then outputs it, and if it isn't a letter it outputs "NaN" which would mean "Not a Number". I also need it to output "N/A" when there's nothing in the input box and the button is pressed.
at the very least, tell me what i'm doing wrong and how to fix it please.
-
By button, are you using mouseclick, keyboard key, or just an overall button?
BTW, it helps to put your else if statements on a seperate line then your {} or your Squigglies (as we call them).
also, are you using CS3 or CS4? Actionscript 2 or 3?
SOME MOAR INFO PLS.
-
Flash MX because thats all the school has, so actionscript 1
i have CS4 on my computer but it doesnt convert so my teacher wouldnt be able to see how i did the code, so i had to install flash MX on my computer. anyway.
its a click button. on(release) and whatnot. its actually the blue arcade button in the common libraries (or common libraries in the classic folder in CS4)
-
well, for outputting if noting is in there, try something like:
else if (i.text >= "")
{
a.text = "NULL"
}
That should give you it outputting "Null" if noone puts anything in the next box.
Also, do you have your variables and functions somewhere else? I'm going to assume this isn't the whole program...
One se,c your code is ALL jacked up...
-
try this:
[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']on (release)
{
if (i.text >= 0)
{
a.text = i.text
} else if (i.text < 0)
{
a.text = i.text / -1
} else if (i.text >= "a" and i.text <= "z")
{
a.text = "NaN"
} else if (i.text >= "A" and i.text <= "Z")
{
a.text = "NaN"
}
}
You had to change the a.text is the second because your a.text is undefined (or null, or whatever the default in variable declariations sets it to).
It has to be that if the contents of i.text are between A and Z. you had it set so that if I.text is > A and A.text (currently undefined), is < Z. That doesn't work. Especially since when it meets a condition, it changes the contents of a.text anyway.
Understand me or am I just confusing?
-
I think i get it
and this is actually everything. i dont seem to work with textboxes well >_>
is the code in the codebox u put fixed up a bit?
-
-_-'
anyway, try the code I posted. If it works, AWESOME. If not, I'll check back in about a half hour and might have a solution. I'm going to register for classes at the moment...
yea, codebox code is fixed.
-
ok i had something like this before, with the same result
the absulute values are showing up with the numbers, but when letters are inputted it outputs the same letter and when i click the button with nothing inputted, nothing shows up
-
Oh one sec.
let me fix the code-box. I never added the Null for "" code...
-
Ok, heres the new box:
[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']on (release)
{
if (i.text >= 0)
{
a.text = i.text
} else if (i.text < 0)
{
a.text = i.text / -1
} else if (i.text >= "a" and i.text <= "z")
{
a.text = "NaN"
} else if (i.text >= "A" and i.text <= "Z")
{
a.text = "NaN"
} else if (i.text = "")
{
a.text = "N/A"
}
}
I can't tab because internet explorer won't let me, and I don't have access to a computer with flash at the moment.
Also, to fix your problem, there are a few things I can suggest
Maybe throw in a function listener for any key that isn't a number-key to be ignored, or to list the error "NOT A NUMBER".
Or, throw in an if statement that says "If i.text is a string, not a number, then a.text = "Not A Number"." Something like that. I don't have flash in front of me, and I'm trying to work from memory.
then again, I use AS 3 so... yea.
Oh, try this for a qucik test:
Adjust the else if (i.text >= "A" and i.text <= "Z") line to else if (i.text = "A")
then, run the program and put A into the textbox and see if the dynamic posts "NaN" as the response. If ti works, let me know and change the code back. I'll work on trying to figure it out.
-
Good god. Don't get me started on formatting. @_@
-
that quick test turned out false
the new code doesnt seem to be doing anything different than the old code
also, about one of my other things, how can i get a bunch of objects to turn invisible at once using a button, and then use the same button to turn them visible again?
-
Yea, the code is HORRIBLY formatted.
Part of the problem, might be that you didn't declare the variables as string or interger.
hell, you didn't even DECLARE variables. I wish I had CS3 or 4 of my laptop so I could fiddle with code till I get what I want...
Do you have to use the code you've written, or can we re-write the code?
-
How about this:
[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']on (release)
{
if (i.text >= 0)
{
a.text = i.text
} else if (i.text < 0)
{
a.text = i.text / -1
} else if (i.text != 0 and i.text !>0 and i.text !<0)
{
a.text = "NaN"
}
}
try that.
-
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 9: ')' expected
} else if (i.text != 0 and i.text !>0 and i.text !<0)
-
Sorry, I fixed it. 1 too many }'s. It should work now. Copy+paste the code-box.
-
no its the same problem, i fixed the extra } on my own, but apparently theres a ) thats expected or something
what i sent you was the exact debugger message
-
oh, also, because of that issue it seems that the button doesnt do anything
-
Flash MX because thats all the school has, so actionscript 1
i have CS4 on my computer but it doesnt convert so my teacher wouldnt be able to see how i did the code, so i had to install flash MX on my computer. anyway.
its a click button. on(release) and whatnot. its actually the blue arcade button in the common libraries (or common libraries in the classic folder in CS4)
cs4 >_>
-
ok, i'll just get one of my friends at school to give me the code from his. it's gonna be a freak nuicance for the both of us but there's no other way i'll be able to drive myself to do anymore of this tonight. good news though, i finished the other 2 things, i might post them sometime >_>
-
I dunno.
Next time, declare your variables and make it a function instead of the craziness it is right now. That will save time debugging and give me more info to help you with.
BTW, CS4 FTW!
-
I ended up using what i had before. it showed the absolute value of numbers and if there were letters, the stupid letters showed up. >_>
-
o btw, i HAD CS4. but when i opened it up today, it was really Fucking gay. outputting shit constantly that seemed useless. so i uninstalled it. >_>
im fine with MX. i only need it for school anyway
-
WIN
import flash.events.TextEvent;
input.addEventListener(TextEvent.TEXT_INPUT, textInput);
input.restrict = "0-9";
function textInput(e:TextEvent)
{
if (parseInt(input.text) > 0)
{
output.text = String(input.text);
}
else if (parseInt(input.text) == 0)
{
output.text = String(input.text);
}
else if (parseInt(input.text) < 0)
{
output.text = String(parseInt(input.text) / -1);
}
else
{
output.text = "NaN";
}
}
-
WIN
[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']import flash.events.TextEvent;
input.addEventListener(TextEvent.TEXT_INPUT, textInput);
input.restrict = "0-9";
function textInput(e:TextEvent)
{
if (parseInt(input.text) > 0)
{
output.text = String(input.text);
}
else if (parseInt(input.text) == 0)
{
output.text = String(input.text);
}
else if (parseInt(input.text) < 0)
{
output.text = String(parseInt(input.text) / -1);
}
else
{
output.text = "NaN";
}
}
-
my apologies but your tooooo late :\
-
But it's correct.
so...
BOW BEFORE MY MIGHTYNESS
-
k
-