ActionScript 3.0 :: Adding Sprites In For Loop?

Dec 20, 2011

How can I add sprites in a for loop?
Example:
var my_shape:Sprite = new Sprite();
for (var i:Number =0; i<total;i++){
addchild(this["my_shape"]+i);
}
So after that I can access that shape like:
my_shape2.visible = false;

View 14 Replies


Similar Posts:


ActionScript 3.0 :: Adding Sprites And Scrolling Them?

Jun 2, 2011

I just started learning AS3 I was just trying out something.To read values from xml and make a drop down menu. I reached only this far

Actionscript Code:
import flash.display.Sprite;import flash.text.TextField;import flash.events.MouseEvent;var i:Number = 0;var sp:Sprite = new Sprite();var sptxt:TextField = new

[code].....

View 7 Replies

Flex :: Adding Sprites To Canvas?

Apr 30, 2011

First off I have this MXML:

<mx:Panel x="270" y="10" width="690" height="680" id="mainContainerPanel">
<mx:Canvas x="270" y="10" width="670" height="640" id="canvas" initialize="onInit()">

[Code]....

The circCentre Sprite never appears on screen and I don't understand how I can get it to appear.

View 1 Replies

ActionScript 3.0 :: Adding Dynamicaly Sprites And Textfields?

May 8, 2011

Basicly I'm adding dynamicaly sprites and textfields, which i populate from xml, in for loop. I'm building sort of table, so for every sprite, I'm adding new data in textfields.I've loaded xml and passed data to 2 xmllists, both traced and doing fine... Later on I add data from xmllist to array which then I'm looping in for loop.Problem is that from 1st xmllist, 6 out of 7 textfields are visible, 1 can't be found nowhere :/ from the 2nd xmllist only 1 out of 4 are visible...I've tried everything, tracing them returns that they are visible, on good position, filled with text, contrasted color from background.

