ActionScript 3.0 :: Know Position In Array From Object?
Feb 28, 2011Code:
var myArray = [];
myArray[6] = new myClass();
[code].....
Code:
var myArray = [];
myArray[6] = new myClass();
[code].....
var array1:Array = new Array();
var array2:Array = new Array();
var obj1:Object = new Object();
array1.push(obj1);
array2.push(obj1);
How can I do this what command should I use?
//obj1's position in array1
//result: 0
//obj1's position in array2
//result: 0
I put my mc's in an array.I have another array with strings.when the mc is clicked I want to get its position in the mc array and return the string from the same position in the string array.How do I do that?
PHP Code:
var numBtnArray:Array = new Array;
function addNumButtonsToStage():void{
[code].....
when i run get lastIndexof for an array I get returned the the size of the array instead of the position here is the code:[code]but instead of returning the last index of it before the current index, it returns the current index (or jus the array length). help!!! it is my first time using lastIndexOf so I am probably using it incorrectly.ps this does not include some of the function run (i know i am passing a value which it does not look like i am using, but i know that part of the code works)
View 5 RepliesI'm trying to trace the path of an object by using setPixel on the object's position every frame in a BitmapData/Bitmap pairing. These pixels aren't showing up normally and I suspect I have a fundamental misunderstanding of the BitmapData class. Here's what I'm doing:
public var contrailBase:BitmapData;
public var contrail:Bitmap;
private var contrailColor:uint;[code].....
Using this code, the red pixels don't show up. If I initialize contrailBase to 0xFF000000 instead then I get a black screen on which the red pixels DO draw, but I need the bitmap to be transparent except for the contrail. What am I doing wrong?
I'm stuck thinking about the best way to go about setting a line segment's position, I have a class Line(length, angle, previous) being called from a class Polygon. Right now I have:
public class Line extends Sprite {
public function Line(length:Number, angle:Number, previous:Line = null) {
if (previous != null) {
this.x = previous.end.x;
[Code].....
I am curious if this is an okay implementation of the Array.filter() method.
[Code]...
I was not able to figure out an implementation of the callback function for the filter() method, where the callback was outside of the getGallery() function. I wonder if there is a way to get the isGallery function outside of the getGallery scope?
I have been trying for an hour to clone an array, It seems that nobody has a true reference on how to do it. Two arrays - movieClipArray 1 and movieClipArray2 I want to duplicate movieClipArray1 entirely so that when I addChild(movieClipArray2[0]), it doesn't take away from movieClipArray1 or reference it in any way.
[Code]...
I am trying to use the following code to convert an object read in from a ByteArray to an Array and store it:
var data:Object = ba.readObject();
var invObjects:Array = data as Array;
In debugging, I find that 'data' is indeed populated with the correct data and takes up memory and is in an Array friendly format. However, invObjects is NULL. How does merely saying 'data as Array' make the holding variable suddenly null?
How can I use the data in an array at position 0 as a piece of information in a gotoAndPlay command?
myMovieClip.myArray[0].gotoAndPlay("labelName");
Actual Code:
var myMenuArray = [home, about]; //1 button duplicated with instance names to reflect
for each (var btn in myMenuArray){
btn.addEventListener(MouseEvent.CLICK, onBtnClick);
} var detectArray:Array = new Array();
function onBtnClick (event:MouseEvent):void{
transition.visible= true;
[Code] .....
Okay, what I want is kinda hard to explain, so bear with me.If I have an array:Code:myPets = ["cat", "dog", "bird", "fish"];Now, is there any AS that can use the value of say "dog", and return the position that "dog" is in the array, I know this seems a bit stupid and dog is obviously myPets[1], but when I'm creating arrays on the fly it becomes slightly harder.
View 3 RepliesI have two arrays thumbs and images, both the thumb and image are added to the same index in their arrays, so thumb[0] is the thumb of image[0]but what I need to do is get the index position of the clicked item, how do i do this?
new_carousel_item.addEventListener(MouseEvent.CLIC K, getValue);
new_carousel_item.buttonMode = true;
thumbs.push(new_carousel_item);
[code].....
Is it possible to call a function to tell me if a var string is in my array. And if so, what position it is in?I pictured it to look something a little like this:
Code:
var pages:Array=['index','services','about','testimonials','contact'];
var pageName:String;
pageName="services";
[code]....
i have an array and want to access the position of the array and replace by anothernumber,how i wan do it.
var cardlist:Array = new Array();
for(var i:uint=0;i<16/2;i++) {
cardlist.push(i);
[code]....
I notice that about 4 times through out, who ever coded it used letters in addition to numbers in an arrays position.
Code:
risksArray["r"+element.@riskCode] = whatever;
but throughout the whole thing, he always refers to the array positions the same way.. so I can't figure out why he would possibly just add an r to the beginning like that.How does that work? Why would someone do it?
1. let's say I have an array full of mcs, is there a fast way of knowing the position of mc_b in that array without looping through it every time?
2. also, is there a fast way of swapping the position of two elements in an array without splitting it and re-sticking the parts?
figure out how I can get the position of a string inside an array.For instance,myArray["hello", "goodbye", "sayonara"];myString = "goodbye";Whats the simplest way to get the index in myArray that myString occupies (ie. 1)? Something like the string-method indexOf() but for arrays
View 10 RepliesI found the tutorial about getting the index of something in an array, but i need the same for a twodimensional array, so i get [0][1] for example. How do i alter this code to do so?
Code:
Array.prototype.getIndex = function(data) {
for (i=0; f=0; i<this.length; ++i; ) {
if (this[i] == data) {
[Code]....
I created an array in the var declarations with Code: var private eDrag:Array In a function that adds imported mcs to the stage, I also added code to push each to the array. Here is an example of a block of code loading the object with the part pushing the object to the array at the end:
[Code]....
I'm working with a web service and am returning an array to a field (that I set the data type as an Array). The result thus far is "[object Object]". How can I get the array values back out as a string?
View 0 RepliesI have an xml say in following format
[Code].....
What I should do is parse an xml and from its node name create object property and then create an object array based on those property. Am I able to make myself clear.
way to position an array containing movie clips relative to the stage? Here's what I was trying...
import flash.display.MovieClip;
var one:MovieClip = new One();
addChild(one);
[code].....
I want to access a paricular array item regardless of position useranswers.splice(indexOf("ans2",1) This dosent work but basically i want to use indexOf and then splice that item?
View 1 RepliesSo I've got a button that spawns a block and when pressed spawns another to the right of that block, if pressed again the process repeats. These blocks are all placed into an Array. When the user click on the blocks, they are removed.I would like the blocks to track their position in the Array so I can splice out the value on click and all the other "building spots" will move to their Array position * building spot width, so when a block is cut out, the others all move a long and remove that space.Since Arrays aren't my strong point, I wish to see what you think would be the best option here. Now keep in mind I am not a Flash Pro, so the way I have coded may not be the best, but I like to think I try Here is the code currently:
ActionScript Code:
onClipEvent(load){
}
[code]......
i have this array with positions:
[Code]...
let each movieclip go to it's original position out of the array?
I have a combobox that displays a list of items from an array (we'll call this Array1). Of course, an item can be selected, and the user is displayed a small output describing the item that was selected.
I created another array that contains the URL for items in the above array, Array1. How can I get the index value of a selected item from Array1? Here is the code I used:
[Code]...
For example, if I selecte FontsForFlash, Flash outputs Fonts for Flash in the Output Window. How can I display the array position of Fonts for Flash instead of the name Fonts for Flash?
how do you find out in which position a certain value is in an array?
View 9 RepliesI've creating a drag and drop card game in AS 2.0 and need to set the cards randomly in set positions every time the game is played. no two cards can be in the same space, so the taken position needs to be taken out of the array.I am not concerned about the Y value just X . I think this needs to be an array containing the positions. then using slice to remove the value from the array. I'm not sure how to assigned the array position to the movie clip.
View 6 RepliesI am creating a container. When I press a button outside the container it adds a movieclip. The movieclip is the width of the container but only a fraction of the height.
I need to know how to get it so every time I press the button it adds the movieclip after the last one, almost like appending a list. Does anyone know how I would do this?Do I use an array or does flash have some sort of table feature?
I did this to dynamcy create a instance of a MovieClip whenever my downKey boolean variable was true
PHP Code:
[code]...
works fine, but now I would like to update the position of the MovieClips every frame, I understand that it should be in my enter frame function but I dont understand how to access the MovieClips.