Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Finding Out If An Object Is An Array



I've been looking through my Actionscript 2 dictionary but cannot find any way of discovering if an item is an array or not. I used to use an edited array prototype and used the property isArray but I don't think you can edit the array prototype like that in flash 7.

I thought if typeof(arrayName) = object and arrayName.length isNumeric I could assume that it was an array. Is there anything else that could be an object with a length property (other than object created by me).

Are there any better ways of determining if an array is an array.



FlashKit > Flash Help > Flash ActionScript
Posted on: 03-09-2004, 06:52 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Changing An Array Result From An Array Object To A MovieClip Object
Anyone know how I can do this?


I have 3 arrays.


Quote:




//set info into arrays
wpInstName = new Array();
for(i=0; i<_global.wpCount; i++); {
wpInstName[i] = _global.newWP;
trace(wpInstName.join(" + "));
}
wpPositionX = new Array();
for (i=0;i<_global.wpCount;i++); {
wpPositionX[i] = _global.wpXpos;
trace(wpPositionX.join(" + "));
}
wpPositionY = new Array();
for (i=0;i<_global.wpCount;i++); {
wpPositionY[i] = _global.wpYpos;
trace(wpPositionY.join(" + "));
}




I need to use the current value of wpInstName[i] to change the _x and _y properties of an attached movie clip.

I have tried allsorts but it still treats the data as an Array object.
I have tried making a new Object and gave it the wpInstName[i] as a value to add properties too but im not sure if I did it right(it didnt work so I guess not ).

If anyone could help it would be greatly appreciated

Thnx

Finding Object
Hi,
In the class MainMenu.as I create a button.
In .fla I create a sprite and add a textfield to it. Both displays correctly on stage. When I click myButton that I created in MainMenu.as, I get error when I try to get the number of children in mySprite. The errormessage is: 1120: Access of undefined property mySprite. What am I doing wrong?

.fla

HTML Code:
import flash.events.*;
import flash.display.Sprite;

var mySprite:Sprite=new Sprite();
addChild(mySprite);
var myTextField:TextField=new TextField();
myTextField.border=true;
mySprite.addChild(myTextField);
myTextField.x=200;
var mainMenu:MainMenu=new MainMenu();
addChild(mainMenu);

MainMenu.as

HTML Code:
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.controls.Button;
public class MainMenu extends Sprite {
public var myButton:Button=new Button ;
public function MainMenu() {
myButton=new Button ;
addChild(myButton);
myButton.addEventListener(MouseEvent.CLICK,myButtonF);
function myButtonF(e:MouseEvent):void {
trace("myButton "+mySprite.numChildren);
}
}
}
}

Finding Parent Object
I have a custom object called module. Within module is an array called mod_lo. Each element in mod_lo is a new lo_object.

This is an over-simplified version, but for example:

code:

_global.module = new function() {
this.mod_number = 0;
this.mod_name = "module 1";
this.mod_lo = new Array();
for(i=0;i<4;i++) {
this.mod_lo[i] = new lo(i);
}
}

_global.lo = new function(lonum) {
this.lo_number = lonum;
this.loname = "some name"
}



Now I have a MC that's has lo as a prototype, and is created with attachMovie, with the initObject being a specific lo.

Is there a way to detect the mod_number of the module that the lo is in?

Finding Path Of Object
Hi,

Let's say i got this piece of coded within some nested functions


Code:
var loadListener:Object = new Object();
How do i go about finding the path to that object (e.g. in the form _level0.something.something)?

Thanks!

Finding Object Edges
I'm trying to figure out how to find the edges of a display object when the registration point is NOT at 0,0 or centered.

Normally to find the edges if the registration is at 0,0 you would do this:


Code:
var leftEdge = mySprite.x;
var rightEdge = mySprite.x + mySprite.width;
or if centered:


Code:
var leftEdge = mySprite.x - (mySprite.width/2);
var rightEdge = mySprite.x + (mySprite.width/2);
I need to be able to find the left and right edges of a display object when the registration is in a irregular position.

Finding The Coordinates Of An Object
How do you find the coordinates of an object?

I have a movie 1000 pixels tall. I have to drag the movie in order to see the items at the bottom. SO the objects within the movie are going to be moving around depending on what the user is looking at. How do I tell the coordinates of something that is moving around? It might be a clip, a text box, a button. Specifically, I am trying to figure out if a text field that is out of view has been tabbed to so I can pan the movie so that it is in view.

