Array Of Arrays
Can someone please help me with this. I am trying to make an array of arrays.
ActionScript Code: var bodytype:Array = new Array;var gender:Array = new Array;var allArrays:Array = new Array;bodytype = [fbody_small, fbody_medium, fbody_large];gender = ["boy", "girl"];allArrays = [bodytype, gender];function hideAll (ev:Event):void{for (var i:Number = 0; i < allArrays.length; i++) { allArrays[i].visible = false; trace ("gooooooood");} Thanks
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 06-04-2008, 02:01 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Copying Array Inside Array Of Arrays
Hi,
I've got an array made up of other arrays, and I need to copy one of the arrays to a tempory array (so i can copy it)
I've tried using...
TempArray = ArrayList[0].splice();
but TempArray just shows (in debugger) as undefined, any idea's??
thanks
phil.
[F8] An Array Of Arrays
I'm loading a number of arrays from a text file. I want each of those arrays to be loaded into another array. The number of arrays may change depending on the info in the text file. How can I dyamically create the array of arrays?
Example:
My textfile
&thisTitle=Clothing - La ropa&
&arr_p1=boots|las botas|las botas|las botas|las botas|Quiero comprar|las botas|negras.|sound1&
&arr_p2=socks|los calcetines|los calcetines|los calcetines|los calcetines|Quiero comprar|los calcetines|blancos.|sound2&
&arr_p3=dress|el vestido|el vestido|el vestido|el vestido|Quiero comprar|el vestido|azul.|sound3&
&arr_p4=swimming suit|el traje de baño|el traje de baño|el traje de baño|el traje de baño|Quiero comprar|el traje de baño|azul.|sound4&
My LV code
lv = new LoadVars();
lv.load("sounds/first.txt");
lv.onLoad = function(success) {
if (success) {
myTitle = this.thisTitle;
p1 = this.arr_p1.split("|");
trace(p1);
p2 = this.arr_p2.split("|");
p3 = this.arr_p3.split("|");
p4 = this.arr_p4.split("|");
}
};
I want to end up with ...
myArray [p1, p2, p3, p4];
...but this array may change based on the number of arrays put into the text file.
Thanks for your help.
An Array Of Arrays?
(Using flash CS3/AS2/3)
The code I have now, (see attached zip link) picks colors randomly from the myColors class.
I want to modify this code so the Class has sets of "myColors" (EG "myColors2", "myColors3") and the fla will pick a random "myColors" array and only use the colors within that array to display in the swf each time it is run. does that make sence?
Ive got this far but cant workout the next bit, which im sure isnt a big step and your help would be most helpful.
Thanks
Chris
Arrays Within An Array
Hi,
how can I read a 2dimensional array.
I have a main_array:
var main_array:Array = Array();
the main_array looks like: [x,x,x,x,x,x,x,x,x,x]
I have a itemA_array, looks like: [A,AA,AAA]
I have a itemB_array, looks like: [B,BB,BBB]
I put the 2 arrays into the main_array:
main_array.splice(2,1,itemA_array);
main_array.splice(3,1,itemB_array);
So far no problem. I load the main_array up with LV to the Database.
It arrives correctly.
The main_array is 10 elements,
itemA is on [2]
itemB is on [3]
The problem:
when I read the data in with LV like:
var main_array:Array = Array();
main_array = this.main_array;
Flash cannot read, that the elements on [2] and [3] are arrays.
Now my main_array has a length of 14 elements, it reads the As + Bs as single elements.
How can I read the 2 item arrays??
Thank you in advance.
Luciewong
Copy Array Containing Arrays
Hi,
How would you, copy an array, that contains other arrays? I think "slice" only works 1 level deep?
thanks
phil.
Sorting Arrays Within An Array
hi there,
I have several values stored in multiple arrays (let's call these 'secondary arrays'). Each 'secondary array' is stored in one cell of another array ('main array'). The structure would look something like this:
Code:
mainArray(secondaryArray(number, textField, textField,...), secondaryArray(number, textField, textField,...), ...)
I was wondering if there was a way to sort the secondary arrays according to one of the values in them (namely the 'number')
Is that possible at all? Any help would be appreciated
Ta
Array Of Arrays, Multidimensionals Maybe?
Hi All,
First time posting, after spending the last week trying to get into actionscript. My question has to do with arrays, specifically, I want to record all mouseup and mousedown actions on the stage, then eventually use the drawing API to draw lines between each down and the following up point. But the current problem is probably more simple:
Code:
var this.ptArray:Array = new Array();
//array will contain [indexnumber:number, connected_to_previous:boolean, _x, _y]
this.onMouseDown = function(){
this.myX = _xmouse;
this.myY= _ymouse;
this.myTempArray = new Array();
this.indexnum = this.ptArray.length+1;
this.myTempArray.push(indexnum, 0, myX, myY);
trace(" myTempArray : "+myTempArray);
this.ptArray.push(myTempArray)
trace(" ptArray : "+this.ptArray);
}
The problem - I can't get my temp array to populate the ptArray. I've also tried changing all of the this.ptArrays to _root.ptArrays, but it still appears empty upon trace?
Thanks,
dialectric
Arrays In One Single Array?
Hi!
is there a way to place arrays in one arrays?
like i got three arrays here, and i want to place them in one array.
ActionScript Code:
var aVisible1:Array = new Array(mcMPR1, mcMPR2, mcMPR3, mcMPR4, mcMPR5);
var aVisible2:Array = new Array(mcMPR6, mcMPR7, mcMPR8, mcMPR9, mcMPR10);
var aVisible3:Array = new Array(mcMPR11, mcMPR12, mcMPR13, mcMPR14, mcMPR15);
//now I want to place all arrays in one array something like
var aAllarraysInOne:Array = new Array(aVisible1, aVisible2, aVisible3);
//but that's not the right way.
anyone who can help?
thanks in advance*
Create Arrays From Array
Hey guys,
tryign to use something liek this:
ActionScript Code:
var section:Array = new Array();section = ["a","b","c"];for(item in section){ _root[item]= new Array{} }
to create array objects from each item in the 'section' array, basiically giving me
a= new Array;
b= new Array
c = new Array
What am i doing wrong here?!
Combining Arrays To Form New Array
Hi,
I need to create an array by combining 4 others. If I just create the array naming the variable name of the other arrays as the elements, it leaves me with a 4 element array. I need all of the elements of all 4 arrays in the combination array. What is the best way to do this?
TIA,
aaroneousmonk
Can I Make An Array Of Pointers To Other Arrays?
Hi again, I'm building a really cool system to parse through properties of a sports team.
I've gotten quite far, but I have a little peice of code I'd like to optimize.
Basically I have a number of arrays called: "KeyTeam[]", "KeyPlayer[]" etc.
And with each array I need to perform a language logic match based on some entered data.
My question is this: I'd like to make a loop so i can call all the arrays via one function, I thought I'd be "smart" and use a reference array named "lookUpKey" so i can replace the array object name with a pointer to the array. But AS thinks I am inserting a string, and not a pointer to the array... is there anyway to have an array with pointers to another array (object)?
Here is a striped snip of the code I am using:
Thanks!!!
Code:
KeyTeamStr = [];
KeyTeam = [];
KeyPlayer =[];
KeyPlayerStr =[];
KeyWhere = [];
KeyWhereStr =[];
KeyWhen = [];
KeyWhenStr =[];
KeyWhat = [];
KeyWhatStr =[];
KeyVs = [];
KeyVsStr =[];
lookUpKey = new Array ("KeyTeam", "KeyPlayer", "KeyWhere", "KeyWhen", "KeyWhat", "KeyVs");//pointer to actual arrays with these names
lookUpKeyStr = new Array ("KeyTeamStr", "KeyPlayerStr", "KeyWhereStr", "KeyWhenStr", "KeyWhatStr", "KeyVsStr");//pointer to actual arrays with these names
//main logic loop:
for (u= 0; u < lookUpKey.length; u++) {
trace("LOOP:"+u);
trace("lookUpKey[u]:"+lookUpKey[u]);
//the problem is this next line, it thinks these are strings and not my arrays:
stepIntoMatches (KeyString, lookUpKey[u], lookUpKeyStr[u]);
}
Arrays || Dynamic Array Name & Set Index
Hi, I have been searching through the forums and could not find anything regarding my dilemma.
I created a three stage break down of a mass string into arrays the second array
set("display_info_"+x, info_split[x].split("*"));
breaks information incrementally into
display_info_0
display_info_1
display_info_x
This works and the "display_info_x" is populated with the correct data.
Now here is the problem I am facing. I need to populate a new array lets say it is:
batch_list = new array()
with
display_info_{x}[2]
I have written this to display what I am trying to achieve, this is a non-working setup but should give you an idea of what I am talking about.
batch_list[x] = eval("display_info_"+x+"[2]");
This is looped through and stops according to x amount of "display_info_x", this is not that important (the looping) mainly I need to know if there is a way to an array name called dynamically.
Thank for your help...
RD
Arrays To Nested-array Problem
A kind forum-member (Xeef) helped me find a solution to an array problem, but now I'm flummoxed as to how to convert my two simple arrays into the nested style: [{v:12, w:6}, etc.]
I tried several ways to construct the nested array style, and I feel I am close with the following, but no cigar:
ActionScript Code:
v = (12,21,-13,48,33);
w = (6,-99,7,-2,-2);
VW = [{}];
for (a=0; a<v.length; a++) {
VW[a].v.push(v[a]);
VW[a].w.push(w[a]);
}
for (a=0; a<VW.length; a++) {
trace(VW[a].v+" "+VW[a].w);
}
//no output
//I need the output: VW = [{v:12, w:6}, {v:21, w:-99}, {v:-13, w:7}, {v:48, w:-2}, {v:33, w:-2}]
Array.shuffle() & Non-repeat Arrays
First, let me say that I love Rothrock's Array.shuffle() and I think it an awesome method, give up the props. But I've heard it said several times that by using the shuffle, it will produce non-repeating choices from the array.
I could be mis-understanding (probably) or not using it correctly (likely), but I've never been able to understand how 'shuffling' the contents of the array would eliminate any of the possible choices, regardless of the index being chosen at random or statically. although the method does a fabulous, perfectly conceived, stupendous, superbly executed (that was butter for Rothrock :) job of shuffling it, I don't see how it's still not possible for items to occationally repeat, through natural random chaos. Granted the more elements in the array, the less likely this occurs, but I believe it will occur.
I did a little experiment to see what happens, and it seems to validate this, but I'm probably doing something wrong anyway. So I though I'd open a disscussion, because I'd like to know more, and get some of the thoughts on this from everyone, maybe work out a solution, or tell me what the heck I'm doing wrong.
Once again though, no shot a Rothrock here, this method truely 'rocks'. Just quest for knowledge.
Here's the code I used, very simple, try it out and pick it apart:
Attach Code
stop();
Array.prototype.shuffle = function() {
for (var ivar = this.length-1; ivar>=0; ivar--) {
var p = random(ivar+1);
var t = this[ivar];
this[ivar] = this[p];
this[p] = t;
}
};
var Ar = [1,2,3,4,5];
var prev=null;
var it=1;
var index = false; //set: true=0[static index], false=rndNum
onEnterFrame = function() {
Ar.shuffle();
(index) ? i=0 : index=Math.round(Math.random()*4);
if(prev==Ar[i]) {trace('repeat after iterations: '+it); it=1;}else{it++; prev=Ar[i];}
}
[F8] Array Help (matching Actions For 2 Arrays)
Hey all...
I'm working on a mockup for a solution...
Got an array of button movie clips and an array of clips these buttons control. Got the button stuff worked out, but I need the buttons to control the corresponding movie clips....
I'm close, but on click the buttons all move the same clip, not the one they're supposed to. I've attached the fla (explains it better)...
Here's the codeActionScript Code:
ActionScript Code:
ActionScript Code:
import mx.transitions.Tween;import mx.transitions.easing.*;//------------------------------------function setArray() { for (var mc in squares) { squares[mc]._y = -100; }}//------------------------------------var squares:Array = new Array(_root.squares.v1, _root.squares.v2, _root.squares.v3, _root.squares.v4, _root.squares.v5, _root.squares.v6, _root.squares.v7, _root.squares.v8, _root.squares.v9);var buttons:Array = new Array(b1, b2, b3, b4, b5, b6, b7, b8, b9);var tweenMethod = Back.easeInOut;//------------------------------------for (var a = 0; a<buttons.length; a++) { btn = buttons[a]; btn.id = Number(a)+1; sqs = squares[a]; sqs.id = Number(a)+1; btn.onRollOver = function() { new Tween(this.stinky, "_xscale", tweenMethod, 100, 150, .5, true); new Tween(this.stinky, "_yscale", tweenMethod, 100, 150, .5, true); }; btn.onRollOut = function() { new Tween(this.stinky, "_xscale", tweenMethod, 150, 100, .5, true); new Tween(this.stinky, "_yscale", tweenMethod, 150, 100, .5, true); }; btn.onRelease = function() { setArray(); new Tween(sqs, "_y", tweenMethod, 0, 50, .5, true); };}//------------------------------------stop();
Associative Arrays: Array Or Object?
Dear all,
I am having a confusing night with Associative Arrays in Flash CS3. For example I wrote these lines:
HTML Code:
var listMC: Array = new Array ();
listMC["0"] = "instance0";
listMC["1"] = "instance1";
listMC["2"] = "instance2";
listMC["3"] = "instance6";
listMC["6"] = "instance8";
listMC["7"] = "instance5";
trace(listMC.length);
Result/ 8
Why 8? It seems flash assumes that it has to take into account those missing numbers (4,5). If I use a loop to see the content of the array I got:
HTML Code:
instance0,instance1,instance2,instance6,,,instance8,instance5
This confirms the assumption. And if I use:
HTML Code:
listMC["id0"] = "instance0";
listMC["id1"] = "instance1";
listMC["id2"] = "instance2";
listMC["id3"] = "instance6";
listMC["id6"] = "instance8";
listMC["id7"] = "instance5";
trace(listMC.length);
Result/ 0
No idea why!!!
So, I tried using objects and I got
HTML Code:
var listMC: Object = new Object ();
listMC["0"] = "instance0";
listMC["1"] = "instance1";
listMC["2"] = "instance2";
listMC["3"] = "instance6";
listMC["6"] = "instance8";
listMC["7"] = "instance5";
trace(listMC.length);
Result/ undefined
Not lucky again
A light in this world of darkness?
Thanks in advance
Question For Array Guru's On Re-initializing Arrays
I have a flash application that constantly can call mysql to get new variables. These variables get put into arrays in Flash. However, when I call new variables, these arrays don't get reinitialized and some elements of the arrays hold the correct elements but also the old ones too. Here's what I've tried.
Right before calling the loadvariables again, I run loops on array[i] setting to "".
I've also tried array = new Array() to possibly empty them.
I have not tried any pop's though.
Does anyone know a Flash function to re-initialize or empty an array.
Thanks.
~Z~
Sorting An Entire Array Based On The Value In One Of Its Sub-arrays
All the 'sort' tutes I can find either seem to refer to sorting an array by
it's top-level values or by a separate 'comparative' array.
What I need to do is sort an array by one of it's own grandchildren, i.e.
____________________________
Array
----[1]
-------[element1]
-------[element2]
-------[element3]
-------[element4]
----[2]
-------[element1]
-------[element2]
-------[element3]
-------[element4]
..etc etc
____________________________
..where I might want to sort the array by 'element3', for instance.
Any ideas?
Thanks.
Array Painter - Easy Made 2D Arrays
http://flashkit.com/board/showthread...hreadid=619448
forgive me for double posting. I was in doubt where to post this thread.
pls post comments in the other post.
Concatenating Dynamically Created Arrays Into One Big Array
I'm dynamically creating arrays based on an xml file that may grow or shrink.
My question is: how do I concatenate those arrays into one large array without knowing how many I will need to combine, since my xml file may change?
I'm aware of the concat() method for the Array object, but every example I've seen uses a finite number of arrays to concatenate.
Any suggestions?
Array.push For Objects Arrays / Problem
Code:
_global.tempItem = new item;
_global.tempItem = _global.allitems[_global.itemToCreate];
_global.tempItem.posX = Number(-50) //Number(_global.myIgra.traka.minX);
_global.tempItem.mc_name = _global.tempItem.ime + _global.myIgra.items.length;
_global.myIgra.items.push(_global.tempItem)
Here I wanted to fill items array (that is property of myIgra object) with instances of item class. This happends every X seconds (I'm adding new item in array in loop) and I'm getting array with item objects but they are totally same.
When I look at debug I get all elements in array with same values (from last entry).... is there easy way just to tell Flash to set new object in array and forget about tempItem. ?
it's seems that tempItem is still connected to all instances in Array...
I can't figure out why....
Thanks in advance!
Help With Arrays (removing A Specific Entry In An Array)
Hi im am currenty having some problems figuring this out.
I would wanna ask hw do u remove a specific entry in an array?
lets say i have 1O items in the array and somewhere later on i wanna remove the 5th entry... How would i go abt doing tt?
i tried researching but i could only find methods to remove the last/first line of code. Theres splice but ive read that its only modifes the specific entry right???
sorry if its a stupid question as im nt v gd in actionscript.
thanks a million and any help will be deeplu appreciated
Trouble With Web Service That Returns An Array Of Arrays
Hello,
I have a project thats dealing with making SOAP calls to various web services. One in particular returns an array of arrays for the logged in user. When I do a trace() on the return, it traces out as [object Object]. So I assume that this is the Main Array. Everything I do to try and access the contents traces out as undefined. Hope this makes sense. I am unable to post the exact code due to my clients security concerns.
Thanks for any help you can offer.
~squirt
Actionscript Compare Two Arrays And Create New Array
I have two arrays which contain something like:
array_one = (a->b, b->c, c)
array_two = (a, b, b->c, c)
and I want to concatenate these (I can do that) but remove duplicates. So at the moment I have:
array_three = (a->b, b->c, c, a, b, b->c, c)
whereas I want it to be:
array_three = (a->b, b->c, c, a, b) the order doesn't matter.
Can someone show me how to do this please? I think I either need to compare each element before concatenation, or somehow remove duplicates afterwards?
Are Strings Arrays? 4 Digit Date To 4 Element Array?
Getting my feet wet in actionscript and see that it sure resembles javascript, which, if I remember correctly lets you access each individual characters in a string as an element in an array. Can this be done in actionscript?
what I'm trying to do is turn the .getFullYear (2001) into some sort of form where I can access each individual number, be the 2 the zeros or the 1.
Passing Array Variables Into Functions (and Why I'm Hopeless At Arrays)
OK, I have spent a day on this now and have done some fairly extensive searching online. The problem is - I am hopeless with arrays (and probably just actionscript generally for that matter)
I want to create an array of buttons, so I set up an array of actions, step through each item and then try to pass that array action into an onclick button for an attached button
The problem I have is that the onclick function ALWAYS returns the last item in the array.
Help!
Code below:
----------------------------------------------------------------
Attach Code
//set up array
var myArray:Array = new Array("action1","action2","action3");
// for each item in the array
for (var i:Number = 0; i < myArray.length; i++) {
var myArrayNode = myArray[i];
myArrayIndex = i+1;
var myButton:MovieClip = attachMovie("workIndexBtn", myArrayIndex, this.getNextHighestDepth());
//ignore -- offset each button by 100px
myButton_x = myArrayIndex*100;
myButton._x = myButton_x;
//end ignore
//action button for each item in the array with correct action
myButton.onRollOver= function() {
trace(myArrayNode); //always returns action3
};
}
Transferring Array Data Between Arrays While Keeping Them Multidimensional
Hey guys, I need a little help. So I'm trying to set up a system for quests in an RPG. The idea is that you get quests, and don't have to finish them in any particular order, so when trying to remove the quest from the array i can't use shift() or pop(). So I've made a function to delete the quest should it be in the middle.
The parameter sent is the ID number of the quest.
Code:
function RemoveQuest(ID#:Number){
for(i=0; i<Quests.length; i=0){
if (Quests[0][0] == eval(ID#)){
found=true;
AddToTalk("Quest Complete: " + Quests[i][1]);
AddToTalk("Gained EXP: 15");
Char_EXP += 15;
Quests.shift();
//trace(Quests[0]);
for (k=0; k<Temp.length; k=0){
j = Temp.length - 1;
//trace("Temp.length = " + j);
//trace("Temp[j] = " + Temp[j]);
//trace("Adding " + Temp[j] + " in to Quests");
Quests.unshift(Temp[j]);
//trace("Done");
//trace("Quests now says: " + Quests);
Temp.pop();
}
} else if (found==false){
j = Temp.length;
//trace(j);
//trace("Adding " + Quests[i] + " into Temp");
Temp[j] = Quests.slice(0,1);
//trace("Done");
Quests.shift();
//trace(Temp[j]);
}
}
}
That works fine, except for one small thing. This piece of code also stores all of the quests before the one that gets deleted into a temporary array called Temp. Once it has deleted the appropriate quest, it moves the values in Temp back into Quests using the unshift() method. Now here's my problem; before i move Quests into Temp, Quests looks like this:
Code:
i = Quests.length;
Quests[i] = ["02", "Getting Some", "The Quest Giver says I won't be ready to become a true hero until I get some. I'll have to find out what 'some' is..."];
This of course spits out Quest[0][0] as "02"; Quest[0][1] as "Getting Some" etc.
Once I move this into Temp using my RemoveQuest() function with the following code:
Code:
j = Temp.length;
Temp[j] = Quests.slice(0,1);
Temp looks like this:
"02, Getting Some, The Quest Giver says I won't be ready to become a true hero until I get some. I'll have to find out what 'some' is..."
For those who can tell, this has now become a singular array, where Temp[0][0] is "02, Getting Some, The Quest Giver says I won't be ready to become a true hero until I get some. I'll have to find out what 'some' is..."; Temp[0][1] is undefined and Temp[0][2] is undefined.
This totally destroys everything. Help please?
Completely Forgot How To Work With Arrays, Create A 2d Array With A Loop?
i want to create a 2d 8x8 array completely filled with 0's.
[[0, 0],
[0, 0]]
something that looks like that. ive gone through many variations of using push and a loop nested within another loop. nothing works. first, i tried to establish the first d of the array so to speak then fill it with the nested loop. then i tried to just say loop[1std].push
none of these attempts worked..
board=new Array()
for(x=0; x<8; x++){
for(y=0; y<8; y++){
board[x].push(0)
}}
thats about what it should look like i think but im missing afew lines of code. can anyone help?
[MX04] Trace Command Will Recognise Values Of Arrays, But Not The Array Itself
Hey all,
I'll begin with offering my script:
Code:
news_a = ["first","Second","Third","Forth"];
function submenu(list,stemx,stemy)
{
createEmptyMovieClip([list+'_holder'],this.getNextHighestDepth());
arr = eval(list) + "_a";//list is 'news'
for(no=0;no<eval(arr).length; no++)
{
trace(eval(arr)); //works
trace(eval(arr[1])); //doesn't work
}
}
I think that's all there is. The value of the list parameter is 'news' as declared by another function that calls this one.
Now, when I try to trace the arr, value news_a, it will all four values in the output window. However, when I try to print a single array it won't work. Can anyone see why?
Thanks,
Greenham.
Arrays In A Text File To Arrays In Flash
What i am wanting to do is get an array list from an external file and put it into flash arrays, the code i tryed to use was this:
PHP Code:
for (i=1; i<33; i++) {
if(id=="undefined" || id=="NaN"){
} else {
id[i] = id(i)
}
}
But that dosent work obviously.
I know ive got the
PHP Code:
id[i]
bit right, but i dont know how to do the bit from the text file.
in the file it goes like this:
PHP Code:
id1=432&id2=324 ect
So basically what i am trying to ask is how to in a look do variables using the i (id plus the i at the end). Anyone got any ideas?
Sorting Arrays...2-Dimensional Arrays
How would I go about sorting two dimensional arrays using the sort() function. What I'd like to do is organize the arrays inside of an array by a certain variable...
i.e:
array1 = new Array("Name", "State1", "Cost");
array2 = new Array("OtherName", "AnotherState", "OtherCost");
array3 = new Array("DifferentName", "YetAnother", "AndAnother");
allarrays = new Array(array1, array2, array3);
Now, let's say I want to sort the arrays in allarrays by their state variable. In other words, I want to sort them so allarrays would look something like this (if sorted by state):
allarrays:
array2,
array1,
array3
Any suggestions or past experiences with this sort of sorting? Would I use the Sort() fuction? or would I have to make my own sort function? Thanks in advance for any help you can provide.
Arrays: Cleaning Up Empty Arrays
Hi,
So, I have an array generator, and its not worth explaining the details, but long story short, I end up with an array in which some of the slots are "undefined". How can I go through and remove just those slots? Eg this this my Array
myArray[1] = "red"
myArray[2] = "blue"
myArray[3] = undefined
myArray[4] = "pink"
myArray[5] = "undefined
and what I want to end up with is:
myArray[1] = "red"
myArray[2] = "blue"
myArray[3] = "pink"
thx!
-Z
Arrays/Arrays/Arrays/and Functioning.
Can someone please , tell me how to shorten that Rescale function to just do all the movies in one shot ? and also to add an array for the delay which is the ( o.2, 0.4,0.6 ) so i need to shorten all this to do something like this
Code:
rescale = function(){
this.scaleTo(100,2,"easeOutElastic",this.speed);
this.alphaTo(100,2,"linear",this.speed);
}
//... the next line is inserted within the duplicate movie loop
eval("item"+a).speed = 0.2*a
Instead of all this..
Code:
// Callback Function for lacos to tell when to rescale/alpha back to 100 percent
reScale = function(){
//How can I shorten this by just making an array and doing this in One shot ? is the only problem
item0.scaleTo(100,2,"easeoutElastic",0.2);
item0.alphaTo(100,2,"linear",0.2);
item1.scaleTo(100,2,"easeoutElastic",0.4);
item1.alphaTo(100,2,"linear",0.4);
item2.scaleTo(100,2,"easeoutElastic",0.6);
item2.alphaTo(100,2,"linear",0.6);
item3.scaleTo(100,2,"easeoutElastic",0.8);
item3.alphaTo(100,2,"linear",0.8);
item4.scaleTo(100,2,"easeoutElastic",1);
item4.alphaTo(100,2,"linear",1);
item5.scaleTo(100,2,"easeoutElastic",1.2);
item5.alphaTo(100,2,"linear",1.2);
item6.scaleTo(100,2,"easeoutElastic",1.4);
item6.alphaTo(100,2,"linear",1.4);
item7.scaleTo(100,2,"easeoutElastic",1.6);
item7.alphaTo(100,2,"linear",1.6);
item8.scaleTo(100,2,"easeoutElastic",1.8);
item8.alphaTo(100,2,"linear",1.8);
item9.scaleTo(100,2,"easeoutElastic",2);
item9.alphaTo(100,2,"linear",2);
item10.scaleTo(100,2,"easeoutElastic",2.2);
item10.alphaTo(100,2,"linear",2.2);
item11.scaleTo(100,2,"easeoutElastic",2.4);
item11.alphaTo(100,2,"linear",2.4);
item12.scaleTo(100,2,"easeoutElastic",2.6);
item12.alphaTo(100,2,"linear",2.6);
};
//Duplicate method puts all movieclips on stage at 0 alpha so the user doesnt see the placement
for (a=0; a<titles.length; a++) {
duplicateMovieClip("item", "item"+a, a+1);
//eval("item"+a).alphaTo(0,0,null);
eval("item"+a).item_txt.text = titles[a];
eval("item"+a).tween("_x", [posX[a]], 4, "easeoutElastic");
eval("item"+a).tween("_y", [posY[a]], 4, "easeoutElastic", 0.1);
//Callback function is set here
eval("item"+a).scaleTo(0,0.2,"easeoutElastic",0.1,reScale);
item._visible = false;
}
Arrays Referencing Other Arrays?
Picture this... I declare two arrays:
array1= new Array();
array2 = new Array();
Then I went through some data and added values to "array1". For this example, let's say it has 20 values. (length = 20)
I want array2 to be a "backup" of this data, so I did this:
array2 = array1;
I would expect array2 to simply be a copy of the contents of array1. But, whenever I .pop() a value off of array1, array2 ALSO loses that same value! How is this possible? Is array2 only a "reference" to array1??
Only Arrays Or Arrays And Objects
Hi
I've been told not to do this with an array...
PHP Code:
var travelbooks:Array = new Array();
travelbooks.push({titel: "Madrid", release: 2004, pages: 248});
travelbooks.push({titel: "Barcelona", release: 2003, pages: 224});
travelbooks.push({titel: "Tenerife", release: 2002, pages: 124});
travelbooks.push({titel: "Malaga", release: 2005, pages: 172});
for (var i=0; i < travelbooks.length; i++) {
trace(travelbooks[i].release + " - " + travelbooks[i].titel);
}
... but to do this...
PHP Code:
var travelbooks:Array = new Array();
var book_1:Object = {titel: "Madrid", release: 2004, pages: 248};
var book_2:Object = {titel: "Barcelona", release: 2003, pages: 224};
var book_3:Object = {titel: "Tenerife", release: 2002, pages: 124};
var book_4:Object = {titel: "Malaga", release: 2005, pages: 172};
travelbooks.push(book_1, book_2, book_3, book_4);
trace(book_1.titel);
trace(travelbooks);
trace(book_releases);
function book_releases():void {
for (var i:Number = 0; i < travelbooks.length; i++) {
trace(travelbooks[i].release + " - " + travelbooks[i].titel);
}
}
Could you tell me why i'm not supposed to use the first example? And why example 2 doesn't work?
Thank you
Ferran
Creating Arrays From Arrays?
I'm not sure this is possible but...
I'm trying to create a series of arrays from one main array.
My main array [main_elements] contains four items - interactive, motion, print and illustration. This main_elements array is dynamically created from an xml file.
I'm wanting to create a set of arrays based on the content within this initial 'main_elements' array.
So i would end up with an interactive array, motion array , print array and an illustration array.
currently i'm at this stage with it...although i've tried every other combination i can think of to get it working.
ActionScript Code:
for(q=0; q<work_elements; q++){
main_elements[q] = xmlDoc_xml.firstChild.childNodes[1].childNodes[q].nodeName
//this is the actual categories of work - the areas - interactive,motion,print,illustration
var Vname = work_elements_ARRAY[q]
//i need to create an array based on the names in the work elements area
//ie i need an interactive array - motion array etc
Vname = new Array
trace("Vname-- "+interactive.length)
//this trace should pick up the newly created interactive array but it doesn't exsits...???
}//end of second for
I would then fill these arrays with the work items.
As you can guess its a menu system of the simplest kind i'm trying to build.
Is there a better way to be doing this or is it a case of correct syntax / approach??
# Of Arrays - Length Of Arrays
Is a length of 540 to long for an array?
If so what a good limit to cap it at?
What # arrays of max limit are to many for a flash movie?
10?
100?
1000?
I'm just curious as i need to track the _x and _y of a dragable MC for as long as possible - 3 to 4 minutes if i can squeeze that. It needs to have smooth motion when it's played back, so the cord's need to be stored about 3 times a second. I was just wondering if anybody has an idea of how much data is too much?
All comments are welcome. Thx
Arrays In Arrays Trouble
does AS3 have capability to do multidimensional arrays? My computer won't let me download it because I have edu version. 2D arrays would make this a lot easier. Here's the class:
Code:
class com.samainsworth.math.matrix {
var arr:Array;
var r:Number;
var c:Number;
public function matrix(r:Number, c:Number) {
this.arr = new Array(c);
for(var i in this.arr) {
this.arr[i] = new Array(r);
}
this.r = r;
this.c = c;
}
public function getPos(r:Number, c:Number) {
return this.arr[c][r];
}
public function fillPos(val, r:Number, c:Number):Boolean {
if(r <= this.r && c <= this.c) {
this.arr[c][r] = val;
return true;
}
else {
return false;
}
}
}
here's the code in the movie:
Code:
import com.samainsworth.math.matrix;
var m:matrix = new matrix(2, 2);
trace(m.fillPos(1, 0, 0));
m.arr[0][0] = 1;
trace(m.getPos(0, 0));
and last but not least here's error:
Code:
true
undefined
I'm trying to work on 3D which requires a lot of matrices work even though flash doesn't support 3D you can fake it with a lot of math - http://www.kirupa.com/developer/actions ... onCube.swf
Array, Array HELP - Importing A External File Into N ARRAY - Almost There
I am reading and external file with the following code:
ActionScript Code:
on (release, keyPress "<Enter>") {
lv = new LoadVars();
lv.onLoad = function() {
questions1 = this.filelist0.split(",");
answers1 = this.filelist1.split(",");
for(i=0;i<questions1.length;i++)
//trace(questions1[i]+" "+answers1[i]);
trace(questions1[i]);
//assumes same number of scores in each list
};
lv.load("questions.txt");
}
When I parse the file it puts it into an columar format as it should...however I need it to look like this:
questions1=new Array ("2+4=?","What is the capital of Illinois?","What color is the sky?","10x(5+2)=?");
answers1=new Array ("8","springfield","blue","70");
How do I do that?
Text file look like this:
&questions1=2+4=?,What is the Capital of Illinois?,What color is the sky?,10x(5+2)=?")&
&answers1=8,springfield,blue,70&
Pls Help: Need To Create New Array Taking 3 Random Entries From An Existing Array
Hello
I have a 2d array:
qTeeth[1] = [How many teeth do we have?, 1-10, 11-20, 21-30, 11-20]
etc.
It goes [question, option1, option2, option3, real answer]
I now just want to extract 3 or so of these entries and create a new array with them. Since I want to just use 3 or so questions randomly from a large array of questions.
Does anyone know a good tidy script to do this with??
Thanks in advance,
Ben.
Array Text Into Textfield And Creating New Line For Each Array Element
I have an array called dropTarg1 which stores dropped-in items.
I want to loop through this array and in a textfield, display each array item on a new line of this text field
I think I need to use something like Array.join("/n") but I can't get it working properly. I hope that the /n would create a new line of the text field called reviewBoxContentText.
for(var i:Number = 0; i<dropTarg.length; i++){
with(reviewBoxContent.reviewBoxContentText){
autoSize = true;
text = dropTarg1.join("/n");
}
}
All that is happening though is that the text field displays on a single line with /n in between each array element.
Calling A Function With An Array Variable As Arguments Is Resetting Array?
I'm going to post the full code of the two functions, disregard the "fluff" unrelated to the two functions as it is all working flawless, I've tested this HEAVILY and cannot understand why it keeps setting the entire array to undefined!
Any help would be grateful.
ActionScript Code:
// processReplace Function function processReplace(transferFiles) { var processArray:Array = transferFiles.slice(); var fileName:String = new String(); var filesArray:Array = new Array(); var replaceArray:Array = new Array(); var exists:String = new String(); var error:String = new String(); var promptResult:String = new String(); // Check for (i=0; i<processArray.length; i++) { // This is where it bugs up <b>exists = processSearch(transferFiles[i][1]);</b> if (exists == "replace") { replaceArray.push(processArray[i]); } else { filesArray.push(processArray[i]); } } // Prompt if (replaceArray.length>0) { error = "Replace "+replaceArray.length+" item(s):
"; for (i=0; i<replaceArray.length; i++) { error += " - "+replaceArray[i][1]+"
"; } promptResult = mSystem.messageBox(error, "Replace Existing Files?", 4); } // Action if (promptResult == "NO") { transferFiles = filesArray; } else if (promptResult == "YES") { transferFiles = filesArray.concat(replaceArray); } processTransfer(transferFiles); }
The processSearch
ActionScript Code:
// == processSearch Function function processSearch(sentInfo) { for (i=0; i<_global.boxFiles.length; i++) { if (_global.boxFiles[i] == sentInfo[1]) { return "replace"; break; } } }
Basically it's supposed to check to see if the file exists and return as true if it does and add it to a replace array, then the replace array is processed into a single string and put into a dialog box through the flash wrapper prompting them to "replace the files or not".
It makes the replace array just fine, it actually even has the right "count" in it but it's setting all the "filenames" to undefined because of the exists = processSearch function.
I even tried to make a new array and run the search just from that one and set the values from the old one and it's still failing.
Is it because of the "break" or can anyone figure it out? Iknow it's hard because you can't use the code
ANY Solution ideas are welcome, even if you think it's dumb
Thanks!
Array.splice Works But Array.slice Doesnt?
This should be simple enough. I have an array of objects, and I want to SLICE a piece of the array and assign it to a new array. All of my attempts have failed. SPLICE works, and I could duplicate my original array into a temp array and splice out what I want, but surely slice is supposed to save me this trouble, right?
I'm a bit baffled, but here's the code:
Code:
private function createGlist() {
var glistObj:Glist = this;
xml_object = new XML();
xml_object.ignoreWhite = true;
xml_object.onLoad = function(success:Boolean):Void {
if(success) {
var i:Number = 0;
for (var this_node = this.firstChild.firstChild; this_node != null; this_node = this_node.nextSibling) {
glistObj.thumb_array.push(new Gthumb(glistObj, glistObj.thumb_array_mc.getNextHighestDepth(), this.firstChild.childNodes[i]));
i++;
}
var load_start:Number = 2;
var load_count:Number = 2;
glistObj.thumb_load_array = glistObj.thumb_array.slice(load_start,load_count);
trace(glistObj.thumb_load_array); //no result, no error
trace(glistObj.thumb_array.slice(load_start,load_count)); //no result, no error
trace(glistObj.thumb_array.splice(load_start,load_count)); //outputs [object Object],[object Object]
} else {
//error
}
}
xml_object.load(xml_url);
}
Array Copy Points To Original Array Instead Of Duplicating
Hey all.
Spent a long time trying to figure out what was wrong with my code. Then I remembered about arrays being objects instead of primitive variables. My question is, how can I make a duplicate copy of an Array?
Details:
So this code
PHP Code:
package{
import flash.display.*
public class tester extends MovieClip{
var a:Array = [1,2]
public function tester () {
var b = a
trace (a)
b.splice(1,1)
trace (a)
}
}
}
results in this output:
PHP Code:
1,2
1
How can i make b an actual duplicate of a, instead of a pointer?
PHP Code:
b = new Array
b = a
doesn't work either.
Thanks!
DHP
Creating Multi-dimentional Array From Single Array
I have an array
myArray=[hello,bye,fred,1,2,3,4,5,6];
I need to convert it to a multi-dimentional array that would look something like below
array1=[hello,bye,fred];
array2=[1,2,3];
array3=[4,5,6];
newArray=[array1, array2,array3];
I am not sure how to split the array can anyone help? myArray.length/3 would give me the number in each of the new arrays but I am puzzled after this?
|