ActionScript 3.0 :: Working With Multiple Instances - For Loop?
Dec 17, 2011
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?
View 21 Replies
Similar Posts:
Aug 2, 2010
In the library of the FLa I have a symbol that is exported for actionscript with a class name of 'aClip'.I am placing multiple instances of it on stage as follows:
Code:
for (var i:int = 0; i < 10; i++) {
var myClip:aClip = new aClip();
myClip.x = 0;
myClip.y = 50 + (50 * i);
}
Each myClip will move across the stage at 1 unit per frame. If I only had 1 instance on the stage I would implement as follows:
Code:
//make an enterFrame listener for the stage
this.addEventListener(Event.ENTER_FRAME, moveClip);
//make a function for the listener[code]...
The problem I am having, is getting this to work for the multiple instances generated in the for loop.
View 2 Replies
Jul 9, 2009
I have several movieclips in my project which are being used as buttons, and when you rollover the mc's the content is viewable the entire time the mouse is hovering in the area of the movie clip, once the mouse moves off it disapeers. Great. I have the code that allows this to happen, but i have multiple mc's and only one works at a time. Here is the code:
mc.addEventListener(MouseEvent.ROLL_OVER, overHandler);
function overHandler(evt:MouseEvent):void {
mc.gotoAndStop(2);
[code].....
View 2 Replies
Jan 17, 2011
I am working on a project which looks like a crossword puzzle. When you mouse over on the white boxes they will light up. When you mouse over the letters they will have 3d rotations and when you rollover only some specific letters, they will flip some specific boxes.
Right now what happens is, when you mouse over the boxes with letters on them, the letters will rotate but the box will not light up. This is because I have created the box movieclip, with the invisible button inside it, and then just duplicated it in my scene to create a tile. But the invisible button for the letters are on the scene,so it's kinda overriding it.when I tried having the buttons on the scene rather than inside the movie clip, what happened is when you roll over one of the boxes, all of them will animate.
View 1 Replies
Dec 17, 2006
I thought this would be simple but for some reason I'm having all kinds of problems. Why won't the for loop create a new c instance each time the loop increments, like it does for sHolder and s? ...And, assuming it is possible to make it do this, how can each instance be given an identifier that can be accessed dynamically, like sHolder and s in the traceSomething function?
Code:
package {
import flash.display.Sprite;
import flash.geom.ColorTransform;
[Code]....
View 12 Replies
Jul 10, 2009
I have Multiple movieclips that when you hover over, a info box pops up and stays active until the mouse is moved away from the info box. Simple enough. I have multiple movieclips and i cannot get more than one to work. In order for the movieclip to work the instance name is 'mc' and this is the code i am using:
[Code]....
View 2 Replies
Sep 8, 2009
Ok so here is my XML slideshow Actionscript:
ActionScript Code:
stop();
var xmlRequest:URLRequest= new URLRequest("graphicImages.xml");
var xmlLoader:URLLoader = new URLLoader(xmlRequest);
[Code]....
So I figured that the coding of separate scenes would work independently of one another, but I guess I was dead wrong, because when I apply this to a different scene and change the XML path for a different set of images, I get all sorts of conflict errors when I test the entire movie. I have my flash film set up so that each link send the user to a different scene, which plays a unique intro for each, and then the slideshow appears on screen and the viewer can navigate the images.
Is there a work around for this? Or am I going to have to break my flash movie into separate movies? Or should I just add a suffix to all my vars and functions so that they are unique for each scene?
View 1 Replies
Jan 20, 2010
[code]My code will:
- loop through the Grid array and place each tile on the stage
- assign RedBall a random Grid coordinate and places it on the stage at that coordinate
I want to be able to click RedBall, which will create a border around the tile beneath RedBall, and create borders around the tiles above, below, to the left and to the right. BUT, I don't want to reference the tiles by their distance in pixels from RedBall or from each other; I want to reference the tiles by their coordinates in the Grid array. So I want to:
- get the coordinates of RedBall
- use those same coodinates to reference the tile at the same coordinates in the Grid array
- use the tile's coordinates to reference the tiles above/below/left/right
- apply a border to all these tiles
What's the best way to reference an instance of a tile? Should I apply a name to each instance as it's created in the loop? like myTile.name = "tile"+i+"_"+j; ? If so, how do you reference that instance later? Just tile1_3 ? Do you have to prepend it with root, or stage, or the class it was originally created in? Do you have to use getChildByName? OR, can you still reference it later without having given it a name?
View 1 Replies
Jun 22, 2010
There's 3 boxes I'm indexing through with a timer. They disappear in sequence. How do I make them reappear?
boxes disappear in sequence 1-3
var pink:Array = ["","boxInstance1","boxInstance2","boxInstance3"];
var timer:Timer = new Timer(555);
timer.addEventListener(TimerEvent.TIMER, onTimer);
[Code]....
I'm not to particular about the sequence they disappear and appear, but it need to keep going in a loop.
View 3 Replies
Aug 5, 2010
I'm trying to create a vertical column of images in a mc that can be clicked. I've added listeners to reposition them once they load, but right now they are overwriting each other. I'm not sure how to rename the object and listener vars for each iteration. [code]...
View 1 Replies
Aug 27, 2006
I'm trying to parse an XML file, and use it to create instances of a custom class the fly in actionscript 2. (can't migrate to 3 for this project).I'm trying to make something happen like:
Code:
for (var i:Number=0; var<n; var++) {
instanceName="MyObject"+i;[code].....
Which doesn't work.When it's all done, I need to have n objects named MyObject1, MyObject2, ..., MyObject(n).
View 2 Replies
Dec 5, 2009
I have created 4 movieclips and named (instance) them box1, box2, box3, box4 and shuffled them with the following code:
var vector_name:Array = new Array("box1", "box2", "box3", "box4");
function shuffle(a,b):Number {
var num : Number = Math.round(Math.random()*2)-1;
return num;
} var shuffled_vector:Array = vector_name.sort(shuffle);
trace(shuffled_vector);
How can I tween the instances using fl.transitions.Tween with a loop. I tried the following but did not work..
btnPlay.addEventListener(MouseEvent.CLICK, startMotion);
function startMotion(me:MouseEvent):void {
btnPlay.visible = false;
for(var j:int = 0; j < 4; j++) {
var twSlide:Tween;
[Code] ......
View 2 Replies
Oct 21, 2010
Here's a piece of script I would like to condense into a single loop where the number of instances created would be dynamic:
Actionscript Code:
//create instances of Door objectvar door_1:Door = new Door();var door_2:Door = new Door();var door_3:Door = new Door();var door_4:Door = new Door();var door_5:Door = new
[code]....
View 5 Replies
Dec 1, 2010
I have a bunch of movie clips on a layer named s1, s2, s3, .. s16.
I need to add them to an array so that I can select a random number to play.
Something like:
var sparkle:Array = new Array();
var i:int = new int;
for(i=0;i=16;i++)
{
sparkle[i] = 's'+i;
}
View 2 Replies
Feb 5, 2010
i am creating a certain amount of instances of a class-object (called Jaar).When i click on one of them, I would like to change a value (isSelected) in all the instances of this class.How can i do this?So far i have this (simplified version) :
ActionScript Code:
package{
import flash.display.*;
[code].....
View 6 Replies
Oct 30, 2010
basically i want to create ten balls on the stage. I have a balls.as file which uses the drawing api to create a circle within it. also within the balls.as file there is a public variable.[code]how would i go about finding out: if you click one of the balls it traces that balls life.
View 9 Replies
Mar 5, 2011
Ok what i want to do is to put MORE than one instance of a MC on stageFor that i try to create a name to the MC inside a (FOR) loop (working)what dident work is to put multiple instance of it on stage.Seem preety basic but i can figure it out
function generateHex(e:MouseEvent)
{
tileSet.x = tileSize;
[code]......
View 2 Replies
Jan 20, 2010
My code will:
- loop through the Grid array and place each tile on the stage
- assign RedBall a random Grid coordinate and places it on the stage at that coordinate
I want to be able to click RedBall, which will create a border around the tile beneath RedBall, and create borders around the tiles above, below, to the left and to the right. BUT, I don't want to reference the tiles by their distance in pixels from RedBall or from each other; I want to reference the tiles by their coordinates in the Grid array.So I want to:
- get the coordinates of RedBall
- use those same coodinates to reference the tile at the same coordinates in the Grid array
- use the tile's coordinates to reference the tiles above/below/left/right
- apply a border to all these tiles
What's the best way to reference an instance of a tile? Should I apply a name to each instance as it's created in the loop? like myTile.name = "tile"+i+"_"+j; ? If so, how do you reference that instance later? Just tile1_3 ? Do you have to prepend it with root, or stage, or the class it was originally created in? Do you have to use getChildByName? OR, can you still reference it later without having given it a name?
View 3 Replies
Apr 28, 2009
I am trying to create TextField Instances for a crossword puzzle in Flash through a loop and then address them later how do I do this. My Code:[code]
View 12 Replies
Dec 25, 2009
I'v been toying with this for a few weeks now and I'm trying to find the best way to animate several instances of an object created by a for loop thru an ENTER_FRAME function.When the function runs only 1 of the 3 instances that were created animates.
var balloonArray:Array = new Array();var balloon: hotAirBalloon;var xVel: Number = -3;var yVel: Number = -4;
addEventListener(Event.ENTER_FRAME, startBalloons)
[code]....
View 9 Replies
Mar 16, 2009
Exactly this doesn't work but is there a way to do it?
Code:
for ( var i = 0; i < 10; i++ )
{
var ["object"+i]:MyClass = new MyClass();
// would create object1, object2, object 3, object 4, ...
}
View 3 Replies
May 28, 2010
So I know that if I want to create an instance of a movie clip called part01Roads from the library I do this:
Code:
var part01Roads_mc:part01Roads = new part01Roads();
addChild(part01Roads_mc);
part01Roads_mc.x = -22379;
part01Roads_mc.y = 317;
Well I want to take this one step further if it is at all possible. Lets say I have 100 different movie clips labeled in a sequence: part01Roads, part02Roads, part03Roads ..... part100Roads. Instead of rewriting the above code 100 times, can I make a loop to do this?
View 13 Replies
Feb 5, 2012
[Code].....
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.
View 4 Replies
Feb 25, 2009
I have a row of buttons within a container, all with instance names. When one of the buttons is clicked and using a switch statement, I want to navigate to a timeline frame and stop to display the desired page. Could someone provide an example of AS code?
The ActionScript 3.0 Language and Components reference is great but there still is a lot missing in the process of coding in AS.
View 23 Replies
Aug 25, 2010
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;
[code]........
View 3 Replies
Sep 2, 2010
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].....
View 3 Replies
Feb 15, 2009
I put in the stage 3 instances of uiloader and name pic1, pic2, pic3. How can i load a bitmap in these 3 instances of uiloader with a loop structure;
View 5 Replies
Jul 17, 2009
I thought would be coded like this:
var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xFF88CC);
sp.graphics.drawCircle(0, 0, 50);
[Code]....
however, I realize even tho im looping that addChild method, its still adding sp, so do I add a new naming convention in the loop, or should I be adding these instances to another display object.... this seems like such a simple thing to do yet I cant figure it out, I also want to randomize the x and y, but this first seems to be the issue I need to address.
View 6 Replies
Aug 17, 2009
can I use the same loader or do I have to have a loader for each instance (the one thing I haven't tried as yet)
View 3 Replies
Mar 21, 2010
i have a movieclip that is instanced on stage everytime i press space. problem being i can't seem to get it to hittest anything other than the first created instance.my spawn mc code is
Code:
function dropbox():Void {
//trace(me);
this.attachMovie("box","box"+Math.random()*300,this.getNextHighestDepth(),{_x: _root.one.me._x-25, _y: _root.one.me._y});
[code]....
the first one returns "It's working" but zip for all of the others.
View 0 Replies