Addressing Variable Value To Array Element
I am trying to assign the values of variables read from an external variable file to an array.
One way or another I really need to figure out how to do this-
I have been trying a routine similar to the following, however I can't get the array element to accept the expression as a value.
varArray = new Array(); LoadVariablesNum("vars.txt", 0); // lets say that the txt stores the var "X" set( varArray[0], X );
what is incorrect about this assignment?
FlashKit > Flash Help > Flash ActionScript
Posted on: 03-12-2002, 12:26 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Assigning Array Element To Variable
How can i assign an array element to a variable?
Like if i enter "10'5" in to an input textfield I want to assign the 10 to one var and the 5 to another. Im using the next code:
code:
on(release){
_root.lnt.split("'");
}
but i dont know where to go from here, plz help, thanx.
How Do I Create A Variable Name From An Element In An Array?
Hi Guys
I've got an array called alphabet
i've also got a variable called doh which holds the number 14
alphabet[3] would be the letter "d"
how can I now create a new array called d14 ?
var eval(alphabet[3]+doh):Array; doesn't work....
Any ideas gratefully appreciated!
Using Variable In Place Of Element In Array To Addeventlisteners
This is probably something very simple that I just can't seem to get to work. Basically I'm trying to use a variable to be called inside of an array instead of the actual array so a simple example would be
Code:
var people:Array = [john,tom,ann];
var selected = john;
trace(people[selected]);
I get an error everytime I try to use a variable in place of and actual element
This is how i'm trying to use it....
I have an array that i'm adding event listeners to for a navigation.
Code:
var buttons:Array=[productBtn,useBtn,stylesBtn,contactBtn];
for (var i:int=0; i<buttons.length; i++) {
buttons[i].buttonMode=true;
buttons[i].addEventListener(MouseEvent.MOUSE_OVER, over);
buttons[i].addEventListener(MouseEvent.MOUSE_OUT, out);
buttons[i].addEventListener(MouseEvent.CLICK, goToPage);
}
inside the click function "gotoPage" I want to save a variable that takes the last clicked button and re-adds eventlisteners which would be removed to show the active state of the current page.
So when you click it removes the event-listeners and takes the button to its active state. I want to use the current variable to re-add those events for the button and then save the new current or last clicked.
Code:
function goToPage(e:MouseEvent):void {
var current = stylesBtn ; //setting up initial variable
if (e.currentTarget==productBtn) {
trace("you hit the product button");
buttons[0].removeEventListener(MouseEvent.MOUSE_OVER, over);
buttons[0].removeEventListener(MouseEvent.MOUSE_OUT, out);
buttons[0].removeEventListener(MouseEvent.CLICK, goToPage);
buttons[0].gotoAndStop(5);
buttons[current].addEventListener(MouseEvent.MOUSE_OVER, over); //trying to use the current in array
buttons[current].addEventListener(MouseEvent.MOUSE_OUT, out);
buttons[current].addEventListener(MouseEvent.CLICK, goToPage);
current = productBtn; //saving new current for next button click
}
}
Like I said this is probably something simple and my brain isn't working but I appreciate the help. thanks alot.
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.
Variable Mc Addressing
hi there,
i have found a few posts dealing with this topic but i can t seem to get it right.
i got multiple mcs wich i want to control from another mc.
_root.mc_bar.mc_f1.gotoAndStop(2); << this works
now i need one of the following to work :
i = 1
_root.mc_bar.mc_f(i).gotoAndStop(2);
_root.mc_bar.mc_f[i].gotoAndStop(2);
i = "1"
_root.mc_bar.mc_f(i).gotoAndStop(2);
_root.mc_bar.mc_f[i].gotoAndStop(2);
so i can iterate the mcs over i.
thnx in advance
[F8] Addressing Dynamic MC Properties From Within An Array
Hello everyone. I'm looking for some resources and if possible examples of using gotoAndStop on an array of loaded movie clips.
I'm doing a project using the Yahoo Maps flash API, and amfphp. Flash is getting a list of locations from a mysql DB via php and amfphp, and then I am creating a custom swf marker for each location, passing it the ID that it needs to update the content that it displays independantly of the parent movie via url string, and adding it to the map.
I have all of this working wonderfully, but I'm running into the wall when I try to use a treeview structure to pan to and jump to a particular frame of the marker movies. The panning is working, but I can't seem to get the tree object to correctly tell the marker to goto frame(x). I am currently creating an array of the movie clips indexed numerically based on the ID (primary key) of the content provided by the database.
I've spent a few hours messing with the debugging output, but I can't get flash to let me preview the movie in full on debug mode (Shift+Ctrl+Enter) because it crashes hard and asks to send an error report to MS. I've got visual C++ installed, and it gives me the option to debug the crash if anyone would be interested in a stack dump.
The lack of proper debugging for this issue has made it very difficult for me to get a clear idea of the variable scope. Here's a small snippet of how I am creating my movie objects.
code:
markerObjects[tmark] = {url: ThisURL + "marker.swf?ID=" + MarkerData[tmark]['id']};
MarkerData is an array containing all the pertinent info from the database. markerObjects is an array of the objects themselves, ThisURL is predefined for the webserver url and isn't relevant to this question, tmark is a variable with the current index.
Any help would be greatly appreciated.
- Jesse
Addressing Local Variables In An Array?
How do i address local variables in an array?
The following doesn't seem to work
Code:
function gotoPanel( input, p0, p1, p2, p3, p4, p5, p6, p7 ):Void {
for ( i = 0; i < 8; i++ ){
if ( ["p"+i] != undefined ){
//stuff here
}
}
it tries to see if "p0" ("p1", "pn") is undefined, which ofcourse it isn't because "p0" is a 2 character string...
The code I used above always worked with global variables with expressions like _root["thingy"+i]
Why doesn't it work here on a global level? How do I make it work?
Addressing Array Inside A Movieclip
Short and sweet: I can't address the array i've created inside the movieclip from outside!
Array name is categories, inside the templates movieclip in _root; I press a button on _root to trace the array inside the movieclip using this code:
ActionScript Code:
on(release){trace(_root.templates.categories);}
It gives me: undefined
Any ideas?
Addressing Movieclip With Variable
Ok I have actually searched the forums and tried everything they said to get this to work and it doesn't work.
on (release) {
var laspos2 = _global.laspos;
trace(laspos2);
trace(_root.timeline.laspos2.timeline_hilite._curr entframe);
_root.timeline.newscroll = -40;
trace(_global.laspos);
this.timeline_hilite.gotoAndPlay(2);
}
I am trying to get this working:
I want to use a variable (laspos2) to dynamically address a movieclip.
var laspos2 = _global.laspos;
trace(laspos2);
trace(_root.timeline.laspos2.timeline_hilite._curr entframe);
It always gives me undefined for the path. (the laspos2 trace gives me the proper string value.) The mc's I am trying to address are named d1, d2, d3, etc.
If I do this:
trace(_root.timeline.d1.timeline_hilite._currentfr ame);
It gives me the proper currentframe so I know my path to that movieclip is working.
This is extremely frustrating and any help is greatly appreciated. I am on a tight time deadline so please don't hold back if you have any ideas. Thanks in advance.
Actionscript; Variable Frame Addressing?
Hi,
Got a bit of a problem with an attempt to address frames with the following script:
I'v got a name for input in a fuction, and I want to make flash jump in a MC to a frame with the same name....
function test (argument) {
tellTarget ("_level0.movieClip") {
gotoAndStop ("[argument]");
}
}
Flash doesn't seem to understand [argument] for a frame label though.
any suggestions??
thanks
Addressing A Nested Variable In Loop
I don't often get the opportunity to share/compare ideas/code, I was hoping someone would be able to clear up a long-time misconception of mine.
I am trying to use a movieclip basically as a struct, and assigning the values from within a loop. Break it down to the nitty-gritty, and I am trying to set the value of a nested variable with a similar routine:
for ( x=0; x < variableUpperLimit; x++ ) {
duplicateMovieClip( ("clip" add x), ("clip" add (x+1)),x);
// the following statement is arbitrary but it gives you an idea of what I'm doing
setProperty( ("clip" add x), _x, (x * "clip" add x add "._width");
// the following statement is the one I'm having problems with
set( ("clip" add x add ".txtVariable"), "_root.mTxtVar" add x);
// Can someone please explain to me why I cannot assign a variable value this way ??
}
Addressing Movieclip/variable Names
I've run into a problem.
I have 3 movie clips which i want one movie clip to hittest for.
The statement looks somewhat like this:
if (this.hitTest(mc1) || this.hitTest(mc2) || this.hitTest(mc3))
blah blah
is there any way to address all movieclips with the sequence of numbers at the end? I have them duplicated at the start with the variable "d", and I'm finally stuck. I hope you guys can help
Array Addressing Hijinks [or Square Bracket Hell]
I don't know if I should be worried about this. Everything works fine when I publish the file and test it from the finder or browser. If I hit "Test Movie" it all falls apart.
I'm doing a movie theater site. I'm reading all the variables in from a text file (movie names, times etc).
There are 6 theaters, a through f, and each has up to 15 films at any one time. The number of films currently playing at theater a is in the textfile as aqty.
So I load the variables, and pack them into an array on the root level.
code:
//setVariables();
aqty = Number(_level0.aqty);
bqty = Number(_level0.bqty);
etc.
afilms = new Array();
bfilms = new Array();
atimes = new Array();
btimes = new Array();
nowletter = "a";
for (i=0; i < aqty; i++){
thisfilm = _root[nowletter+"film"+(i+1)];
thistimes = _root[nowletter+"times"+(i+1)];
afilms[i] = thisfilm;
atimes[i] = thistimes;
}
When you select a theater from the primary navigation, the button sets idx to that theater's letter (a through f).
Then the theater movie clip runs the following:
code:
idx = _level0.idx;
thname = _level0.theater[idx];
thaddress = _level0.thaddress[idx];
filmq = _level0[idx + "qty"];
filmqty = Number(filmq);
filmarray = _level0[idx+"films"];
timesarray = _level0[idx + "times"];
timesbarray = _level0[idx + "timesb"];
film1i = filmarray[0];
film2i = filmarray[1];
film3i = filmarray[2];
film4i = filmarray[3];
film5i = filmarray[4];
film6i = filmarray[5];
Etcetera. This movie clip has dynamic text fields for film1i and times 1i all the way up to 15.
I developed it in MX (on my laptop), where it was working perfectly. Then I got back to the office and started working on it in MX 2004. About half the time it would work correctly when I'd test movie, but half the time film1i et al would come up "undefined."
Now if I open it from the finder, or view it within an html page, everything still works, but the test movie function never loads the contents of my array into the temporary variables for my theater mc.
It seems like the main problem is how it tries to resolve filmarray. Here's what happens when I click theater b in the navigation:
Movie Clip: Target="_level0.theatermc"
Variable _level0.theatermc.idx = "b"
Variable _level0.theatermc.thname = "Eastgate"
Variable _level0.theatermc.thaddress = "123 Eastgate Address, Eastgate (999) 555-1212"
Variable _level0.theatermc.filmq = "8"
Variable _level0.theatermc.filmqty = 8
Variable _level0.theatermc.filmarray = [object #4, class 'Array']
Variable _level0.theatermc.timesarray = [object #7, class 'Array']
Variable _level0.theatermc.timesbarray = undefined
Variable _level0.theatermc.film1i = undefined
Variable _level0.theatermc.film2i = undefined
Variable _level0.theatermc.film3i = undefined
So it's made filmarray into an array, when what I really want is for filmarry to stand in for the array _level0.bfilms[] and resolve to that array when I set the variables film1i, 2i etc.
So it seems to me there's some picky syntax I'm missing, which the standalone player mercifully forgives, but Flash's test movie player will not.
Are we having fun yet?
EDIT: Added [ as ] tags. - jbum
Addressing Variable Clips Inside Variable Clips - Easy Question Probably
in actionscript 1 (flash mx (not 2004))
i posted yesterday, and got an answer that solved my simpler problem with the subnav... it is related , so here is the link which should get you up to speed (thanks for bearing with me...)
http://www.flashkit.com/board/showth...hreadid=501186
now what i need to do is address a clip inside a clip and tell it to gotoAndPlay a frame. the thing is, both clips are dynamic. it is a main nav and sub navs for each choice of the main nav, where from the main nav, i need to address the correct main nav clip, and the correct sub nav clip, and tell the sub nav clip to gotoAndPlay a frame.
so if i were to hard code it, it would look like this:
clip1.subClip3.gotoAndPlay("endFade");
but clip1 and subClip3 might be clip4 and subclip6, or whatever, if you know what i mean.. they're dynamic.
i got as far as this in my attempt to solve my problem:
currentSection="clip1";// determined elsewhere
fadethis(currentSection);//called from elsewhere
function fadeThis (fadeMe) {
trace(fadeMe);//returns clip1
fm = this[fadeMe];
trace(typeof(fm) +" "+ fm);//returns movieclip _level0.clip1
}
but i couldnt find a way to get any further than that...
how can i do this? let me know also if i'm explaining this sufficiently... i am having a hard time articulating what i mean, but my fla is way too big so i am hoping someone will understand. i really think this is probably very easy, but i'm just not getting it. and if you do know the answer and do choose to help me, a brief explanation of why your way works and mine doesnt would be super awesom (if you've got the time)...
ok thanks in advance for whoever helps...
-lemur
ARRAY Element Value - Not Array Index Value
Hi all -
Have a small problem converting the below variables from PHP into a useful Ascript Array. I keep getting the value of the array index, rather than the value of the variable in question.
So I know I have 3 rows in my database (totalRows var),
and I have a incremental values for the "recordId"'s (which correspond to the record ID in the db).
totalRows = 3
recordId0 = 1
recordId1 = 5
recordId2 = 6
this is the code I am using:
Code:
function extractMenu() {
//returned vars (FYI): totalRows=3&recordId2=6&recordId1=5&recordId0=1&result=okay&
this.menuArray = new Array();
with (menuLoad) { //menuLoad is the LoadVars object holding PHP vars.
for (i=0; i<=totalRows-1; i++) {
menuArray[i] = recordId + i;
trace(menuArray[i]);
//the trace returns:
//0
//1
//2
//I was expecting the values:
//1
//5
//6
}
}
any takers?
Test If Array's Element Is An Array.
I'm recursively looking through an Array, and I'm looking for a solid way to test if an element is actually an Array(there is a chance that the tested array element is another datatype). I was thinking that I could use the length property to test, however looking in the index of ASDG2 I see that there are a few other Objects that possess the a length property, and I am afraid that this might cause a problem.
look at
nav_array[i].length >= 1
below
Is there a way to use typeof on an Array, and have it return anything other than Object?
Code:
private function recurseThroughArray(nav_array, itemsArray, depthHolder){
for(var i=0;i<nav_array.length;i++){
depthHolder.push(i);
if(nav_array[i] == itemsArray){
var returnDepth:Array = depthHolder;
break;
}else{
if(nav_array[i].length >= 1){ //make sure that this is an Array
recurseThroughArray(nav_array[i], itemsArray, depthHolder);
}else{
depthHolder.splice(depthHolder.length-1,1);
}
}
}
return returnDepth;
}
also, I'm new to recursion, and I haven't tested this yet.
Element In Array
Can anybody tell me if there is a built in array function in Actionscript which returns true if a value is an element of the array, and false otherwise, or do I have to write my own by comparing each element?
Thanks
Array Element
hi everyone,
can anyone help me?? how can i remove the first element of an array and then put him in a var??
thanks Catarina
Get Next Element In Array
Hello ,
I have dynamically created array image gallery ...when I rollover one image I want it to enlarge and shift neighbouring images aside...
What I need to know is : when I rollover particular mc with image how to list mcs with indexes lower in that array and with higher index number in that array ?
Code:
_root[myArray[i]].onRollOver = function (){
this._xscale +=10
this._yscale +=10
}
Now I need to get the mcs with lower index and higher index than that one mcs that was rolled over
Anybody ??
Thanx
Set Vars To Array Element
I need to on the first frame:
1)declare a newarray called myArray
2)with a for loop set elem0 - elem9 to = its corresponding array element
ex. elem0 = myArray[0]
so wrote the following code but it doesnt work
--------------------------------------------------------
var myArray = new Array();
for (var i = 0; i<=9; i++) {
var "elem"+i = myArray[i];
}
--------------------------------------------------------
what am i doing wrong. I know it has to do with the way im trying to dynamically create each variable
Remove Element From Array
How can I remove elements from the following array?
myArray=[0,1,2,3,"",5,6,"",8]
In my case, I'm speciffically interested in removing the empty strings "".
Thanx, Smash
Referring To The Last Element Of An Array
I want to refer to the last Element of an Array
Is there another syntax then:
existingCells[existingCells.length-1]
Like a special word:
existingCells[last]
Or something...
Delete Element From Array
Hi there
I am have loads to trouble deleting elements from an array
what I am trying to do is make a shopping cart in flash
using arrays when the user click on an item it pushing the
product variable into an array but the problem is when
the user need to delete the product from the array.
I have tried using the pop (); function but that just
Deletes the last element from the array and what I
Really need is to delete the element at relates to the
Product that the user want to delete.
Any ideas
any help on this would be GREAT
Thanks
Mac-10
Delete A Particular Element From An Array
Hi All,
I have an array of 17 elements all numbers from 1-17 stroed in it.
I am generating a random number and want that particular number to be deleted from the array
Thanks in Advance
Warm Regards
Deepak Lohumi
Remove Array Element
Does anybody know how to remove elments from an Array that have the same value. For instance i have :
myArray(1,2,3,4,undefined,undefined,undefined,8,9, 10)
How do i remove all elements that have UNDEFINED value and decrease myArray length from 10 to 7 ? Thanks
Removing An Element Of An Array
Hello everybody!
Is there a way to remove an element of an array by its name?
I can remove elements with the splice method, but it works with the index.
Thanxs in advance
Comma In An Array Element?
Hi,
I am using LoadVars to bring in array items, delimited by commas. Unfortunately it is required that some array elements include the character "," but not as a delimiter [example: "I need to add commas like this, thanks."]. We tried using the %2C escape sequence but this does not work in IE [no idea why, but it instead adds a line break], is there any other way to display a comma in an array like this? Thanks a lot for any help,
Jeremy
Programming Art
PS. I am using Flash MX
Get Random Element From Array
apologies for this easy question but I'm new to actionscript and flash!
I have an array with a list of things, and I simply want to pick out a random element from the array. How can I do this?
I was trying to solve this by having a random number, multiply by 10, then have a function to call to check whether it is greater than the count of the elements in the array, but this seems long-winded and it didn't work anyway!!!!
Thanks.
Array Element Names
Hello gurus
Stuck on what seems a simplish question and cannot find the info anywhere.
I want to call an array element by name and clear it totally from the array.
I know that if you use delete on an array, it only clears the value.
I read somewhere that if you name the elements, you can then use delete to clear the value and its container.
q1/ Does naming the elements make it an associative array?
q2/ If this is so, and I cannot use the length method, is there some other way of getting the length?
q3/ Any better ways of doing this that the way I am going about it.
Have looked at Objects and deleting but again, cant get length.
Thanks if you can help out. I am just diving in to actionscript and haven't had that AHA! moment yet.
..
cz
[Help] Deleting An Array Element
Ok I created a function to delete an element of an array which looks like:
Code:
function deleteD(index,array){
newArray =[];
if (index == 0){
}
else{
newArray = array.slice(0,index);
}
if(index >= array.length-1){
}
else{
newArray.push(array.slice(index+1,array.length));
}
return (newArray);
}
But for some reason it doesn't work properly. For example:
Code:
testArray = [['a',0],['c',1],['e',2],['g',3],['i',4]]; //an array with some random elements.
testArray = deleteD(1,testArray);//Should delete element 1: ['c',1]
trace(testArray) // traces a,0,e,2,g,3,i,4 like it should
trace(testArray.length) //traces 2, when the length should be 4
trace(testArray[1]) // traces the second element which should be ['e',2] as e,2,g,3,i,4
I attached the .fla so you could see it, and any help would be great. I've been pulling my hair out over this...
Delete An Element On Array?
Hello,
direct to the point. my problem is, i have an array and want to delete an element, lets say "my_Array[4]" from it. the thing is i can erase the variables, but that leaves an empty space en "my_Array".
how can i move all the records of "my_Array" to fill the blank space?
after i delete the element i got this (and i dont need it that way):
my_Array = [dog, cat, plane, train, undefined, house]; (this is a geek example).
please help.
Array Element Visibility
Describes the mood or content of the topic posted 03-19-06 09:27 PM
Hi, I have a script problem in Flash not sure it can be easily solved.
I am a casual Flash user and not sure if there is a easy solution to this:
I have and array of elements from which one of them is retrieve randomly, and then stored in the variable selectedElement
myElements = new Array("beerBelt", "bottleBelt", "canBelt", "chipBelt");
function randomAll() {
_global.randomNumber = Math.round(Math.random()*(myElements.length-1));
_global.selectedElement = myElements[randomNumber];
};
Inside a MC in the same scene I have a series of MCs with the instance name exactly the same names as the variable elements, they are invisible from the first frame,
beerBelt._visible = false;
bottleBelt._visible = false;
canBelt._visible = false;
chipBelt._visible = false;
then an action frame appears to make the selected MC visible,
selectedElement._visible = true;
selectedElement.gotoAndPlay(_currentframe + 1);
stop();
for any reason (my lack of knowledge sure is the one to blame) I cannot make that element visible, I tried everything I know.
Could you please advice me what is the best way to aproach this problem?
Is it really possible to use variables values (in this case strings) to modify a element property?
Am I missing something?
Please any comment would be really welcome....
Attaching MC To Element Of Array
I want to plcae a movie clip in somthing like an inventory, so it will show a movie clip of the element of the array if it is there.
-----------------------------|
|
[$] <- icon_MC [#]<-amount|
|<---(inventory screen)
|
------------------------------
Inventory [0]= gold;
and how do I set the value of that element. Say 500gold?
Array Element Exists?
How do I check if an element in an array exists?
I'm looking for something along the lines of this, but don't know the proper syntax:
ActionScript Code:
if(array[5].exists()) {
// Do something.
}
else {
// Do something else.
}
Keep Adding Element To Array
Hello,
I'm trying to extract the data out from the array and put them into a new array consisted of name, x location, and y location. Somehow I can't keep adding them, the result of the new array will show only 1 element. can somebody help please?
thanks
ActionScript Code:
function doDub1(){
var myLV:LoadVars = new LoadVars();
myLV.onData = function(src:String) {
var words = (src.split(" "));
//trace(words);
_global.wordArray = new Array();
wordArray = src.split(" ");
_global.n = wordArray.length;
trace("Output Data = ");
for (i = 0 ; i < wordArray.length ; i++){
trace(" wordArray[" + i + "] = " + wordArray[i]);
}
for (i=0; i<wordArray.length; i++) {
_global.mc = attachMovie("Word", "noun"+i, 100+i, {msg:wordArray[i], _x:mc._width*i, _y:mc._height*i});
//mc.oldname = mc._name;
//mc.oldX = mc._x;
//mc.oldY = mc._y;
//trace("mc.oldname = " + mc.oldname);
//trace("mc._x = " + mc._x);
//trace("mc._y = " + mc._y);
xLoc = getProperty ("noun"+i, _x);
yLoc = getProperty ("noun"+i, _y);
trace(xLoc);
var abc:Array = new Array()
abc.push(["noun"+i, xLoc]);
trace(abc.length);
if(wordArray[i].length > 4 && wordArray[i].length <= 9){
mc._xscale = mc._xscale * 2;
}else if(wordArray[i].length >= 10){
mc._xscale = mc._xscale * 2.3;
}else{
mc._xscale = mc._xscale;
}
}
}
myLV.load("nounsFile.txt");
tempLabel = "Nouns";
}
Delete Array Element By Value?
Is it possible to delete an array element by value rather than position?
I need to do something like:
Code:
my_array.splice("value",1);
Which doesn't work.
Is there a way to do this?
Cheers,
Jr.
Save Array Element
Is it possible to save an element of the array to a txt file? or do I have to create a new array to hold that value then save it? Please note that I only have one variable that when the mouse is over the movie clips it will show the element of array on to that variable.
Array Element Not Being Defined
Hey
It's late here and i'm tired, so it could just be that, but i can't work out why this isn't working:
ActionScript Code:
trace ("index" + index)
_root.SavedSO.data.Inventory[index][0] = getable[i];
_root.SavedSO.data.Inventory[index][1] = _root.SavedSO.data["room"+x+","+y+","+z].getinfo.split("*")[i];
trace(_root.SavedSO.data.Inventory[0][0])
index is 0, as it should be, yet the trace at the end returns undefined. However, if i remove one of the array elements it works... Does anyone know why this would be, or how to fix it?
Swapping Element In An Array
Hi all,
Can someone tell em what I'm doing wrong here? I basically want to swap the order of two elements in the array. The splice command works fine with only a single field in the array eg bob.push("aaa") but I get undefined when using multiple elements in the Array...help!?
bob = new Array()
bob.push({name:"aaa",age:1})
bob.push({name:"bbb",age:2})
bob.push({name:"ccc",age:3})
bob.push({name:"ddd",age:4})
bob.push({name:"eee",age:5})
bob.splice(1,0,bob.splice(2,1))
trace(bob[0].name) // gives aaa
trace(bob[1].name) // gives undefined
trace(bob[2].name) // gives bbb
trace(bob[3].name) // gives ddd
trace(bob[4].name) // gives eee
Position Of An Element In An Array
Hello,
Is there a method to get the position of an element in an array?
if I have an Array like this
myArray=[apple,pears,orange,banana];
when I ask for "apple" I would like to have 0 returned (its position in the array)
when I ask "banana", it will return 3
Thanks
Henri
Array And Deleted Element
Hi,
I have a Form with 6 input Text fields.
Now the Submit button should find out, if all Text fields are defined.
The Array is updated on enter text with >splice< like
var a:Number = 0;//
while(a<6){
this["formTF"+a].onChanged = function(txt){
var theText = txt.text;
var theNo:Number = this.avar;
theSubmit_array.splice(theNo,1,theText);
};
a++;
}
All works fine, I have an array like this > AA,BB,CC,DD,EE,FF <
But, when the TF is left empty or previous entered Text is deleted, lets say TF no.2, then
my Array looks like >> AA,,CC,DD,EE,FF < so… BB is gone and I have an empty space.
How can the Submit button read, that the TF no 2 is empty???
I have tried so many things during 2 days, but found no solution.
For ex. looping through the array like:
for(var x:Number=0,x<theSubmit_array.length;x++)
var checkStr = theSubmit_array[x];
if(checkStr == ""){
//play error
}
}
// but does not work.
Can anyone help me please??
Thanks.
Remove Element From Array ?
hi
How can i remove the element from array in actionscript?
i have this array:
myArray = new Array ("1","2", "3", "4", "5");
i want to remove the element "3" when i press button.
Remove Element From Array
Hello kirupers,
i am trying to remove elements form an array.
the array is kind of special: content depends on what you have clicked or not:
see some code:
pArr = [];
for(var i =0;i<max;i++){
johndoe[i].pressed = false;
johndoe[i].onPress = function(){
this.pressed = !this.pressed;
if(this.pressed){
pArr.push(this.obj)
}else{
pArr.remove(this.obj);
}
}
}
of course the remove function is my pb, not done yet.
i have tested some proto on it, but cannot figure it properly.
How can i remove the same object from the array, knowing that the array can contain several times the same object, so i do not want to delete it many times but just the good one ? so the trick is to remove only the object associated with the johndoe button.
maybe the pb comes from the way i push the elements ?
thx for your reading so far, hope this is an understanding problem.
tofu.
Deleting A Element In Array.
var my_arr:Array =['das',2,jack',4,5];
i need to delete the element by refering thier index number.....
like this my_arr.remove(3);
how can be this done....
Help-instance Name->array Element,array Element->instance Name
help. I need help!
i got a problem here, i have some movie clip on the stage, and when i click on it, it will save one variable, _global.array1=new Array("a");
a is the instance name, which other function will use this element on other button.
But when i click on other button, how it can link this element to trigger the instance?
thanks!
(i'm using Mx2004.)
Remove An Element From Array
I have created a bit of AS that attaches library images from an array 1 at a time, but i am having difficulty remove the element/images once it has been displayed from the array and stage.
output
Entry lunchbox(12)
Array No:12 was removed
Entry toydoll(20)
Array No:20 was removed
Entry newspaper(14)
Array No:14 was removed
Entry pictureframe(17)
Array No:17 was removed
Entry fork(7)
Array No:7 was removed
Entry jug(9)
Array No:9 was removed
Entry key(10)
Array No:10 was removed
Entry pan(15)
Array No:15 was removed
Entry spoon(18)
Array No:18 was removed
Entry trophy(21)
Array No:21 was removed
//should not have been deisplayed again
Entry fork(7)
Array No:7 was removed
Entry chair(3)
Array No:3 was removed
//should not have been deisplayed again
Entry fork(7)
Array No:7 was removed
been going round in circles with this.
heres my code so far
Code:
var picArray:Array = new Array();
picArray[0] = "bottle";
picArray[1] = "bucket";
picArray[2] = "carrierbag";
picArray[3] = "chair";
picArray[4] = "coat";
picArray[5] = "cushion";
picArray[6] = "envelope";
picArray[7] = "fork";
picArray[8] = "hat";
picArray[9] = "jug";
picArray[10] = "key";
picArray[11] = "kitchenroll";
picArray[12] = "lunchbox";
picArray[13] = "mirror";
picArray[14] = "newspaper";
picArray[15] = "pan";
picArray[16] = "phonebook";
picArray[17] = "pictureframe";
picArray[18] = "spoon";
picArray[19] = "toyboat";
picArray[20] = "toydoll";
picArray[21] = "trophy";
picArray[22] = "trouser";
picArray[23] = "vase";
var depths:Number = -1;
var rndNum:Number = olddepth;
function attachPic()
{
rndNum = Math.floor(Math.random() * picArray.length);
_root.blank1.attachMovie(picArray[rndNum], picArray[rndNum] + "Clip", depths++);
return ("Entry " + picArray[rndNum] + "(" + rndNum + ")");
}
trace(attachPic("picArray: ", +picArray[rndNum]));
function picRemove(toRemove:String)
{
for (var i:Number = 0; i < picArray.length; i++)
{
if (picArray[i] == toRemove)
{
_root[picArray[i] + "Clip"].removeMovieClip();
picArray.splice(i, 1);
return ("Array No:" + i + " was removed");
}
}
return ("Failed to remove an entry.");
}
trace(picRemove(picArray[rndNum]));
//trace(picArray);
How To Access This Array Element
Here's the function :
Code:
var curItem;
function disableAll(){
for (var i=0;i<buttonArray.length;i++){
trace(buttonArray[i])
}
}
Here's the problem/question :
- I want to assign the var curItem into the onRelease function throughout the buttonArray. How?
|