ActionScript 3.0 :: Naming From A Loop?
Aug 8, 2011is it possible to add variables and name them according to position in a loop? for example how can I do something like this:
[Code]...
is it possible to add variables and name them according to position in a loop? for example how can I do something like this:
[Code]...
Is there a way to do this somehow?
Code:
var someVariable:int = 3;
for(var i:int = 0; i< someVariable; i++){
var mainArr[i]:Array = new Array();//I get an error if I try this
[Code]....
k say i wanted to create a bunch of movieclips in a for loop but wanted to name them something different each time, how would i dynamically name them?
View 1 Replieswhat is the syntax for assigning names to textfields created dynamically using a loop.
Code:
for (var i:uint=0; i<10; i++) {
var myText:TextField = new TextField();
myText.defaultTextFormat = textFormat;[code]....
As expected, this code gives me a warning "Duplicate variable definition".How can I assign names dynamically (myText1, myText2, myText3...)?
Code:var StringMine:String = "hello";And i want to use the value of that string, 'hello' to name a new variable, i thought like this,Code:var [StringMine]:String = "One";but not supprisingly, it doesnt work...
View 2 RepliesI thought that there was a way to be able to name array indexes. Like instead of myArray[0], it could be myArray["tileFour"]. I thought that instead of using index numbers one could use index words.
View 1 Repliesi 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:
rectangle_mc.startDrag();
rectangle_mc.x = mouseX;
rectangle_mc.y = mouseY;
[code]...
loader is display object but I could not set name to loader. In the documentation loader does not have property of "name". How to set name for loader instance. Example
var imgColl:Array=new Array("1.jpg","2.jpg");
var i:Number=0;
while(i<tot){
[code]....
I need to change porperites on MC that is in a MC I just attached something and for some reason I can't seem to find out how to get an instance name into them or to just use the one thye have in the library.
View 7 RepliesI have created a function to load up my movies what I would like to do is two things
(i) change the ldr to a movieclip
(ii) add an extra parameter to add an instance name movieclip when I call the movieclip
loadMyImage('images/headers/logo.png', 80, 20 );
function loadMyImage(imageURL, xPos, yPos) {
var ldr:Loader = new Loader();[code]....
Ok, I've been climbing the walls trying to figure this out, looked everywhere for an answer, learned a few bits and pieces along the way, but still can't do it.I've made my Class which is a little movieclip called 'block', it's fine and does what I tell it to do ie. I can reposition itstretch itotate it and stuff.The problem is.. I want to make more of them and reference them individualy so I can change the properties of them individualy ie, the x and y values etc.
for (var i=0; i<2; i++){
var newBlock:blocks = new blocks();
this.addChild(newBlock);
[code].....
I am wanting to create an array. 10 values in it (couting from 0 index to 9). Each 'place holder' will have a corresponding value to it;s index i.e.
myArray[0]=0
myArray[1]=1 etc...
I can do that in a for loop. But then I want to attach each value to a single variable name. I then want to change that each variable to a string. I then want access to all the variables outside of the for loop.
var i:Number;
var aArray:Array = new Array();
for (i=0; i<10; i++) {
[code]....
The output error is 1084: expecting identifier before aArray.
When I instantiate a new object I want the object to automatically be named the same as the name used in the instantiation.var fred:Person=new Person();trace(fred.name); // traces "fred"Is there a reference I can use in the Person constructor to do this?
public class Person extends MovieClip {
public function Person() { name = ??? // what goes here? }}
I'm working on a framework for game development in flash and I'm wondering if there's an accepted naming scheme for the main tick / update method name and a name for the functions to call before and after?I can think of:
onPreTick(), onTick() and onPostTick()
onPreFrame(), onFrame(), and onPostFrame()
onPreUpdate(), onUpdate(), and onPostUpdate()
[code].....
or some reasons i need to create var dynamicaly.
Exemple
I have first an Array wich i want to use to "compose" my vars names
myArray:Array = new Array("aa","bb","cc");
In my final project this Array is created from a xml.
I want to do something like this, but doesn't work...
var ["myvar" + myArray[0]]:Sound = new Sound();
var ["myvar" + myArray[1]]:Sound = new Sound();
var ["myvar" + myArray[2]]:Sound = new Sound();
[Code].....
i create an application using Adobe flex 4.5 for recording videos and i was wondering how to give appropriate names to my files produced. What i was thinking is to give the current timestamp which is unique what's your opinion, is there a better solution and how can it be implemented using actionscript?
View 1 RepliesHow to name through AS3 buttons components?I have 3 buttons components: a BackButton, a ForwardButton and a PlayButton.I have named them through the properties panel, (where it says 'Instance Name').But once I click on them and check for event.target.name I receive, always 'button_mc'.How could I name the buttons?
View 1 Replieswhat is the quickest way to name more than one instance at the same time as i have 84 in total and they have to be named:
MC1 - instance name: 1
MC2 - instance name: 2
MC3 - instance name: 3
MC4 - instance name: 4
MC5 - instance name: 5
etc etc...
I'm curious if there is dynamic naming for variables, arrays, functions and whatnot in AS3. Below are Perl examples of what I'm asking about. It should be pretty explanatory.
[Code]...
I'm producing an array of thumbnails onto the stage from xml, all works fine, but I need to give them a unique number, starting from 0 etc. I believe I'm doing this right but I'm trying to trace back the ID/number from a mouse event...and keep getting the highest number for all of my instances.[code]
View 6 RepliesI made a thread a couple days ago, but dont think i explained the problem well enough. What im trying to do is name each of the children.
Child 0 = A
Child 1 = B
Child 2 = C
all the way to Z. Then start at A again.
ActionScript Code:
function moveBubble(Event) { // This function handles the movement of the bubbles
if (!inPlay) return;
[code]....
I am working on a little project where I have this:
Code:
for (var py:int = 0; py < 6; py++)
{
[code]....
i have a problem whenever i name a movie and set its properties. whenever i use eval on the name it works,
[Code]...
i've heard you shouldn't use eval anymore because it's deprecated, and that you should use this[object]._property instead, but it's not working for me--am i doing it wrong?
I am trying to assign meaningful names to buttons in a for loop based of the var mainBtn.mName. This would normally be easy but i need to to get the width of the buttons before it (the bold code) to work out the position of each button, any ideas how i can do this?
Code:
for (i=0; i<folder.length; i++) {
var mainBtn:MovieClip = mainMenu.attachMovie("button", "button"+i, i);
mainBtn.mName = folder[i].attributes.name;
mainBtn._x += mainMenu["button"+(i-1)]._x+mainMenu["button"+(i-1)]._width+btnSpacing;
I created a slot machine and it works properly but i need it to do more. Currently when you spin the Reel, if you get any 4 of a kind its a jackpot. I need it so if you hit 4 "7's" lets say its different than hitting 4 "Bar's".On the main reel I have 4 frames with movie clips, each having a different (chip) and the end. I have set the random() function on them so it is completely random on how they hit. So my question is...how do I set a variable name for the frames so I know that frame 1 is a "bar", frame 2 is a "7", frame 3 is a "cherry" and so on. That way when I write the "if" statements, I can compare them so a "7" is better than a "bar".
View 2 Repliesi created a flash menu that calls its items from an xml document. the menu items are images that scroll within the menu movie clip depending on mouse position. my problem is that, when clicked, each of these menu items needs to call a pretty complex function.
so this seems like a really basic question, but, is there a tag or something i can use in the xml file to like, name each of the items so that i can write functions with them individually with my actionscript in flash?
I am just getting started with AS3 and have run into a problem. I had a way of attaching movieClips from the library to the stage in AS2 that used the old attachMovie() function where I would run a for loop and it would duplicate the moviclip to the stage and dynamically create new names for the new instances.I now am using this:
var myCube = new cube();
addChild(myCube);
Then, I can access the myCube instance's properties like this:
[code]....
Is it possible to dynamically name a variable? Like set a certain string as a variable name wouldn't think so but just in case.
View 2 RepliesCode:
public function btnU1Out_Handler (event:Event ):void {btnUOut_Handler(1);}
public function btnU2Out_Handler (event:Event ):void {btnUOut_Handler(2);}
[code]......
I'm creating some mc's on the stage with the attachMovie function in a loop. I have no problem naming them like that:
foo.attachMovie("myClip", "myClip"+i, 200+i);
But I need to name them with part of an array like that:
foo.attachMovie("myClip", "myClip"+array[i]+"_mc", 200+i);
I thought that would work but I guess my synthax is wrong. How do you mix strings and arrays elements inside the () of the attachMovie?I need to get something like: myClipArrayElement1_mc for the name of the attached movies...