ActionScript 3.0 :: Make Shorthand If Statement?
Jan 15, 2011Code:
if (myBoolean){
mc.gotoAndStop(2);
[code].....
Code:
if (myBoolean){
mc.gotoAndStop(2);
[code].....
As I get into more advanced ActionScript, I start wondering about ways I can write things more quickly. For example, this code
ActionScript Code:
button1.onRelease = function() {
//something
[code].....
I ran across this: queue.push ({src:xmlItem.@src, title:xmlItem.@title, url:xmlItem.@url}) I know what it does but I can't find the expanded code version
View 5 RepliesI've built controllers for the application which are defined in the Document class while the get & set methods are in the appropriate class. I find they become very screen real-estate intensive once you have more than 10 methods so i was wondering if anyone could let me know a way for writing them which has one function and sets and gets all the properties. heres some of them which define all the height,width, color,stroke,fill,tint of a drawn rectangle.
[Code]...
Is there an easier way to do this?
ActionScript Code:
if(!mc.visible) mc.visible=true;
Didn't know if I've missed some kind of reversal syntax that could instruct an IF statement to reverse it's value if it is true.
ActionScript Code:
//theoretical reverse method
if(!mc.visible) reverse;
I'm trying to get better at coding but I'm having a hard time with this one. How do I turn this into shorthand:
[code]...
What the syntax is for removing the listener when writing it shorthand?[code]...
View 2 Replieswhats the best way to make a statement run just once?at the begining of my movie i have a few default values i wish to be set, but only the 1st time thru, i have done this before by doing something like this
Code:
xxx=xxx+1
if(xxx==1){
///some stuff here
}
but this no longer seems to work with AS2.0 since it produces a NaN error
I'm trying to make my code a little more readable by dividing a very long if statement in multiple sections.It looks something like:
if (a==2 || b == 1 || c == 3 || d == 6) {
// do something
}
And I want it to read something like:
if (a==2 || b == 1 ||
c == 3 || d == 6) {
// do something
}
how to group up the arguments, since that cannot be done in the original.
whats the best way to make a statement run just once? at the begining of my movie i have a few default values i wish to be set, but only the 1st time thru, i have done this before by doing something like this [code]but this no longer seems to work with AS2.0 since it produces a NaN error.
View 2 RepliesI made a multibutton menu and I have a sound set to play when you click each of the buttons but the sounds play over one another if buttons are pressed one right after the other. I know theres a way to make each sound stop using an if statement just cant figure it out.
View 0 RepliesI have a large group of functions.The function to be called depends on the value of a var (which is a int);I could make a long case statement along the lines of this
PHP Code:
var Pos:int = 0;function test1():void{ trace("Test 1");}function test2():void{ trace("Test 2");}function test3():void{ trace("Test
[code]....
I have the following code in the main timeline:
[Code]...
how to make the final trace statement work?
I hope the following is pretty self explanatory. There is a ball movie clip "mc1" on stage. The addEventHandler simply starts a tween and the ball rolls from left to right until it's off the stage. I'm simply trying to make the clip stop when it reaches a certain x value on stage. I'm trying to teach myself simple techniques for the if statement and loops.
[Code]...
I'm just trying to make a simple function that will return all the data from my SQLITE database as an array. But it looks like when my function is returning the array, the SQL statement is actually still executing... so it's empty... Does anyone have a suggestion? Or am I just going about this whole thing wrong.I know I could just have the event listener functions outside this function, and they could then set the data. But i'm trying to make a AS3 Class that holds all my SQL functions, and It would be nice to have everything for this particular function just in one function, so it can return an array to me.
public function getFavsGamesArray():Array
{
getFavsArraySql.addEventListener(SQLEvent.RESULT, res);
[code].....
I want to make a simple SWITCH statement with Button._name as variables for CASE
so i got this code:
Code:
Button.addListener(_root);
_root.onRelease = function() {
[Code]....
I just have a button and a movie clip (MenuUp) and i want the button to be able to make the movie clip jump to different frames...
[Code]...
Having a few problems with what I thought was a simple if statement. Here is the code:
[Code]...
I can't quite figure out the small problem with the code. It seems to just bypass the first requirement of the if statement when I do type in the proper input and go straight to the else statement.
if (variable == 1){
//code
//Execute this code.
} else if (variable == 2) {
//code
[Code]...
I dont want to copy the code from the first into the second and the first and second into the third.
My mind isn't working and there is probably an extremelly simple way to get this working.
I know I could used functions but for some reason it stops the instance referencing working: _root["bullet"+j] doesnt work in a function.
The Flash movie contains 2 Text files, one Component button, and 1 component checkbox.The purpose of the application is to load an XML file(works)Populate 2 text fields with information from the XML file(works)Compare the two text fields, if they contain the same information then the checkbox, via AS is told to be selected. (Heres the problem);
Heres the code:
Code:
runCode_btn.onPress = function() {
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = function(success) {
[code]....
The idea behind this app is that its an electronic form. The user fills it out, the information is then sent to a newly created XML file, months later the open the XML file in flash, and Flash fills out text fields and check and or unchecks Checkboxes based on the XML data.CheckBoxes are mandatory.But I don't see how I'll be able to use them if i can't create and condition statements based on the loaded Data.
why this code won't work
[Code]...
I'm sure you can put if statements inside other if statements, seriously I can't figure it out
I need to write an if statement inside an if-else statement. But no matter how I write it it keeps giving me a syntax error.The syntax error is "1083: syntax error: else is unexpected".[code]No matter how or where I place the braces, it keeps giving me errors.
View 13 Replieswhat I'm trying to do is create an else if argument for each object in an array based on a user set number
Code:
for(var i:int=0; i < numberOfElseIfs; i++){
GENERATE AS3 CODE
}
to which I want it to GENERATE THE FOLLOWING CODE:
Code:
}else if(baskets[i].used == false){
baskets[i].used = true;
drawButton(i);
}
the problem is obviously that the compiler reads this code rather than understanding I'm trying to regenerate the code within the for loop...does that make sense :S? So basically I need as3 to read the code between the for statement as if it is going to echo that out later. Is this even possible?
I have a script which is giving me a lot of trouble since I have no idea how to write another "if statement" inside another if-else statement. I keep getting errors, I guess I don't know where to put the braces exactly...
example:
if(bla == bla) {
<------------how would I write another if statement here?
}else if (bla == bla){
}
I have a movieclip on the screen called "mc_bg". Within this movieclip are 7 movieclips called "barrier1" through "barrier7".From main.as I want to be able to do this call:
for (var i: int = 1; i < 3; i++ ){
trace("got here")
trace(mc_bg["mc_barrier" + String(i)])
[code]....
Is it possible to use a if statement with a eventlistener in it?
eg
if(myBut_btn.addeventlistener(MouseEvent.CLICK)){
[code]....
So I've been reading a lot today about the with statement performance, readability and stuff like that but i'm still not sure whether i should or should not use the with statement in AS3.
Using the with statement seems the same as creating local var which would carry the reference.
I am sending my header location to some variables in flash from my php page.For example when i am in the homepage then the header is:
&from=sitemap&product_id=1
What i want to do is tell the flash to go to one frame if it is the homepage and to another for any other value of products_id.What i have in my actionscript is this:
Code:
var prod_num = product_id;
if(prod_num == 1){
gotoAndStop("s1");
} else{
gotoAndStop("s2");
}
It is getting the product_id....but for some reason it always goes to frame name "s2".
ive got an array of cards 2-10 plus jack, queen, king, ace and i'm pulling members from the array at random--in order to score it, i decided to check the first character of the string and see if it returns a number or not.if it's a number, add the number to the score, but if it returns 'NaN' (not a number) then it will just add 10 to the score--so even tho NaN is defined as a variable in flash, somehow my if statement 'char==NaN' isn't working...
PHP Code:
[code]....
I'm using a for-statement to add a series of movieclips.
for (var i:Number = 0; i<10; i++) {
attachMovie("myMC", "myMC"+i, this.getNextHighestDepth());
}
Inside the movieclips I have some code. In this code I need the index-number of the movieclip. I'm staring the code off with: var indexr:Number = _root.i; The for-statement is so fast that all the movieclips get number 9 in the index-variable! Is there any trick to manage this, like can I get the index from the name in some way? Or do I have to work around it in some more or less complicated way?