ActionScript 3.0 :: Create Multiple Variables With A Function Or A Loop?
Mar 17, 2010I want to dynamically create variables that will create and place instances of a movie clip on the stage at runtime.[code]
View 5 RepliesI want to dynamically create variables that will create and place instances of a movie clip on the stage at runtime.[code]
View 5 Repliesi am trying to "dynamically" create variable names inside a for loop and add them to an array...
[Code]...
// ' this["thumb" + i] ' is definitely not the way to write it.. so how should i write it?
Is there a way to make the variables generated from a for loop within a function accessible to other functions? because at the moment other functions are firing errors because the variables refferenced are from a different function.
You may of seen this code from other threads
ActionScript Code:
function nodePoints():void {
//VarName, mcName, XPos, YPos
var row1:Array = ["clientComp", new clientComp(), 100, 200];
[Code]....
I want to make multiple empty MCs and fill each one with a thumbnail for a menu. I want to do this using for loops so I can control as many as I need.
What's the most efficient way of doing this?
I'm used to creating empty MCs in AS2, but I'm not familiar with the new display object way of handling this method.
So far I have this:
Code:
for (i=0; i<numImages; i++) {
thmb.push(gallery.features.image[i].@thmb.toString());
var imageLoader:Loader;
[Code]....
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]......
I put together this code that builds a container that contains boxes(squares) in an ordered way. Problem is when I rotate the container, the boxes don't stay in their order. (something to do with swapping depths I think) . In fact, they look a bit confusing. Just create a movieClip 24 x 24 and Name it Box. Create another movieClip and name this one Container. Save them in your library. Then just copy this code and compile. You know the routine.
[Code]...
i'm having a problem with a for loop. The problem is that it doesn't create multiple movieclips with an unique instance, i think it copies over itself.
for( var i = 1, x = -20; i < 4; i++){
if(this['plaatje' +i] != undefined){
_root.again.createEmptyMovieClip("image", i);
[Code]....
i'm having a problem with a for loop. The problem is that it doesn't create multiple movieclips with an unique instance, i think it copies over itself.
for( var i = 1, x = -20; i < 4; i++){
if(this['plaatje' +i] != undefined){
_root.again.createEmptyMovieClip("image", i);
this._root.again.image += _root.again["image" +i];
[Code].....
My issue is that I have 10 small audio clips and I want to make them into variables that i can access later in the code. But I'd be happy if I didn't have to write the same code 10 times down over and over to create/access them.[code]...
A question on the side, is there any built in sound generator in actionssccript 3.0?
If I have multiple variables of the same type, can I create an array and loop to create them or do I need to create them individually.
For instance,
var ajArray:Array = new Array(mc1, mc2, mc3, mc4, mc5, mc6, mc7, mc8, mc9, mc10, mc11, mc12, mc13);
for (var i:number = 0; i<ajArray.length; i++){
var [ajArray[i]]:MovieClip;
}
[code]....
Code:
for (var i:Number = 0; i<12; i++) {
var myFunction_i:Function = function () {
trace("This is function "+i);
};
[code]....
I'm needing to create identical functions but different 'i' Number Variables so that I can call them as shown when I need to.
I'm trying to create multiple Functions inside a Loop.[code]I essentially want to make 4 Functions called closeButOut1, closeButOut2, closeButOut3 and closeButOut4.This is the error message I get:
-1084: Synax error: expecting identifier before this.
-1084: Syntax error: expecting leftparen before rightbracket.
I wished to create multiple copies of a variable in a loop.such as:
var pots:String = thisString [i]
and then i wish to reference one of these loop generated variables.Now how would you set it up so you could have all those variables of "pots" had their own names so one could reference say: "pots1" "pots2" or "pots17" ? This kind of situation would bee seen in a situation where I would be bringing in many array values and assigning certain parts of them to the variables. such as array[i][name]
As seen below, I tried to return more then one variable from a function but , I think I have some syntax problem..
function hesapla3(parametre1,parametre2):(Number&&Boolean) // PROBLEM IS HERE, I NEED TWO VARIABLES TO RETURN{var yenideger2:Number=new Number();var bol2:Boolean=new Boolean();yenideger2=parametre1+parametre2;if(yenideger2>80){bol2=false;}return yenideger2;return bol2;trace(yenideger2);trace(bol2);}
I'm trying to make a point and click game for the fun of it. I'm having troubble with the .onPress function. I've made an array of movieclips, and I want to go through them in a loop, and make an onPress function for each of them. What I am trying to do with the code below is to make the debugText tell me what movieclip I pressed:
var letterArray = new Array();
letterArray = [l1_mc, l2_mc, l3_mc, l4_mc, l5_mc, l6_mc, l7_mc, l8_mc, l9_mc,
l10_mc, l11_mc, l12_mc, l13_mc, l14_mc, l15_mc, l16_mc, l17_mc, l18_mc,
l19_mc, l20_mc, l21_mc, l22_mc, l23_mc, l24_mc, l25_mc, l26_mc, l27_mc,
l28_mc, l29_mc, l30_mc, l31_mc, l32_mc, l33_mc, l34_mc, l35_mc, l36_mc];
[Code] .....
DebugText outputs:
Pressed movieclip nr: 36 36 36 36 36 36
No matter what clip i press, i get the same output: 36. why?
How would one go about creating a function inside a for loop that does not have a button action attached to it while still having access to the current index number.
This code was found on senocular:
Code:
var curr_button; for (var i=1; i<=3; i++){
curr_button = this["button"+i];
curr_button.num = i;
[Code]....
This is all great however i would like the functions to just be regular old functions, not button actions (onPress), is this possible?
I'm attempting to create a graphical representation of the microphone activity in flash for a conference.
I got a movieclip called eqNotch that's just a rectangle and its linkage name is EqNotch.I also have a movieclip where I am writing my as3 on the first frame, its called dynamicBar and linkage name is DynamicBar.
I've successfully written the code for the dynamicBar to create one column of eqNotches and the number of rows is dependent on mic activity.[code]...
I would like the loop to create the multiple setInterval's based off the array, but the function called is not clearing the setInterval...
var timecode = new Array(1, 2, 3, 4);
// use the array to assign the interval
for (var i = 0; i<timecode.length; i++) {
[Code]....
I'm new to Actionscript programming. I'm trying to figure out what is the best way to return multiple variables, each having a different data type, from a function. For example, if a function needs to return variable aa ( a string) and variable bb (a number).
The function I'm using just crunches a lot of math, and doesn't relate to an object in a GUI. One method I got from a Google search used an Object, but as (I think) this requires me to create a class, I wondered if there was a simpler way. Since an array can hold elements of different data types, perhaps this is a simpler approach (?). [code]...
I'm making a XML photogallery. Im using a MovieClipLoader to load multiple images on the screen at the same time. I've assigned variable path to hold image
[Code]....
I just want to know if there is a way to assign multiple variables, and if there is a way to check multiple variables.
I want to be able to assign variables to false and then check if all the variables are false.
If you place a for loop in a recursive function with the function call within the loop... will the loop finnish or does it stop working untill the last recursion?
View 2 RepliesHow can I make a bunch of variables from a for loop. for example for (var i=0; i<total; i++) {var bunch(i);}. that i make a bunch of variables named bunch1, bunch2, bunch3. I keep getting errors. I program and use so many different languages that I dont know if that can be done with AS3. my only other alternative i can think of is to create some sort of event dispatcher object array. but I dont know how to get them all to send events to one listener with there index number.
View 5 RepliesSay, I had a loop in a function...
[Code]....
How would I refer to a in another function
I would like to create a loop so the icons in the menu continually loop indefinitly.[code]
View 2 RepliesI am attempting to use a loop to create text field with the loop's current value. The code looks like this:
ActionScript Code:
for (var i = 1; i<=10; i++) {
var 'nameHolder'+[i]+'_txt':TLFTextField = new TLFTextField();
'nameHolder'+[i]+'_txt'.x = 40
'nameHolder'+[i]+'_txt'.y = 40
'nameHolder'+[i]+'_txt'.text = "Hello World"
}
So essentially what it should do is create 10 text fields at 40, 40 with the text: "Hello World".
[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.
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]........
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].....
i am trying to do a loop to create several variables to aasign each one of those variables one number.when i write
[Code]...