ActionScript 3.0 :: AddChild Using For Loop Then Put Into Array
Jan 20, 2010
Is there a simple equivalent to what I used to do in AS2 to add a bunch of new objects to the stage and throw them into an array so they can easily be referenced? I'm finding this more difficult than it used to be.
[Code]...
View 3 Replies
Similar Posts:
Feb 8, 2012
Is there a simple equivalent to what I used to do in AS2 to add a bunch of new objects to the stage and throw them into an array so they can easily be referenced? I'm finding this more difficult than it used to be.
Old code:
ActionScript Code:
mc_array = new Array();
for(i=0;i<5;i++){
[code]....
View 6 Replies
Mar 29, 2011
I had a previous old script working with AS2 and have tried to convert it as the new system requires AS3 .the below script :
function displayItems() {
var xPos = 0;
var yPos = 0;[code].....
This gives me the following for the bolded line
Scene 1, Layer 'as', Frame 1, Line 44 1067: Implicit coercion of a value of type String to an unrelated type flash.display:DisplayObject.
This line used to be addmovieclip which worked. I'm not sure how to edit this to suit the new addchild method.
View 12 Replies
Aug 14, 2009
I've a loop that adds a child (loader that loads image) to the stage.
This is working fine but when I go to the other page the images just stays on the screen.[code]...
View 4 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
Mar 10, 2008
I want to load multiple different movieclips from my library(mc1, mc2, mc3 etc.)with a loop and I can't seem to succeed with this..
each movieclip is unique and it would be a nightmare to code them.
View 7 Replies
Jul 18, 2009
I am just trying to grasp a simple concept of utilizing loops, addChild, and eventListeners.My goal is to use a loop to create multiple instances of the same type of object from my library (called Ball), and when one is clicked, have it move "above" all other instances on the stage (and eventually drag, but that's easy enough to make happen later).My current code attempt is:
for(var i:uint = 0; i<=10;i++)
{
var my_ball:Ball = new Ball() //new instances of Ball from library export
[code].....
View 2 Replies
Jan 7, 2011
I cant get addChild to work withing a loop (while).
I have a range of movie clips in the frame hidden away. These are called item_1, item_2, item_3 etc.
It works FINE when Im adding say item_1, then item_2, but if the code tries to add "item_1" twice, it seems to just overwrite the first new "item_1"!?!
This is what I need to do, and it just wont work!
ActionScript Code:
while(i<10){
this["item_new_"+i] =new MovieClip();
this["item_1"].y = 0;//I put this in just to make sure they line up right
[Code].....
View 8 Replies
Oct 15, 2009
I have an array with names referencing movieclips, how do I add them so that I can control them in a function? I want to control each one seperately.
If I wish to control the .x value of say myArray[1][6][12] do I have to call them individualy as in:
myArray[1].x+=128
myArray[6].x+=194
myArray[12].x+=236
Or can I control say the X coordinates of a bunch of movieclips in one line of code?
Here is my code:
ActionScript Code:
var myArray:Array = new Array();
var star:mcStar;
//var xpo:Number = new Number (Math.ceil(Math.random()* 400));//ignore
[Code]....
View 4 Replies
Feb 18, 2012
so i have an array containing many instances. let's say movieclips.
and i have another array which contains numbers..in this case those numbers represent selected indices that i've somehow chosen!
var manydots:Array = new Array ();
for (var i=0; i<10; i++)
{
var newDot:dot = new dot ;
manydots.push(newDot);
}
var indices:Array = [0,1,5,8,4]
i want to use AddChild to add those movieclips into my scene, but not all of them, only selected indices contained in my 2nd array
View 2 Replies
Dec 22, 2009
I'm just trying to add the mc's from the array into a column but don't know how to gain any control over them since right now, they're just all overlayed on top of eachother .
Code:
var myArray:Array=["mc1","mc2","mc3","mc4","mc5"];
for (var i = 0; i < myArray.length; i++) {
var classRef:Class=getDefinitionByName(myArray[i]) as Class;
addChild(new classRef());
}
View 1 Replies
Mar 31, 2011
I have a MovieClip called item with the same linkage set and my first task is to display 10 of these items on the stage nested inside a movieclip called MainItem. I have dragged MainItem to the stage and have the following for loop:
[Code]....
View 5 Replies
Mar 26, 2009
I'm familiar with AS2 and just getting started with AS3. I found a submenu fla I would like to use, and I have everything set up, just not sure how to attach movies from the library when someone clicks a navigation button.In AS2 I would have made an empty mc and used attachMovie when the button is released.I've looked at some of the addChild questions and tutorials here, but since I'm working with pre-written code for a submenu, I'm not sure about how to modify what I've read to work in that code.Here's the code that sets up the submenu, the last function (navigate) is where I'm not sure how to instruct flash to load an mc when one of the buttons (from the var subButton:Array) is clicked. The MCs in the library correspond to the array entries ie: s.home has a library item mcHome, s.web has library item mcWeb that would load when they click that button. var s = this.services.subBar //create a variable to shorten the path to the buttons in the sub barvar subButtons:Array = new Array(s.home, s.it, s.web, s.graphic, s.contact); // create an array with all the buttons in the sub bar
for (var i:int = 0; i< subButtons.length; i++) // create a for loop to add the CLICK event listener to all the buttons in the sub bar at once
{
[code]....
View 1 Replies
Aug 18, 2010
I have an array of a custom class. The class includes 3 movieclips that all share the same position. I have 5 items in the array, and in the document constructor I fill them as such:
ActionScript Code:
glassArray[0] = new glasses(spot, beam1, glasses2, "index/nav/aboutus", new Point(156, 400));(different string and point for each of the 5 items)
Here's the glasses constructor:
ActionScript Code:
public class glasses extends MovieClip{ //I am the Constructor.
public var spot:MovieClip;
public var beam:MovieClip;
public var glass:MovieClip;
protected var target:String;
[Code] .....
It then goes on to fill each of those mclips with properties based on the point received. How to addchild from the class, I've got a simple for loop in the document constructor that adds them all in. Everything works, except what I'm seeing is that as each item in the array is added in, it overwrites the previous items' properties. In effect, I can create 5 items and give them each a different position, but when I go to addChild I see that all of them have taken on the position of the 5th one.!
View 2 Replies
May 20, 2009
I am creating a container. When I press a button outside the container it adds a movieclip. The movieclip is the width of the container but only a fraction of the height.
I need to know how to get it so every time I press the button it adds the movieclip after the last one, almost like appending a list. Does anyone know how I would do this?Do I use an array or does flash have some sort of table feature?
View 1 Replies
Mar 15, 2011
I want to create a grid of movieclips using an array. But every movieclip added needs some sort of unique idenifier so i can access each individual movieclip.
The grid is 6 movieclips on the Y and variable on the X(that doesnt really matter to be honest)
I have managed to create an Array that displays 6 movieclips on the Y using this [code]...
now i tried creating another class and storing the 6 tickets i made in this class in another movieclip and then using the same method in the other class (i called it Ticket_Batch) i created another row of 6 movieclips. although this kind of worked visually i could no longer access each individual ticket.
my question is: how do i create a 6 x 36(or any other multiple of 6) grid of my movieclips in the same class using an array (or 2 arrays) and giving each movieclip an instance name that i can access and use?
View 4 Replies
Jul 27, 2009
I'm using addChild(new nmonster()) to populate an on stage MC from my Library.
Instead of specifying the Symbol, I want to add it using an Array reference, like addChild(new monsterArray[0]()). I've tried a number of variations, but AS3.0 is unforgiving.
View 4 Replies
Apr 26, 2010
why i keep getting Parameter child must be non-null. And my code won't display 5 enemyBlock objects onto the stage but only just one.
returns:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChild()
at flash.display::Stage/addChild()
[Code]....
View 2 Replies
Sep 25, 2009
I want to loop through an array and use the array value to reference a variable.
The Setup:
(For illustration only. Not actual script)
My MCs:
triangle_mc
square_mc
[Code]....
View 1 Replies
Aug 25, 2011
ActionScript Code:
var answerArray:Array = ["3", "2", "5", "3", "2"]; //these are the correct answers
var answeredArray:Array = ["3", "1", "1", "3", "2"]; //this is an example of what the user
[code]....
View 3 Replies
Jun 15, 2011
I'm trying to have a class file which can add objects to the stage via addChild; however, when I call addChild from within the class file, I get the error "1180: Call to a possibly undefined method addChild." I've tried importing flash.display.* and that doesn't fix the problem. Does the class file have to extend Sprite or MovieClip to be able to add objects to the stage?
View 8 Replies
Jan 16, 2012
I have downloaded Box2d ([URL]) and created a project that looks like this: [URL]. catalyst is the green cube and it has the base class "shapes.box", it is inside "world" which has the base class "wck.World". What i want to do is to add another "catalyst" from the library inside "world" when i click on add_btn. I tried to accomplish this by this code:
[Code]...
Symbol 'buttons', Layer 'Actions', Frame 1, Line 41061: Call to a possibly undefined method addChild through a reference with static type Class.
View 9 Replies
Jan 20, 2011
I have the followings:
_p:Player (which is a MC)
a1:Animation1 (which is a MC)
_p.addChild(a1); //doesn't display anything
_p.stage.addChild(a1); //displays a1
Why won't the MC display a child without using his stage?
View 1 Replies
Aug 11, 2009
I'm trying to resolve an issue that reared it's ugly head yesterday.Frame one of main timeline I have the following code:
Code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
[code]....
The newMC doesn't show up.If I add 'parent.' in front of the addChild then it appears.mc_LibItem has a base class of "flash.display.MovieClip" and is exporting for ActionScript and on frame one.For grins I created a new .fla and began messing around with the same addChild idea and it worked.
View 14 Replies
Oct 30, 2005
somewhat understood the basics of adding and removing children, however, I am facing another problem. After using the removeChild Function, I can't seem to add another child.For example:
ActionScript Code:
var attachedMC = new (getDefinitionByName("Content1") as Class)()
Page.addChild(attachedMC);
[code].....
View 3 Replies
Jan 20, 2011
I have this flash movie I've been working on for awhile. I've received in these forums. I have my file set to load an array of swfs. Now, though, I'm wondering how to keep it from looping. At the end of the last swf, I want the movie to go to the last swf and then just stop. Here is my code:
[Code]...
View 9 Replies
Nov 11, 2009
I have this map I'm creating in Flash. You click on a state, then you can click on an icon to view a tooltip/popup of some information. What I was trying to do was instead of creating new functions and event listeners for every different icon is to use a for loop...but it's not going so well.[code]...
View 2 Replies
Jun 21, 2010
I've a container file which loads an array of SWFs. The code is as follows:
var request:URLRequest;
var loader:Loader= new Loader();
stage.addChild(loader);
var myMovies:Array=["../flash/movie1.swf","../flash/movie2.swf", "../flash/movie3.swf"];
var movieNum:int=0;
var mcExternal:MovieClip;
[Code] .....
This works fine - the array is loaded and plays through once... What changes are needed to get it to loop through the array.
View 2 Replies
Oct 6, 2010
how can i set an array by using a loop.. the array is contains by a data that i read from database.. so the length of carry depend of the length of data in my database..
i try to use
for (var i:int = 0; i < xxx; i++) {
products = [p[i]];
}
i never read data from database in as3.. so if i want to use the data in database for this loop,what should i do?
View 2 Replies
Feb 16, 2008
if you could run a loop in an array?
I'm having to make an array that has each value increase by a 10, like 10, 20, 30, etc. is there an easier way to put in those values without adding them 'manually'?
and I have another question that is related. For this same project, on the stage there will be a text box and the user will put in a number--how can that value be run through the array? like say I input the number 500, how does it find it in the array? is there a passed id, a listener and a broadcaster?
View 2 Replies