I have tried globalToLocal, localToGlobal, getBounds and they give me the same coordinates no matter where I have scrolled the movie to. Damn, what am I not understanding?

Finding The X,y Of An Object On Screen
The current .x and .y is local to its parent, I tried to work my way back by adding this.parent.x to its this.x to find the global .x and .y

But this seems to be not working... anyone can help me a bit on this? I need the x,y coordinates on screen of the object...

AH... okie...

My mistake was I created a canvas by drawRect(pos_x, pos_y....)
When I should have drawn with 0,0 and then manually set the .x and .y of that canvas... To me this is counter initiative..

Finding The Class Of An Object
Say I have an object, e, which is an instance of some class. How can I find out which class e instantiates from?

Finding An Object's Class Name
Hi, guys.

Is it possible to get the name of an object's class?

I know you can check to see if an object is an instance of a class...


ActionScript Code:
if( fooObject instanceof ClassName )

...but it would be very handy to be able to pull the class name from the object...


ActionScript Code:
var className:String = someMagicMethod(fooObject);

Any ideas?

I could manually add the class name to the actual class as a static property I guess, but that would be a last resort.

Help: Finding MCs Inside An Array
I'm creating a game that needs to find certain portions of a box for different things to occur. There is an array of boxes being created from a clip loaded outside the viewing area.
This is what I currently have:

PHP Code:



if (_root.ball, hitTest(_root.box.bottom)) {
        yspeed *= -1;
    }
    if (_root.ball, hitTest(_root.box.top)) {
        yspeed *= -1;
    }
    if (_root.ball, hitTest(_root.box.left)) {
        xspeed *= -1;
    }
    if (_root.ball, hitTest(_root.box.right)) {
        xspeed *= -1;
    }




I was thinking something like this:


PHP Code:



if (_root.ball, hitTest(("box+i").bottom)) {
        yspeed *= -1;
        removeMovieClip(i);
    }
    if (_root.ball, hitTest(("box+i").top)) {
        yspeed *= -1;
        removeMovieClip(i);
    }
    if (_root.ball, hitTest(("box+i").left)) {
        xspeed *= -1;
        removeMovieClip(i);
    }
    if (_root.ball, hitTest(("box+i").right)) {
        xspeed *= -1;
        removeMovieClip(i);
    }




I need the hit object to be removed from the stage, but allow the other arrays to stay.

Thank you very much in advance for your help.
Strider-

Finding An Index In An MC Array
FP v. 7. AS v. 2.0
_____________________

I have 10 MCs called "button0", "button1", "button2", etc. inside an MC called buttonsHolder.

I can access each "button" mc this way:

_root.buttonsHolder["button" + index]

This is what I have inside each "button" MC:

on (release) {
_root.buttonPanel[this].gotoAndStop("on");
}

I know I can find out button's number by using substring() on "this", but is there another way to find out the index of "this" inside buttonPanel? I couldn't find any methods or properties for that.

Any ideas?

Finding The Array Position Of A Value
I have defined an array as follows:

listRA[0] = "first";
listRA[1] = "second";
listRA[2] = "third";

daValue = "second";

Is there any way to determine which member of listRA == daValue? Or do I have to search it out with a For loop?

I haven't found anything else, and I know other languages have functions to discover the value.

Thanks,
Paul

Finding Any Value In Array (not IndexOf)
Hi everyone,
I am wondering if Flash has a built in way of finding if a value in an array exists. IndexOf only works with string values, but I couldn't find any function that tries to find a value of any data type in an array.

If there isn't one, I will just end up using this:
ActionScript Code:
contains = function (array, input) {for (i=0; i<array.length; i++) {if (array[i] == input) {return 1;}}};

I am trying not to use my own functions for things that Flash already has built-in, so I just want to double check with you all in case I missed something

Thanks!
Kirupa

Finding The Mode Of An Array
I have a simple array and I want to find the most common element in the array, i.e. the mode statistically

Can anyone help?

This is what I have so far,

var answers = ["c","b","c","a","b","c","a","b"];
var aTotal = 0;
var bTotal = 0;
var cTotal = 0;
for (i=0; i<=answers.length; i++) {
switch (answers[i]) {
case "a" :
aTotal++;
break;
case "b" :
bTotal++;
break;
case "c" :
cTotal++;
break;
default :
doNothing();
}
}

stop();

Finding Out What Object Attached A MovieClip?
The situation is as follows.

An custom class A extends MovieClip. This custom class used attachMovie to attach a MovieClip from the library to the stage. The movieClip in the library has a custom class B linked to it. It also has a close button .