PS: here is the part probably causing the problems..
for(mojbroj=0;mojbroj < dohvatiosamih2;mojbroj++){if(mojbroj%2){lista.graphics.beginFill(0xdddddd);lista.graphics.drawRect(150,prenesi+(

[code].....

View 1 Replies

Actionscript 3 :: Adding Sprites To A Container From Flash?

Jan 7, 2011

i am currently working in flashbuilder and i imported a swc wich containes a ratingcontainer. That ratingcontainer contains 5 ratings, they are labeled "Rating1", "Rating2, "Rating3", "Rating4", "Rating5".These are placed on the stage. i also have a sprite called "Star" and when i for example click on "Rating4" then every Rating from 1 to 4 should get stah Star sprite added to them, when i click again on Rating 3 or something then only 3 the first 3 should have the star added. i tried the following:

detailContent.RatingContainer.addEventListener(MouseEvent.CLICK, ratingClickHandler);
private function ratingClickHandler(e:MouseEvent):void{

[Code]....

View 2 Replies

ActionScript 3.0 :: Add A Sprite Or Object Capable Of Adding Sprites To Scene3D?

Jul 11, 2011

Ages since I last played with away3d, totally forgot how to use it.What do I do if i want to add a Sprite or object capable of adding Sprites to my Scene3D?

Edit: Using the MovieMaterial in not a possibility due to YouTube disabling Draw() on their APi

View 3 Replies

Used A "for Loop" To Create A Number Of Sprites?

Jan 31, 2010

I have used a "for loop" to create a number of Sprites.This same loop names the Sprites and places them in an array. That array is used to add and locate the Sprites on the stage. The problem I am having is when I attempt to use the Array index in a "hitTestObject" statement ie; [URL]...with the accompanying code being trace("hit"). I get "hit" displayed on the output panel,whenever "myObject" collides with any Sprite from that array. How can I make these hits spicific to the particular object from the array.

View 1 Replies

Professional :: Adding A Loop To The Following Codes?

Oct 18, 2011

i will like to add a loop to this codes below
 
var myTimer: Timer = new Timer(1000);
myTimer.start(); 
myTimer.addEventListener(TimerEvent.TIMER, nextPic)

[code]...

View 7 Replies

ActionScript 3.0 :: Adding A Hover Event To Each MC In A Loop?

Jun 4, 2009

My goal with this actionscript is to create a new movieclip for each top-level XML node and include in the movieclip two separate textfields, an image, extend the movieclips to two row if necessary, rotate each movieclip differently depending its parity and add a hover event based on the movieclips instance name. I have achieved each goal except for the hover bit. The reason I cant access the instance name outside of the for loop is because the instance name only lasts for duration of the loop. Here is my current code (at pastie address).I have extensively searched the interweb to try and find a solution, but nothing has worked.

View 5 Replies

Dynamically Adding Movieclips To Stage In 'for Each' Loop

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?

[Code]....

View 1 Replies

ActionScript 3.0 :: Dynamically Adding Function Through For Loop?

Jul 25, 2011

i have an array of coins that are layed out on a map for a character to come pick up.i have the coins displaying on screen but i cant get a simple hit test to work. it only seems to work on the last coin created, i presume because the 'i' value hasnt been appended to the name. i knew how to do this in as2 but dont know the syntax for as3. ive attached the file for you to have a look at.

code:
ActionScript Code:
character.startDrag();

[code].....

View 5 Replies

Actionscript 3.0 :: Adding A Hover Event To Each MC In A Loop

Jun 4, 2009

My goal with this actionscript is to create a new movieclip for each top-level XML node and include in the movieclip two separate textfields, an image, extend the movieclips to two row if necessary, rotate each movieclip differently depending its parity and add a hover event based on the movieclip's instance name. I have achieved each goal except for the hover bit. The reason I can't access the instance name outside of the *for* loop is because the instance name only lasts for duration of the loop.[code]I have extensively searched the interweb to try and find a solution, but nothing has worked. I'm definitely not being lazy, I have just run out of options.

View 2 Replies

ActionScript 2.0 :: Adding Multiple Movieclips Within A For Loop?

Mar 7, 2012

Basically I have 5 movieclips I want positioned around the stage. So I figure the best way to this is with a for loop. However the way I've coded it doesn't appear to add new movieclips and seems to just move the first movieclip 5 times and it always ends up with an x of 169. Here's my code:

Code:
for (i=0; i<5; i++){
var barName:MovieClip =
_root.game.attachMovie("butSquare","r1wBar"+i,_root.getNextHighestDepth());

[Code]....

View 1 Replies

ActionScript 3.0 :: Adding Set Of Grid Lines To Movieclip Using For Loop

Jun 7, 2009

I am dynamically adding a set of grid lines to a movieclip using a for loop. And I was wondering how I go about removing all of them so that I can add another set of grid lines to the same movieclip.This may sound weird but what I am doing is dynamically creating a table from an array and I wanted to dynamically add gridlines in between the table entries depending on how many entries there are in the array. I got this to work fine but when you go from one table with more entries to a table with less then the grid lines from the longer table are still there.Hence I want to be able to remove all the grid line instances before creating the next table.

View 6 Replies

ActionScript 3.0 :: For Loop - Adding MovieClip And Button Class

Aug 30, 2011

Actionscript Code:
public function Main():void {
var my1:MovieClip = new Sp();
var my2:MovieClip = new Jp();
var my3:SimpleButton = new But();
var rel;
for (var i:Number = 0; i < 3; i++) {
rel = "my" + (i + 1);
trace(rel);
addChild(rel);
}

See the above script, Here I don't wanna add the MovieClip and button class separately using "addChild" like,

Actionscript Code:
addChild(my1);addChild(my2);addChild(my3);

So I used for loop function. But it is showing error:
TypeError: Error #1034: Type Coercion failed: cannot convert "my1" to flash.display.DisplayObject.
at com.priyan::Main()
at mainFile_fla::MainTimeline/frame1()

View 2 Replies

Incrementing Several Movieclip Positions When Adding To Stage Using For Loop?

Jun 23, 2009

I'm adding several similar movieclips to the stage with a 'for' loop. However, I'd like to increment the position of each movieclip when added on to the stage. I know exactly where I want each movie clip positioned as well. At the moment I just have a small 'for' loop which setups the movieclip. Like so...

[Code]...

View 1 Replies

ActionScript 3.0 :: Adding Scrollbar To Sprite Inside / Outside For Loop?

Nov 26, 2009

I'm currently having trouble on integrating a scrollbar that I downloaded from Warm Forest Flash. I built a XML gallery that is going out of the boundary of height of 466 pixels. The thumbnails that are out of the boundary are still visible. On top of that, I tried to add the scrollbar to the sprites inside and outside the for loop, but sadly it doesn't appear. For the height thing, can I set the size of the ULLoader? Or should I just use a mask or something?

Main.as
import flash.net.URLLoader;
import flash.net.URLRequest;
import fl.containers.UILoader;
import gs.*;
import gs.easing.*;
[Code] .....

View 1 Replies

ActionScript 3.0 :: Adding Images From My Library To Empty Mc In Loop

Apr 3, 2011

I am 1 step away from finishing my for loop. I have a item mc I have duplicated 8 items (indexarray.length) and what my loop currently does is display these 8 blank movieclips on the screen positioned 4 in each row. Inside this blank item mc I have a dynamic text field name_text within this item that call on names from a previously declared array. I also have a empty movieclip called image_holder with property name imageHolder. So far the below displays my 8 items with names but without the image:
 
function displayItems()
{
var xPos = 0;
var yPos = 0;

[Code]...
 
All my images are in my library in movieclips name item0 to item 7 to fit in accordingly. What do I need to add to the above code to get these images inside my image_holder mc?

View 5 Replies

Actionscript 3.0 :: Adding Objects To Stage Through An Array And For Loop?

Jul 7, 2010

I am trying to create a card game (deck of 24 cards/6 cards will be dealt to the stage at one time (3 arrays)).

I want 6 cards to be dealt to the stage when you click the "Deal" button. I think i have the loop set up properly, the first array traces, however i can't get the cards to be added to the stage. What am i doing wrong? Once i get the first set of cards to be built to the stage, i will want to remove the previous set and the second set will be dealt to the stage once the "Deal" button is clicked again.

//code
var aArray = new Array();
aArray[0]=Card1;
aArray[1]=Card2;

[Code]....

View 9 Replies

ActionScript 3.0 :: Adding Timer To MovieClip Loop In Triangle

Jan 25, 2010

I set up a loop where a movie clip moves in a triangle over and over. It works, but I want it to pause for 5 seconds at each location, so I added a Timer (my first attempt). Now, it will go through the triangle once, pausing correctly, but then the main movie clip (target_mc) stops in the original position and never moves again.

Code:
import fl.transitions.*;
import fl.transitions.easing.*;
var xMove0:Tween;
var yMove0:Tween;
var xMove1:Tween;
[Code] .....

View 5 Replies

ActionScript 3.0 :: Dynamically Creating And Adding Movieclips To Stage In 'for Each' Loop

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

ActionScript 3.0 :: Adding Data To Array From Text Input Through Loop?

Jun 9, 2010

I am trying to add data to an array from the textinput which I have created through for loop, but not working.
import fl.controls.TextInput;
import fl.controls.Button;
var myBt:Button = new Button();
addChild(myBt);myBt.label="Submit";
myBt.x=50;myBt.y=200;
[Code] .....

View 4 Replies

ActionScript 3.0 :: Incrementing Several Movieclip Positions When Adding To Stage Using For Loop?

Jun 23, 2009

I'm adding several similar movieclips to the stage with a 'for' loop. However, I'd like to increment the position of each movieclip when added on to the stage. I know exactly where I want each movie clip positioned as well. At the moment I just have a small 'for' loop which setups the movieclip. Like so...

ActionScript Code:
for (var i:uint = 0; i<=8; i++)
{
zone[i] = new Zone();
}

I then have a long list adding and setting each mc position on the stage...

ActionScript Code:
stage.addChild(zone[0]);
zone[0].x=267.6;

[code]....

Although I've just had a thought as I was typing that last bit of code. Will I need to setup a for loop for each row...so the y position remains constant and I just increment the x value for each movie clip, and then repeat this for loop for the next row with the new y coordinate?

View 1 Replies

ActionScript 3.0 :: Adding Previous Numeric Values In Array During For Loop?

May 23, 2009

While a for loop runs through all the elements in an array I want to get the width of each element and add it to the sum of the width of all previous elements.

View 2 Replies

ActionScript 2.0 :: Adding Properties And Events To MovieClips Inside A Loop Inside A Function

Dec 8, 2009

I have done this same thing in ActionScript 3, but am not familiar with ActionScript 2, which I am forced to use for this project. I am loading products into a SWF via XML and attempting to add a click event to each dynamically-created movieclip. Simply tracing the text from a node in XML will do for now. I'd like to assign a property called "desc" or "description" to each movieclip and have it trace that property's value when clicked. Here is the relevant portion of my code as it stands:

ActionScript Code:
var iXML:XML = new XML();
iXML.ignoreWhite = true;

[Code].....

View 6 Replies

Importing The Images/Sprites?

Apr 10, 2011

If I am to import an image and I wish to use it as a sprite or something like that; How do I remove the white areas? For example, if I was going to create a custom cursor or something like that, an I was to use this image: Image - how would I remove the white areas, so that they are transparent. I would also like to know if it is possible to set where the center of rotation in an image is?I do all my image work on Photoshop, if that is of any significance.

View 1 Replies

ActionScript 3.0 :: Add Same Images To 2 Sprites?

Oct 29, 2010

How do i add the same images to 2 sprites?The below code doesnt give an error but only adds the image to 1 sprite[code]...

View 2 Replies

Actionscript 3 :: Joining Sprites Together?

Nov 13, 2010

So created a Sprite to which I add other Sprites which are game tiles. Each tile is 60 x 60 px big. In result I've the Sprite with about 200 childs (those tiles).When I try to startDrag() the container sprite the lag when moving it is very noticeable..

Is there a way like to join the tile Sprites so the container would have only 1 child Sprite instead of 200? Because it lags so much probably cause it needs to move (change the x and y) all those 200 tiles.. Am I correct?In this case I can't use the cacheAsBitmap property, cause user can zoom in or zoom out the map..

View 3 Replies

ActionScript 3.0 :: Draw Sprites With XML?

Aug 12, 2010

I'm currently building a slideshow application using the MVC pattern, as it stands the application works by going to the next picture by clicking the photo or controlling the slides with a next/prev button.

i am trying to add additional navigation so that there are thumbnails of the images loaded with XML so the user can click the image and go straight to the image clicked on.

thats easy enough i could add buttons manually with thumbnails in them but it would tedious to update the photography or artwork when it comes to increasing or reducing the number of photos.

so what i plan is that ,when the application loads it reads and counts the images Thumnails in the XML file,then the AS3 generates thumbnail icons according to the amount of images counted in the XML File, then places them on the stage in a sequence next to each on the stage. as a sequence of thumnails with can then be used to navigate around the library with more control and is easy to update simply by changing the XML file.[code]...

View 0 Replies

IDE :: Possible To Insert Sprites Directly?

Feb 12, 2009

How can insert sprites from the IDE? When I press f8 the only options are MovieClip, Buttons and Shapes. If I export to ActionScript I can change the class to Sprite, but I want to insert a Sprite directly from the IDE.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved