ActionScript 3.0 :: Loop For Multiple For Statements?
Oct 20, 2010
I need to put a load of MC's on stage with the use of an array as such:
Code:
for (var i = 1; i = 4; i++) {
if (reg[i] == "singlewall") {
var Wall:MovieClip = new wallClass() as MovieClip;
mainClip.addChild(Wall);
}
}
I need a lot more then 4 though and I need a way to make new "Wall" variables
Tried doing it with:
Code:
for (var i = 1; i = 4; i++) {
if (reg[i] == "singlewall") {
var Wall:MovieClip = new wallClass() as MovieClip;
Wall.name = "mc"+i;
mainClip.addChild(Wall);
}
}
This does not work though, yields an infinite loop somehow
I'm trying to do a binary search in a for loop. However, flash does not like the following for loop. for(var select:int = Math.floor((min + max / 2)), var turns:int = 0; turns < input.length / 2 + 1; turns++, select= Math.floor((min + max / 2))){ if(input[select] > want){ max = select; } else if (input[select] < want){ min = select; } else { return select; }}
On the first line I get 1084: Syntax error: expecting identifier before var. I think I know why (I'm using , to separate the different statements), but how do I fix it? ; won't work since it's what the for loop uses. ( var select:int = Math.floor((min + max / 2)) ; var turns:int = 0); turns < input.length / 2 + 1; //etc does not work either.
If the subject isn't entirely clear, it's because I'm not sure how to describe what I want to do. What I have currently is a large group of ComboBox components which trigger an event handler, which uses a Switch...Case statement to determine the selection, and then uses another Switch...Case to figure out which ComboBox actually called it so the function called can use the appropriate arguments. The way I have it written has bloated the code, so I'm wondering if there's a shorter way to do this.
So I am creating a drag and drop game but the thing is that there is not one question for each statement. Is it possible to have say... 10 statments on the right and one "box" on the left where the statements can be dragged to, if its correct it stays there, if its incorrect it goes back to its original position.
I'm building a quick products display app for my company (basically customers put in certain numeric values and the app recommends a product based on the numbers.) I've done this with if statments and addChild()s
Now if they've gotten one result and they want to try with different values I need to removeChild() the product images from the stage.
So far I have this working by adding the addChild()s to an Array and using a for loop to remove them everytime the calculate button is hit. This works fine until I get to product double ups (some products can work across multiple values) then it errors.
Below is part of the code I've shorthanded some of the parts which are working fine as well as the repeat parts so that it's not just a whole blob of code
I've been developing an AS3 based 2D fighting game engine (like Street Fighter II), and have run into an issue. I'm using if/else statements in my onEnterFrame function to hit test my fighters. This works great in my first if/else statement, but for some reason it doesn't recognize my second if/else statement that follows the first. I know it's not the code, because if I bring the second if/else statement up and place it above the first statement (simply swapping the order), the hit test is successful. Why is it that only the if/else statement that comes first works, but any that come after it don't?
Here's my code: function onEnterFrame(event:Event):void { //MOVE THE char1 PlayerBase.players[0].x += plyr1vx; PlayerBase.players[1].x += plyr2vx; [Code] .....
I've also attached a .zip file with my published files so you can see the issue in the game (must be viewed in a browser for keys to work correctly). Move the left player using "A" and "D" keys. Make him punch with "Z" and kick with "X". Punch is the first if statement in my code, and kick is the second if statement (not working).
I am working on a puzzle has four different eyes, nose, and mouth. These can be placed on a blank head. I want to be able to place all of the same parts of the face, and have a response that says "Beauty" if the mix up the pieces from different faces, it will say "Beast." I don't know how to set up the AS3 to make this work.
I am trying to check 3 scores at once. Is there a better way to code this... I want to check to see if they are all tied? If one score is greater than another? Seems like there should be a more cleaner way.
Below is code that has a timer countdown that reads off of the computer. Below in bold is code to read "if it reaches the date, go to and play frame (2).
[Code]...
Below is code that is manual input - I had set up a dynamic txt field in flash named it : raffle_tix_remain When loaded on to the host I can manulally update the xml code and the change will take effect. raffle_tix_remain.text = root.loaderInfo.parameters.raffle_tix_remain;
My question: Since the raffle_tix_remain is a manual input from a user to xml Is there a way to tell flash once it refreshes and "raffle_ tix_ remain" goes to (0)zero gotoAndPlay(2); and let it play like a "sold out" sign i guess that would be a if else statement.
I have a group of 16 images that I would like to load 1 of each into each movieclip. I want image1 to be inside of visual1, image 2 inside of visual2, and so on. the images are named like, 1960s_(1).png where the 1960 (year) part is coming from the rangeNum variable. The above gives me this error: 1061: Call to a possibly undefined method addChild through a reference with static type int.
How do i word a for loop to make it loop through multiple arrays?I want 1 for loop to loop through multiple arrays in order to move/alter objects.I want to keep the arrays separate.
ActionScript Code: characters = new Array(); characters[0] = male;
i have been building a library that has thumbnails which you click to view the full image. i have built the application it works but i want to change the way the image on the actual thumbnail loads using code instead of manually adding the value to the url loader component.
var myX;var instanceN:String;trace(instanceN);var currentLoad:uint = 0;// current loader and image loadingvar thumbnailURL:String;//Thumbnail URLvar thumbReq:URLRequest;// Thumbnail url requestfor(var k:uint = 0;k < iL_btn.length; k++)[code].....
the loop runs fine without the last line of code which i've commented out.the make up of these thumbnails are a uiLoader component which are each inside there own movieClip.what i wanted this to do was every time the loop runs it currentLoad adds 1 to its value then that value is subbed into instanceN:String and thumbnailURL address that bit works the trace statements read correctly.but my issue is using the instanceN value as the instance name path which then loads the current thumbnailURL value which is the URL address for the thumbnail picture.when i try to load the url address using the commented out code above i got the error .TypeError: Error #1010: A term is undefined and has no properties.the trace statements correct values below
the first value is the currentLoad value.
the second value is the instance name path.
the third is is the URL address for the thumbnail.[code].....
say i want something to happen, but I only want it to happen if more than two conditions are satisfied...is there a way to use multiple "if" statements?
If they get a question wrong in my quiz ( weakest link) the money clip goes to zero and it goes onto the next question. If they get it right the money clip advances and they go onto the next question. I want to include each time that it should only go onto the next question if all questions have been asked. SO i want an extra if clause in both sections, saying if current question is more than 11 go to '#game over"The questions are saved in the frame of the quiz
_root.qArray = new Array("question: A;B;C;D") _root.qArray.push("Question?:A;B; C; D")
There are 11 questions.At the moment at the section with choosing answers I have
function selectAnswer(n) { // correct if (answers[n] == correctAnswer) { _root.money.nextFrame();
I really hope someone can help me with this one! I've been trying to loop several embedded flv files in one flash document. I've found some really useful script that works when applied to one flv file in the document, however I don't really know how to adjust the actionscript so that it applies to the other three flv files on the page.[code]
I have many MCs on the stage ,I just dont want to paste the same code to all MCs one by one..so I want to ust the following loop but not sure where to paste the following code.
1. Created a flash banner ad on the first scene. Take note they're all under frame one because I used movie clips for the animations (Movie clip ends on the 100th frame and not sure if I need to add a stop(); code there or place the gotoAndStop command). Anyways, moving on.
2. I created a new banner onto another scene which by now I have 2 scenes. Just like scene 1, all the animations and such are all under frame 1.
3. Placed an action script on the first scene to play the next scene. gotoAndStop("scene 2", 1);
4. For the second I placed the action script: gotoAndStop("scene 1", 1);
Output:It looks like my banner ad is flipping one scene from another without stopping. I know my action script is not correct. I know you folks are far more experience in flash, so I implore your wisdom.
I have this for loop that is basically pulling some info from an xml file and putting it in a list box. And for each item in the xml, it also adds 2 radio buttons.Everything is working properly except all the radio buttons have the same y location, and i want them to be spaced apart, not on top of each other.I have tried messing around with the y location (rb1.y+105, etc) but I'm not having any luck.
for (var i:uint=0; i<il.length(); i++) { lb.addItem({data:il.description.text()[i], label:il.title.text()[i]});
I have several SWF files which are essentially little trivia files, provided to me by a 3rd party. They are individual files that number about 20. I am wondering, how can I play this as a list; like a playlist, and then loop back to restart? I'd like to do this in the stand alone player however it can only seem to load 1 file at a time. How I might look to accomplish this looping playlist?
I'm very new to Adobe Flash CS5.5. Can you create a common instance EG: "Enemy" and then control it like so: Enemy.x += 1; So that all instances of Enemy will move forward one pixel each frame? Instead of just one enemy? If this is not possible could I set up some sort of array of enemies like you can in C and try something like: int EnemyNo = 1; for(EnemyNo = 1; EnemyNo < 5; EnemyNo++) { Enemy[EnemyNo].x += 1; } Does Flash even support "for" loops?
I simply want to be able to access 3 already created, but not yet added movieclips using a loop. I've tried a few code combination but can't figure out the syntax.[code]
there is something i just dont get regarding motion with multiple movieclips (from a for loop). I have tried many different approaches, and every time there is either all the clips move in the same direction, other times they only move one direction, other times when i get individual motion for each object they dont move smooth, and seems more too move very slowly across the scene but rapidly back and forth in a small area. I dont have any specific code to show, but does anyone have tips or a place to direct me, cause i dont understand the logic of it, however i want to understand.