How can I now delegate a close-button click event to the object A from Object B. I can not pass a reference to the Object B in the attachMovie() function.

Why can this.removeMovieClip() not be used inside B? It has no effect.
How can I get rif of B now?

Finding The Postion Of An Element In An Array?
Hello,

I have an array: A,b,c,d,e,f

When the user types in a text filed: B I want to find the postion for ex. A = 0 b=1 c=2

Any help please.

THanks

Finding The Index Number In An Array
Hi there - not sure if this is a tricky one, but hopefully someone can help.

I have an array with a list of ten scores in. I have an object called "details" with a variable attached called "score". I know that details.score is in the array because I just put it in there and had the array sorted using .sort) with a function in the braces to sort numerically rather than by ascii.

Now I want to find out the index number of that score. The reason is that details also has another variable, Name. I also have another array with a list of names in of Top Ten scorers. If a player gets a top ten score, his/her score is put into the score array and sorted. So now I have to find out the position of the new score so that the players name is placed in the same index in Top Ten scorers array.

The reason for all this is that I have a Score board screen where the two arrays are looped through with a For and obviously the two, score and name, have to match.

Now I know I am probably doing this inefficiently and yes I will be exploring later better methods to handle this, but I am new in the area of multiple arrays; so any help would be gratefully received!

cheers

frank

Finding The Keys To An Associative Array
In an associative array is it possible to "read" what the keys/labels are?

If i have an array like:

var sample_array:Array=[
{Dog: "Old Yeller", Age: 9, GoodDog:"true"},
{Dog: "Spot", Age: 3, GoodDog:"false"},
{Dog: "Barney", Age: 5, GoodDog:"true"}
]

Is there a way to determine what the first key is?
(in this case: "Dog")

Is there a way to determine how many keys there are?
(in this case: 3)

Trouble Finding An Index Of An Array
Hi all,
I have posted this on the adobe forum and have got closer and closer to making this work.
I have parsed data from a CSV file and got it into an array. However when I try and find an index of an array, I am getting an undefined returned.

