ActionScript 3.0 :: Creating A Sprite And Run A Loop Create 100 Instances And Add Them To Stage
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
Similar Posts:
Jul 16, 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 1 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
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
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
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
Jan 16, 2011
I am working on a project in which I need to create a bunch of buttons.. all need to look the same with different text on the button.. rather then making each button separate in my library I would like to make one and create instances of the one button. I have created a button with a text field on top named txtLabel with a default text of "Label Here". I have dragged an instance of the button onto the stage and named it btnHome
btnHome.txtLabel.text = "Home"; d
Does not work..
I get the following error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MyProject_fla::MainTimeline/frame1()
View 9 Replies
Jul 31, 2009
what I'm doing wrong.i'm trying to create sprites in a for loop.
Code:
while( i < linkNumber )
{
[code].....
View 2 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
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
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
Feb 22, 2012
Is this correct? I am gettign this errorTypeError: Error #1007: Instantiation attempted on a non-constructor.I am trying to created a new instance of a movieclip on stage based on the number from elderCount.
//elderCount is a var:Number
var elderMan:Array = new Array(new starMovie());
var Star:starMovie = new elderMan[elderCount](stage);
[code].....
View 5 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
Nov 15, 2010
ActionScript Code:
var MapBtnArray:Array = [];
var MapBtnSprite:Sprite;
var i:int;
[Code].....
I'm using to code above to create several sprite on the stage, but when I click on the sprite, the index of each trace work just fine (output of J is according to the target i click); however MapBtnArray[j].x keep equals to "0"
I want the coordinate of the sprite on stage, how come what i get is "0" instead?
View 1 Replies
Jun 28, 2009
I'd like to create a chain of objects (either movie clips or sprites) that move left to right across the stage continuously. I know I can create two movie clips that contain a series of several 'chain links' and are each a little wider than the stage width. Then I can move both clips across the stage and when the first movie clip is completely off stage reset its x position back to 0. Likewise, when the second clip is completely off the stage on the right, reset it's position off the stage to the left.
This works and gives me the basic effect that I want by creating this uninterrupted moving chain, but it doesn't seem like its the most efficient way to achieve this. What I thought would be more efficient would be to create each link in the chain separately from an individual mc in my library by programmatically adding new instances to the stage.So, I created a single chain link mc and set its export linkage to 'Link' and left the base class to flash.display.MovieClip. Next, I placed the following snippet of the code on the first frame of my movie:
Code:
var xPos:int = 0;
var yPos:int = 100;
[code].....
View 1 Replies
Dec 2, 2009
I am reading in collection objects from an XML file. Each collection has an img field that stores a URL to the collection image. So I am trying to load the images of each collection, storing each image in a MovieClip, and add these MovieClips to the stage. However, my problem is that after adding a MovieClip (with the collection image) to the stage, when a new MovieClip is created in my 'for each' loop it overrites the previous MovieClip. So the images I am adding to the stage are being replaced by the following collection's image on each loop iteration. What can I do to avoid this?
Here is my code...
var collXML:XML = IXml(assets.collections).xml;
var collNodes:XMLList = collXML.children();
for each (var collInfo:XML in collNodes)
{
[Code].....
View 6 Replies
Dec 6, 2010
I have the code below but I need to generate it with a for loop. What is the proper way to do this? I don't initially know how many points i will have. I just want to create a for loop to loop through a variable that holds the point count such as "var totalPoints=10"
//1
var p1oint = new Point();
points.addChild(p1);
[code]......
View 1 Replies
Sep 10, 2010
So basically, this is how I'm adding one movie clip to the stage.
[Code]....
View 4 Replies
Feb 22, 2010
Can we able to create multiple text fields using actionscript 2, without creating any movieclip on the stage.
[Code]...
View 5 Replies
Jun 27, 2009
am loading an image onto stage dynamically. When I click on the loaded image, i am drawing a circle/rectangle[which is of Sprite type] at exact pixel-position on the image and making these circles/rectangles(Sprite_objects) visible there itself. In this way, I am adding as many number of Sprites_objects, till I continue clicking on the same image present on the stage.
The code in my application(which displays red colored rectangles when you click on the image) is as follows:
If you copy the code into ur actionsPanel directly,then make sure "image1.jpg" file * is present beside the .fla file.Since it gets loaded iff it is present in same directory.
*/ var myContainer:MovieClip = new MovieClip(); var temp_x:int,temp_y:int; //Loading an image dynamically and adding listeners... var urlReq:URLRequest=new URLRequest("image1.jpg"); var loader:Loader = new Loader(); loader.load(urlReq);[code]....
View 9 Replies
Jun 3, 2011
I am building a Custom Image Picker, that shows 6 alternative versions. However the photo is only showing on the 6th item.
_model.selectedPhoto returns a Sprite, and does not let the app function correctly.
However when I use _model.photos[ii], A photo is added to each item - Why is this? I need to add _model.selectedPhoto to each s:Sprite
for (var ii:int; ii < 6; ii++)
{
//Create BG
var s:Sprite = new Sprite();
[Code]....
View 2 Replies
Jul 10, 2009
I'm trying to write a class which can spawn many instances of a given sprite. Something like.....
package {
import flash.display.Sprite;
public class particlePlane extends Sprite{
public function particlePlane(particleType:Object, ammount:uint, planeWidth:uint, planeHeight:uint) {
trace("particlePlane: Populating with "+ammount+" "+particleType);
for (var count = 1;count <= ammount; count++) {
[Code]...
View 2 Replies
Jan 17, 2009
I am trying to add a dynamically drawn vector to a loop using a sprite,I 'm not to sure what i'm missing. ( using cs4)
View 2 Replies
Sep 19, 2009
Been struggling with the basics of creating instances at runtime. I needed to implement an XML video player and even though the client has supplied a component that they liked and it works fine, i cant turn it off as im not sure how the thing works. Basically the timeline hits a keyframe and stops. It runs the code to make the player popup but once the user has exited, the player stays on.If the function creates an instance for flv playback... how do i tell it to stop?
function below
function makePlayer ():void {
my_player = new FLVPlayback();[code].........
View 1 Replies
Feb 22, 2012
I'm having trouble creating instances of an object, I want a random number to be generated and then based on the number which was choosen create an instance of an object in one of four positions.The problem I'm having is, my instances are generated fine but there is one that keeps jumping to x 0 and y 0.[code]
View 21 Replies
Feb 1, 2010
I'm trying to build a picture viewer that can be used in every way. So it's important for me to make everything dynamic. I have a xml file that I load and then I read all the images and I want a border surrounding the image. I've made a new sprite to load everything in, I made a second sprite to load the images and that second sprite should be behind every image but it will only show behind the first image.
<code>
main_container = new Sprite();
main_container.x=containerX;
[code].....
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
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 5, 2010
I have several clips in the library:
MCA1
MCA2
MCA3
....
MCA100
Each with "export for actionscript" checked, and mathcing classnames.
I want to create an instance of each - and add to the current stage. I need to do this:
PHP Code:
var clipA1:MCA1 = new MCA1();
var clipA2:MCA2 = new MCA2();
var clipA3:MCA3 = new MCA3();
[Code].....
View 1 Replies