ActionScript 2.0 :: Remove Element From Array?
Jun 1, 2004How 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.
View 3 RepliesHow 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.
View 3 RepliesI have an array used to track shots fired from a cannon, and when they hit the ground they are removed.
I would like to know what is the most efficient way of finding and removing a certain element from an array. I heard that using pop() instead of splice() was faster, is it ?
Also, the big question I have is that the only way I see of actually finding the element in the array is using
Code:
for(i=0;i<array.length;i++){
if(array[i] == movieClipToRemove){
//i == movieClip index in the array
}
}
Then I would use either splice() or pop() to remove it from the array before deleting the MC. Is there a better way than scanning through the whole array comparing each element to the triggering MC ?
how to remove a particular element from array
View 1 RepliesI have an array of objects. Each object has a property called name. I want to efficiently remove an object with a particular name from the array. Is this the BEST way?
private function RemoveSpoke(Name:String):void {
var Temp:Array=new Array;
for each (var S:Object in Spokes) {
[Code]....
First of all, how should I remove an element from an array?Now I am using arrays this way (just an example):
array["red"] = 0xff0000;
array["black"] = 0x000000;
How do I remove "red" for example from the array?
i have items drawn my stage dynamically and information regarding them in arrays.when i remove an item from the display list:Code:a.target.graphics.clear(); then use the spliceď and index of method to locate chosen MC remove their values from specific array :Code:mcName.splice(mcName.indexOf(+mcRef.boxCount),1);Now when i remove any item which isnt the lastitem of the array, then trace all the data of the array using a loop the values appear to have corrupt? like they have lost the order in the array since one was removed?
View 21 RepliesUsing a for-loop I made a grid of movieclips. But I wanted it so every second row had one less than the one above it. I thought I had that sorted when I placed an if statement in the method. However, flash still "sees" the missing movieclip. I've tried to splice the array element from it, but instead of removing it, it seems to have copied it.
Here's the code:
Code:
package
{
import flash.display.MovieClip;
[Code]....
First of all, how should I remove an element from an array? Now I am using arrays this way (just an example):
[Code]...
I am trying to remove an element from an array by using splice like:
Code:
myArray[1].splice(2,1);
This works & finds the element I am looking for but it doesn't really remove the element but it will just insert a blank object instead. Am I doing something wrong here. How would I "really" remove the element, meaning that the Array would become shorter?
I am trying to remove elements form an array. The array is kind of special: content depends on what you have clicked or not:
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. 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?
Is there a way to generically remove an object from an array? (maybe not using array.filter or creating a new array)
Example:
var arr:Array= new Array();
//create dummy objs
for (var i:uint=0; i < 10; i++){
var someObject:SomeClassObject = new SomeClassObject();
[Code]....
Here's what I'm currently doing/trying to do to accomplish my goal. But it is not removing the "row" the way I would like it too.
So, I'm making an object, then pushing it into an array. And the adding to the array part works fine and just as I expect.
var nearProfileInfoObj:Object = new Object();
nearProfileInfoObj.type = "userInfo";
nearProfileInfoObj.dowhat = "add";
[Code].....
But this doesnt seem to be deleting the whole row like it implies.
Is it possible to, if you have an array of class names like ActionScript Code: var city01names:Array = ["pic_01", "pic_02", "pic_03" ...] make a new array which would read these names, instantiate them, and push them into a new array containing the instances of all these pictures, which I could then use for a slideshow?
[Code]...
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 fieldI 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;
[code].....
How do I remove the last element in a arrow?
I have an arrow called lagers.
When I press a button I want the last element in the arrow to be removed.
I heve tried this code, but I cant figure it out.
removeMovieClip(lagers[lagers.length]);
I have 4 buttons and an empty array. When a button is clicked,I'm adding a element to an array with array.push. However, I want to check the array 1st to see if that element exists. If so, then don't add it. Here's what I have thus far
[Code]...
Now I'm taking it I'd have a conditional statement to see if the element already exists. Unfortunatly I cannot just disable the button. I searched the AS dictionary but oddly enough it doesn't have an easy way to search an array. And IndexOf seems to only work for a string.
I am wondering how to remove a specific element from a vector.[code]...
So from the code example above I was using Element.pop() but thats wrong -I think -as it removes the LAST element. I need to remove the element at the location of the match.
I have this array:
[Code]...
I want another array which takes the values of the price from the 1st Array. Can we do something like this? private var another_price_array:Array = [all_array.price]; This second array will be used to populate a ComboBox, or can I populate the combo directly from the first array itself?
i need to split a large text file into an array at line breaks so one array element = one line.i have tried the using "" in both match() and in RegExp but it doesnt work.i had the g and m flags on. tried the $ sign too.
View 8 RepliesI know how to get one element from the array. But I don't know let's say how to take 3 elements ( position 0,1,2). I don't know how to trace all the three together. I am getting errors all the time.
var myArray:Array = [1,2,3,4,5];
trace(myArray[0]);
trace(myArray[0], ?,?);
I have an array like this
public var dataAL:Array=[
{Kiv:"cash", jan:26,janTarget:28,feb:27,febTarget:26,mar:30,marTarget:32,apr:31,aprTarget:32,may:28,mayTarget:29,jun:46,junTarget:32,jul:37,julTarget:39,aug:40,augTarget:42,sep:41,sepTarget:42,oct:48,octTarget:49,nov:40,novTarget:41,dec:38,decTarget:40},
[code]....
Now if i want to access febTarget for cash how will i do it?
How can add element to array in ActionScript3
If i have an array: var myArray:Array;
How can add element to this array "myArray", something like this:
myArray[] = value;
My second question is: How can compare if variable value exist in array element value?
Something like in_array function in php
I'm trying to make a memory like game. It might be called Simon or Simple Simon or something. Basically something is shown for a second and then gone, then the user clicks that something. Then two or three things are shown in order and then gone and the user clicks the order.
I'm stuck at the very beginning, just showing something from an array for half a second or so then stopping and then starting over and adding one more element.
This is for a small RTS prototype I'm working on for some fun, but I've hit a snag.
For examples sake, I've got two arrays, activeAgents and houseArray. A number of movieclips (player controled units/agents) are stored in activeAgents and houseArray is used to store any agent that is "inside" the house.
If an agent in activeAgents hitTests the house that houseArray belongs to and the agent ISN'T already in the houseArray, then I want to add the agent from activeAgents INTO the houseArray.[code]...
Code:
arrayA[i] = arrayB[j];
This results in:
1:[object #7, class 'Array'],
I'm would like to set arrayA[i] to the value of arrayB[j], not set arrayA[i] to the object arrayB[j].
I can't use .toString() as I'm trying to pass on an array inside an array.
I'm using the .unshift method therefore the newest values go into [0] and the rest are pushed down.
What is a good method to remove a value from an array once it has passed a certain length? For example i only want my array to hold 5 values.
Also, is there a method for clearing the entire array, ie removing all values? Or will i have to manually change all the values with a loop?
I've got an array containing various sprites... I'm wanting to reference the sprite I want by its name rather than its index in the array, and was wondering if theres a simple way of doing this? I know I could do a for loop through all the array elements and see which one has a name that is equal to the name im looking for, but is something along the lines of myArray[elementName] possible?
View 5 RepliesI am trying to provide a "URL" to the "Loader" from an array element, if I trace the element I get the URL name within "",but when I run the loader I get "URL not Found". If I declare a variable=ArrayElement I get null or undefined. The array has been populated from a simple XML file.
View 1 RepliesI'm trying to retrieve the value of an array element in a trace statement...how do I go about this? I've had a look through the AS reference manual but can't work out what should follow the dot '.'?
ActionScript Code:
trace(currentBall.name + " is in " + zone[i]./* something here to retrieve array element value */);
I have an array, created as:
ActionScript Code:
myArray:Array = new Array(10)
pretty much just saying there is 10 elements in it. I define each function as "land", for example. Then in the same function I redefine a random element as "water".
(It is a bit more complex, this is simplified!)
Upon executing this I get the error:
ActionScript Code:
TypeError: Error #1010: A term is undefined and has no properties.
if I put the second bit in a new function (the random water part), there is no problems and it executes perfectly. Obviously I cant define an element twice in the same function.