Code:
stop();
Array.prototype.findPos = function(value) {
var tAr = [];
for (var i = 0; i<this.length; i++) {
if (this[i] == value) {
tAr[tAr.length] = i;
}
}
return (tAr.length>0) ? tAr : false;
};
myVars = new LoadVars();
myVars.load("members.csv");
myVars.onData = parseCSV;
var TonyData = [];
function parseCSV(raw) {
var delim = (raw.indexOf("
") > -1) ? "
" : (raw.indexOf("
") > -1) ? "
" : "
";
var temp = raw.split(delim);
var fields = temp.shift().split(",");
for(var i=0;i<temp.length;i++) {
var row = temp[i].split(",");
if(row.length != fields.length) continue;
var tmpObj = {};
for(var j=0;j<row.length;j++) {
tmpObj[fields[j]] = row[j];
}
TonyData.push(tmpObj);
}
TonyData.onData
trace("Data Has Loaded");
trace("33's trace is..." + TonyData[33].Name_First + " " + TonyData[33].Name);
trace("10's trace is..." + TonyData[10].Name_First+" "+TonyData[10].Name);
var finder
//This finder value actually works, but introducing findPos causes it to fail finder = TonyData[10].ID;
finder = TonyData[10].ID.findPos(42703);
trace(finder);
if (!finder) {
trace("not found");
} else {
trace("The Array Index relating to the Membernum is: " + finder);
}
gotoandstop(2);
};
The annoying thing is that I can trace TonyData[10].ID but TonyData[10].ID.findPos returns undefined. I have also tried getIndex as well with the same results.
Does anyone have any experience in getting an index of a CSV parsed array, or can anyone see any holes in this code?
Any help would be greatly appreciated.
Regards,
Tony

Finding Adjacent Values In A 2d Array.
So i have a tile game that uses a 2d array to store all the tiles. So i can refer to them as tileAr[0][0] and i have a number for a range say 4. So i need to get the tileAr[y][x] all tiles adjacent upto 4 tiles away from the original.

I guess theres a fancy for loop or something that can do it but i can't figure it out

So can anyone help me please???

Finding The Position Of An Array Index
i was wondering if you have an array value, can you find what number it is in the array's order. For example,

letters=new Array("a","b","c","d");
cnumber=letters.position["c"]
trace(cnumber);

so that cnumber=2. How would I go about doing something like this?

-Brendan

Finding Index Of Array Item
I'm working in AS2 and have created an array of movie clips (symbol_box[n]) with n ranging from 0 to 24. I want to be able to return the index of a movie clip (symbol_box[n]) when it is clicked so I can use it to access another movie clip in a second array. I need to be able to get the value of n... i.e. the index of the clicked clip. Any ideas? I'm sure it is simple!

Finding Values In An Array Tutorial
Hi all,
Firstly im new to strings/arrays and dont erally get the difference, forgive me if i sound silly

i was looking at the tutorial Finding Values in an Array here
and was wondering if i could replace
Code:
dataValues = [10,9,8,7,6,5,4,3,2];
with a string value thats is read from a text box eg,
Code:
dataValues = [myStringValue];
. myStringValue holds
Code:
"1,2,3,4,5,6,7"
and only finds it if i type in the full value, how do i get it to find each value seperatley after each comma? Everytime i try that it doesnt work correctly.

Could someone please help me out
Thanks

Finding Out Position Of Elements In An Array?
Hi,
a short question, how do you find out in which position a certain value is in an array?

thanks in advance,
polar

Finding POSITION In Array - Not Just Boolean
I'm trying to find the possition of an elemtent within an array.

I'm currently work around this. It a button attatched in relation to the amount of items in an xml file:

this.onRelease = function() {

for (var k=0; k<array_length; k++){

checkARRAY = (_root.Nav_array[k])

//search through the array and get the possition of the currently clicked item

if(checkARRAY=this){

number_in_array.text = k

}else {

trace("not found")

}
}
}

What i'm trying to do is tell find the position of the currently selected item in the array so i can move the _y value of the items infront of it. Its a menu - all the other items would move down once i clicked the top item. I'm trying to make it all dynamic [from XML] so i can't refer to the items in the array without looping through it [i think].

If anyones got any ideas - it would be awesome!!

Finding The Most Frequently Occuring Element In A Array
How can I find the most frequently occuring element in an array of numbers?
I'm lost on this one.

Finding Maximum-Minimum Value In An Array (by Kirupa)
I'm using FlashMX, and my english isn't quiet good but I hope someone will help me.
I seek to take advantage of this good tutorial to extract the values
minimum and maximum of a series of dates that an user can select
pressing buttons in a calendar.

Each button of the calendar takes associate a variable that corresponds
to the ordinal number starting from 1 up to 201 (e.g.dn1=1 until dn201=201).

The selected values are used to build an array declared this way
myArray = new Array(dn1, dn2, dn3, dn4,....................., dn201);
Initially, before the user intervention, the values of all the variables
(dn1, dn2, dn3, dn4,....................., dn201) they have been
declared as 0 (zero), so that the new array looks like (0, 0, 0, 0,......., 0).

When the user finishes the selection of dates is requested to confirm
by means of another button that updates the array substituting the zero
initials for the values settled down by each of the pressed buttons.
Then the updated array continues containing even many zeros and therefore the minimum value obtained is 0.

I would like to know if some function or prototype is able to delete
the elements of the array whose value is 0. I have tried to make it with
the below function but the result that I obtain it's not the one that I seek
then it also delete the zeros in other elements of the array as 10, 101, 110, etc.
Array.prototype.findAndRemove = function(toRemove) {
var s = this.toString()+",";
var t = s.split(toRemove+",");
var u = t.join("");
u = u.substr(0, u.length -1);
var v = u.split(",");
return v;
};
myArray = new Array(0, 0, 0, 0, 9, 10, 11, 12, 13, 14, 15, 16, 17);
myArray = myArray.findAndRemove(0);

Finding Numerical Position Of Items In An Array
What i want to do is to populate a text field with the numerical position of an item in an array. Here's what I've got so far:

an array- call it bArray - which holds references to three button mc's:
ActionScript Code:
bArray=new Array[btn1, btn2, btn3]



Then I have a for loop which feeds a variable that numbers each button, and includes rollOver and rollOff functions:
ActionScript Code:
for(var i=0; i<bArray.length; i++){
pos=i+1;
//numberText is a text field in the btn movie clip.
bArray[i].numberText.text=pos;
[i]//bPos=bArray
bArray[i].onRollOver=rollOverButton;
bArray[i].onRollOut=rollOutButton;
}



Okay, not a problem. But now what I want is this- when you click a button, a text field in another movie clip displays the number of the button just clicked. And I can't figure out how to derive that value from the array.

Anyone have any helpful clues?

Recording Characters In An Array And Finding Values About Them
hi, this is about strings and making a very simple search in dynamic text to find characters range and etc.

var letters:String = dinamik_txt.text;
var record:Array=new Array();
//making all characters an element of our array
//spaces are not taken as an element of our array, so we only take account the characters
for (i=0; i<letters.length; i++) {
if(letters.charAt(i)!==" ")
{
record[i] = letters.charAt(i);
trace(record[i]);
}else
{trace("there is space here");
}
}
//making search for character which we want to find, you can change "e"
//you can also make user enter the characters that s/he wants to find, with a dynamic text box and button
for (a=0; a<letters.length; a++) {
if (record[a] == "e") {
trace(a+1 + ".character: e");
}
}

I wish you good work...

Finding Smallest / Largest Values In An Array
Howdy!

I am trying to parse through an array and return the min / max numbers and although my method works it only works if there are values above & below my preset test var.

EX:


ActionScript Code:
sn = [
     [50, 950],
     [-300, 1075],
     [400, 1200],
     [150, 1150],
     [-250, 750]
     ];
 
    this.maxWidth = 0;
    this.minWidth = 0;
    this.maxHeight = 1000;
    this.minHeight = 1000;
    with (this) {
        for (i = 0; i < sn.length; i++) {
            // find our maxWidth value
            if (sn[i][0] > maxWidth) {
                maxWidth = sn[i][0];
            }
            // find our minWidth value
            if (sn[i][0] < minWidth) {
                minWidth = sn[i][0];
            }
            // find our maxHeight value
            if (sn[i][1] > maxHeight) {
                maxHeight = sn[i][1];
            }
            // find our minHeight value
            if (sn[i][1] < minHeight) {
                minHeight = sn[i][1];
            }
        }


As you can see if my values in the array are all higher or lower than my initial var values it botches the output. Any help?

Thanks in advance.

Finding Variables In Movie Clip Array
So I have a number of movie clips on the stage, each of which declares the variable "tagNum" on load. Each movie clip has a different value for "tagNum".
Example:

Code:
onClipEvent (load) {
this.tagNum = 3;
}
Here's what I want to do. As part of my script, I want to cycle through all the clips, and determine the value of "tagNum" for each clip. Thing is, I can't figure out how do this this.

When I tried this...
Code:
for (var i in this) {
if (typeof (this[i]) == "movieclip") {
trace(this[i].tagNum);
}
}
I keep getting "undefined" returned.

Could someone please tell me what I'm doing wrong and how I can fix it?

Problem Finding Class When Access To Global Object Added
Hi there,

Okay, bit odd this. Everything's working fine, then I add a line into one of my classes to access a global object that's in another SWF that loads the one I'm working on. When I do this Flash decides it can't find one of the class files it was seeing fine before.

e.g.

someClass.as is imported in anotherClass.as

I add the line "somevariable=globalObject.getSomeValue;" to someClass.as and it starts throwing up errors saying "**Warning** C:pathanother_class.as: Line 191: There is no class or package with the name 'foo.bar' found in package 'foo'."

The package foo definately contains a class bar.

Anyone come accross something like this before?

Web Service Param Is An Object Inside And Array Which Is An Object
Howdy. This is my first time on this forum, and I hope I get more help here than some of the other forums. I'll try to explain my dillema as simply as possible.

I have a webservice. I am calling a method 'InsertSlide'. That method requires and object as the paramater.
the object shcema looks like this:

Object
-SlideID (integer)
-Name (integer)
-SlideTypeID (integer)
-Hits (integer)
-LocationID (integer)
-SwfFileName (integer)
-SlideDataCollection (Array)
- -N (Object)
- - -Label
- - -Value

I hope that makes sense, all I'm trying to get at, is there is an object with an array as a property, that array is populated with an object and it has properties.

I recieve that same ojbect from the webservice fine, but when I send that object like that to the Webservice it does not fully populate my databases, unfortunatly I did not write the webservice.

Is it possible that the problem is the webservice? or flash?

Thanks for any help!
- Kiwi

"Finding Maximum/Minimum Value In An Array" Article Question
Today I needed to get the maximum value(s) of an array and was wondering the best method to approach this.

After researching the topic a bit more I was wondering why Kirupa uses a loop to return this value when you can simply use Array.sort and slice out the last (or first if reversed) elements.

For all of you out there looking to do this not only for the max value but the top values (as many as you like until the end of the array) here is a simpler method:


Code:
var values = ['2', '4', '4', '1', '3'];
var count = 3;

values.sort( Array.NUMERIC | Array.DESCENDING );
values = values.slice(0, count);
trace('Top ' + count + ' Values: ' + values);
http://www.kirupa.com/developer/acti...ay_max_min.htm

Julian

Finding The "coords" (x,y) Position Of An Item In A Multidimensional Array
Is there a relatively easy way of finding the x,y position of an item in a multidimensional grid array?

I have this grid structure for drawing a map for a game. Number 2 is going to be the starting point of the player. How would i find the x,y position of that number in the array?

It's currently at 2,2 within the array.. but i want it to be dynamic.


ActionScript Code:
map[0]  = new Array(1,1,1,1,1,1,1,1,1,1)    map[1]  = new Array(1,0,0,0,0,1,0,0,0,1)    map[2]  = new Array(1,0,2,0,1,0,0,0,1,1)    map[3]  = new Array(1,0,0,1,1,1,0,1,1,1)    map[4]  = new Array(1,0,0,0,1,0,0,0,1,1)    map[5]  = new Array(1,0,0,0,0,0,0,0,0,1)    map[6]  = new Array(1,1,1,1,0,1,1,1,1,1)    map[7]  = new Array(1,0,0,0,0,0,0,0,0,1)    map[8]  = new Array(1,0,0,0,0,0,0,0,0,1)    map[9]  = new Array(1,1,1,1,1,1,1,1,0,1)


This is the code i have to draw the map.


ActionScript Code:
function drawIt(theMap) {    var pos = 0;    diameter = 72;    xOffset = 20;    yOffset = 15;    for (var y = 0; y<diameter; y++) {        for (var x = 0; x<diameter; x++) {            pos = x+(y*diameter);            if (theMap[y][x] == 0) {                _root.attachMovie("myTile2", "tile_"+pos, pos, {_x:x*diameter+xOffset, _y:y*diameter+yOffset});            } else if (theMap[y][x] == 1) {                _root.attachMovie("myTile", "tile_"+pos, pos, {_x:x*diameter+xOffset, _y:y*diameter+yOffset});            } else if (theMap[y][x] == 2) {                _root.attachMovie("sprite", "sprite", 2, {_x:x*diameter+xOffset+35, _y:y*diameter+yOffset+35});            }        }    }}

About The "Finding Values In An Array" Tutorial
I just read the tutorial "Finding Values in an Array". Sure, the code works, but that's only because we are searching arrays the contain a small number of elements.

Suppose we have n elements in an array. To search that array for a particular element we may have to do n comparisons.

If the array we are searching contains 10 million elements, we have a problem; can you imagine doing "if (this == that)" 10 million times?

There's got to be a better way to search the array. Or perhaps we shouldn't use arrays to store the information.

Anybody has any ideas?

Array Object
Does anyone know how many elements can an array contain???

I tried adding 14 elements but it only display until the 6th.

Here's what i wrote:

steps = new Array();

steps.push({one:"left", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});

steps.push({one:"right", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});
steps.push({one:"", two:""});

[F8] Array Vs Object
Heita,

I sometimes build programme frameworks that run from xmls. The client is then given an xml gui to structure the content of the programme himself and also for routine maintance.
I found that whenever I work with XMLs I store segment attributes in multiple arrays for easier referal.
eg.code: function getItemData (thePassedSeg:XMLNode):Array {
myItemArray[0] = thePassedSeg.childNodes[_global.currentNumber].attributes.importType;
myItemArray[1] = thePassedSeg.childNodes[_global.currentNumber].attributes.theFilePath;
myItemArray[2] = thePassedSeg.childNodes[_global.currentNumber].attributes.videoPath;
myItemArray[3] = thePassedSeg.childNodes[_global.currentNumber].attributes.id;
myItemArray[4] = thePassedSeg.childNodes[_global.currentNumber].attributes.musicType;
return myItemArray;
}

Many of these arrays are then stored and used as reference.

Question: Is it wise to store these attributes in the way I have, or should I rather use objects as in...
myItemObj.importType= thePassedSeg.childNodes[_global.currentNumber].attributes.importType

Ta.

Add New Object To My Array?
i need help to add new MovieClip to my array any one need to help send to me smartic@gmail.com & the file is attached to solve my problem

Object And Array
Hi,

What is the different between object and Array.

Using Object/array As A Map
Adobe recommend you don't use an Array as a map collection, since it breaks much of the built-in functionality. They actually recommend you use a simple Object instead.

This works quite well, but what about when you have a map and you want to iterate over all the keys/values? I could write a Map class which uses both an Object and Array internally I guess...

Array Object
in as2 there was 'eval' ,, as in:

var buttons:Array = new Array("bananas", "oranges", "apples", "kiwis");
for (i=0; i<buttons.length; i++)
{
z = buttons[i];
eval(z)._alpha = 0;
}


how do you reference arrays as objects in as3?

Object Array Help Please
Alright. With the help of Supra long ago, I got this project started. However, upon revamping it, I can't get it to work. That's where you come in.
<


<dl><dt>What you need to know:

<dd><li>This is a program I'm developing for a closet shelving company, which is supposed to let the user go in, add the shelves to a particular job, print out a "cut sheet" to give to the shelf cutter, and print out an invoice for the job that was created. To view more information about the beginnings of this program, view an old post <b><a href="http://www.kirupaforum.com/showthread.php?s=&threadid=1187" target="_blank">here</a></b>.

<li>I got the program working, added a ton of stuff to it, but then realized that it was terribly arranged and coded. Therefore, I recently decided to rip it apart and make it better. In doing so, however, I messed up some functionality that I can't seem to get back.

<li>Prior to having multiple scenes, I had just one scene, "job." I thought this was incredibly unorganized, so I wanted to separate each different frame of the program into separate scenes. You will still see the original frames in the "job" scene, which I just copied over to the new scenes. And just so you know, the code in the new scenes is indeed different, and the code from the original "job" scene may not be the original working code either. I can't remember what I changed in that.

<dt>The problem:

<dd><li>What the user should be able to do is this:
. In the "shelfmanager" scene
. Type in the room, length of the shelf, style, etc.
. Click Add (or hit enter) to add the current shelf to an object array called shelfList
. The array will be viewed in the big corresponding textbox

<li>For some reason, the data being entered is not getting stored into the object array. And I have no idea why. Everything looks good to me, but it's just not working.

<li>The main code to look at is that which is attached to the "Add" button, and in the keyframe on the "actions" layer.</dl>


Here is a link to the FLA: <b><a href="http://www.fallingforautumn.net/other/pictures/shelfmaker.fla">shelfmaker.fla</a></b> (approx. 600k)


I would greatly appreciate any help I can get with this. All you guys are awesome, and I don't think you get enough credit for all the help that is given out here. And once I become somewhat decent enough, I'll return the favor and help others too.


Once again thanks in advance,
Matt

Object And Array
hi,

could anyone tell me what the differance between an object and an array is??


cheers,
G

XML And Array Object
I'm reading "track" xml nodes. When the search string is found in trackTitle value, the album properties are added to the album object and then the album object to the object array.

Here is the "as" function:


Code:
function getAlbumByQryTrack(qryTrack:String):Array{
var totalTracks;
for(i=0;i<totalAlbums;i++){

nodAlbum = tocXML.firstChild.childNodes[i];
totalTracks = nodAlbum.childNodes.length;

for(j=0;j<totalTracks;j++){

currentTrackName = nodAlbum.childNodes[j].attributes["title"];

if(currentTrackName.toLowerCase().indexOf(qryTrack.toLowerCase())!= -1){
//trace(currentTrackName + " : it's album id: " + nodAlbum.attributes["id"]);
if(arrObjAlbums != null){ //Only if the array list exists
if(arrObjAlbums[arrObjAlbums.length-1].albumID != i+1){ //Only if the value of the last array item is not the same as the incoming value
//trace("Previous value: " + arrObjAlbums[arrObjAlbums.length-1].albumID);
objAlbum.albumID = parseInt(nodAlbum.attributes["id"]);
objAlbum.albumTitle = nodAlbum.attributes["title"];
objAlbum.albumArtist = nodAlbum.attributes["artist"];
objAlbum.albumTags = nodAlbum.attributes["tags"];
objAlbum.releaseDate = nodAlbum.attributes["releasedate"];
objAlbum.artworkPath = nodAlbum.attributes["artworkpath"];
objAlbum.noOfTracks = parseInt(nodAlbum.attributes["totaltracks"]);
trace("Adding albumID: " + nodAlbum.attributes["id"]);
arrObjAlbums.push(objAlbum);
trace(objAlbum.albumTitle + " is added.")
}else{

trace("Already added.");
}
}else{
trace("Array is null.");
}
}else{
//trace("No result.");
}
}
}
for(h=0;h<arrObjAlbums.length;h++){
trace(arrObjAlbums[h].albumTitle);
}
return arrObjAlbums;
}
XML file structure is as follow:


Code:
<album id="1" title="First Album" artist="Britney Spears" releasedate="16-May-2000" artworkpath="~/Britney_Spears/Oops_I_did_it_again/artwork.gif" tags="pop;rock;">
<track title="003abcdef" artist="Britney Spears;M. Martin;Rami;" />
<track title="Strabcdeonger" artist="Britney Spears;M. Martin;Rami;" />
<track title="Oops!... You!" artist="Britney Spears;M. Martin;Rami;" />
<track title="Stronger" artist="Britney Spears;M. Martin;Rami;" />
</album>
<album id="2" title="Almas del Silencio" artist="Ricky Martin" releasedate="20-May-2003" artworkpath="~/Ricky_Martin/Almas_del_Silencio/artwork.gif" tags="pop;rock;jazz;">
<track title=" Jaleo" artist="Ricky Martin;Madonna;Dido" />
<track title="Stronger" artist="Ricky Martin;JMe" />
<track title=" Jaleo" artist="Ricky Martin;Madonna;Dido" />
<track title="Stronger" artist="Ricky Martin;JMe" />
</album>
<album id="3" title="Second Album" artist="Britney Spears" releasedate="16-May-2000" artworkpath="/Britney_Spears/Oops_I_did_it_again/artwork.gif" tags="pop;rock;">
<track title="Oops!... You!" artist="Britney Spears;M. Martin;Rami;" />
<track title="Stronger" artist="Britney Spears;M. Martin;Rami;" />
<track title="Oops!... You!" artist="Britney Spears;M. Martin;Rami;" />
<track title="Stabcdenger" artist="Britney Spears;M. Martin;Rami;" />
</album>
I look up 'abcde'. It should be found in album1track1, album1track2 and album3track4. So, two albums - 1 and 3 - should be added to arrObjAlbums. "tracing" says it's done so. The bolded should return "First Album" and "Second Album". But now, it returns "Second Album" and Second Album". I don't know what did I do wrong.

Help! Thx in Advance.

Peace:
Kryptonova Z.

Object Array
How do you create an array containign movie clips. I can't figure it out, i know it sounds like a dumb question xD

so far i have this


Quote:




var dpBox:box = new box();
var text1:tf1 = new tf1();
var text2:tf2 = new tf2();
var text3:tf3 = new tf3();





var heh:Array= new Array;

heh = [text1, text2, text3]

addChild(heh)

Array Vs Object
I have been wondering what the main differences were between Array and Object processor and memory usage. I'm working on a project that will be using a lot of data so if using Objects is better than using Arrays (or vise versa) then it would be good to know.

To try an find out I ran a couple of tests in Flash that simply used a for() loop to add 1,000,000 (one million) string variables to an Array, and the same for an Object. The test was run 10 times to get a nice average time.

Here are the results for a 3Ghz PC (AMD Athlon XP processor)...


Code:
Array test...

1.11
0.891
0.891
0.891
0.891
0.891
0.891
0.906
0.906
0.906

Average time -> 0.9174 seconds

Code:
Object test...

1.125
0.906
0.906
0.906
0.906
0.906
0.906
0.907
0.907
0.907

Average time -> 0.9282 seconds
Not much difference in the results really, so that rules out any CPU usage issues. As far as memory goes though I'm not sure how to test that, but I imagine that they are pretty much the same.


Any thoughts or comments?


Si ++

Add Object To Array
Hi,

I have this class (below) which creates an array and then handles the addition of objects to it. However for some reason the array isn't accessible within the class, can anyone help?


Code:
class arrayObject
{
//Properties
public var newlist:Array
public var product:Object


//Constructor
public function ShoppingList ()
{
var newlist = new Array()

}

public function addProduct(product : Object)
{
trace(newlist.length)
trace("adding to array...")
newlist.push(product);

for (var j = 0; j<newlist.length; j++)
{
trace (newlist[j].first);
}


}
}
Code on main timeline...

Code:
import list.arrayObject;
//make new list...
var mylist:arrayObject= new arrayObject();


//add an item in....
var product = new Object();
product.pname = "Cheese";
product.pprice = "1.99";

//add it to the new list...
mylist.addProduct(product)

Add New Object To My Array?
i need help to add new MovieClip to my array any one need to help send to me mailto:smartic@gmail.com & the file is attached to solve my problem :)

Copyright © 2005-08 www.BigResource.com, All rights reserved