Components Values To Associative Array
Greetings
I am wondering if one or more of you very helpful people could possible help me with some actionscript.
I am creating a form using components, ie, textfields etc.
And I need to pass the entered value into an associative array, and then have it traced for checking purposes.
would someone be so kind as to assist me with this?
thanks and regards Anton
FlashKit > Flash Help > Flash ActionScript
Posted on: 05-02-2005, 10:17 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Associative Array
Hi!
make3DPoint(x,y,z) is a function which has three parameters x,y,z
How do I go about adding them into the pointsArray with a looping structure? Instead of one at a time as below????
pointsArray = [
make3DPoint(-50,-50,-50),
make3DPoint(50,-50,-50),
make3DPoint(50,-50,50),
make3DPoint(-50,-50,50),
make3DPoint(-50,50,-50),
make3DPoint(50,50,-50),
make3DPoint(50,50,50),
make3DPoint(-50,50,50)
];
anyone?
Ikonik
Associative Array
I'm trying to create a private assoc. array property that is populated in the constructor, and I'm loosing my mind trying to figure how to do it. It seems like it should be so simple.
Code:
public class SimpleScrollingEnemy extends Enemy {
private var _velocity:Number;
private var _direction:String;
private var _boundaries:Object = new Object();
/**
*
*/
public function SimpleScrollingEnemy(s:DisplayObject = null,h:Number = 10,d:String = "left") {
super(s,h);
//should i add an initialize method?
_velocity = 2;
_direction = d;
_boundaries.left = 0;
_boundaries.top = 0;
_boundaries.right = stage.stageWidth;
_boundaries.bottom = stage.stageHeight;
trace(_boundaries.right); //NEVER EVEN TRACES! ugh
}
}
Dynamic Associative Array
Does anyone know how to create a dynamic associative array. I also want to sort the array.
So instead of putting:
myArray.name = "whatever";
I want "name" to be a variable so I can make an associative array based on user input..
For sorting purposes I've tried analysing another associative array and making a new one from that using a for...in loop with:
myArray.[name] = Arrayname[name];
but that doesn't work..
Please help.
Associative Array Problem
can someone help me... i have multidimensional associative array like
arr = new Array();
arr["a"] = new Array();
arr["a"]["id"] = "id";
arr["a"]["name"] = "name";
arr["b"] = new Array();
arr["b"]["id"] = "id2";
arr["b"]["name"] = "name2";
when i try to loop arr array like
for(i=0;i<arr.length;i++)
loop doesn't start because arr.length returns 0?!?
please help...
how to loop that array?
tnx
Associative Array On SharedObject
I've been unsuccessfully trying to store an associative array on a SharedObject without success.
At the moment I have to store my array in a multi-dimensional style like this:
Code:
var scores = new Array()
scores.push({score: 720, name: "my_game"})
scores.push({score: 1200, name: "that_game"})
scores.push({score: 23 + "secs", name: "some_game"})
then rebuild it as an associative array once I've extracted it from the SharedObject. Is there no way around this? Has anyone out there stored an associative array on a SharedObject? It allows what I call an 'ordinary' array of the form scores[0] = 720... scores[1] = 1200 etc.
Loop Through An Associative Array?
Is there any way to loop through the objects in an associative array?
For example if I have made this associative array:
code: var my_friends:Object = new Array();
my_friends.jackie = {fname:"jackie", url:"/123"};
my_friends.john = {fname:"john", url:"/456"};
my_friends.kate = {fname:"kate", url:"/789"};
Is there any way to access those elements somehow through a for loop?
Associative Array Question
Im doing the tomkitta test and just wondering..did i answer this question wrong? surely u dont need to declare an array as an Object type for it to be associative?e.g
Code:
var myArray:Array = new Array();
myArray["hello"] = "wow";
trace(myArray["hello"]);
or am i getting terminology mixed up?
Ive attached a screen shot..
cheers in adavnce..
[F8] Associative Array Enigma
I have an associative array:
Code:
var arr = [
{Description: "Banana", Quantity: "7"},
{Description: "Strawberry", Quantity: "3"},
{Description: "Nut", Quantity: "9"},
{Description: "Banana", Quantity: "17"},
{Description: "Melon", Quantity: "8"},
{Description: "Nut", Quantity: "5"}
];
What I want is to make another array without duplicate items but with sum of their quantities, so:
Code:
var arr_new = [
{Description: "Banana", Quantity: "24"},
{Description: "Strawberry", Quantity: "3"},
{Description: "Nut", Quantity: "14"},
{Description: "Melon", Quantity: "8"},
];
I found how to extract items without duplicates:
Code:
var i, j;
var indexes=[];
var duplicate = false;
for (i=0; i<arr.length; i++){
for(j=i+1; j<arr.length; j++){
if(arr.getItemAt(i).Description == arr.getItemAt(j).Description){
duplicate = true;
break;
}
}
if (!duplicate){
indexes.push(arr.getItemAt(i).Description );
}
else
{
duplicate = false;
}
}
}
but I canīt associate them with their sums (and no-duplicate items with their original values) to create arr_new from above.
Is it possible?
Thanks in advance
[CS3, AS2] Associative Array Enigma
In Flash CS3, Actionscript 2.0, if trace( key ); displays the string value "two"...
...and trace( myAssocArray["two"] ); displays the string "This is the second entry"...
...why does trace( myAssocArray[key] ); display "undefined"???
Just curious.
...mondoFred
Parse XML To Associative Array
Hello all
I've been working on this all day and have gotten no where, please help!
I am trying to parse this xml file:
Quote:
<?xml version="1.0" encoding="utf-8"?>
<topics>
<general>
<item displayName='Cars' dataName='car' filename='vehicles' />
<item displayName='Bikes' dataName='bikes' filename='vehicles2' />
</general>
<sports>
<item displayName='Football' dataName='football' filename='helmet' />
</sports>
<finance>
<item displayName='Stocks' dataName='stocks' filename='shares' />
<item displayName='Bonds' dataName='bonds' filename='money' />
</finance>
<health>
<item displayName='Chiro' dataName='chiro' filename='back' />
<item displayName='Medical' dataName='medical' filename='cure' />
</health>
</topics>
so that it can work like the solution given in this thread http://board.flashkit.com/board/showthread.php?t=752573.
Quote:
myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("test.xml");
myXML.onLoad = function(success) {
if (success) parseXML(this);
};
function parseXML(xml) {
_global.Data = new Array();
aNode = xml.childNodes;
len = aNode.length;
for (var n=0;n!=len;n++) {
obj = {};
obj.displayName = aNode[n].attributes.displayName;
obj.dataName = aNode[n].attributes.dataName;
obj.filename = aNode[n].attributes.filename;
Data[n] = obj;
}
tracer();
}
function tracer(){
trace(Data[0].filename); // vehicles
trace(Data[1].filename); // vehicles2
};
The problem is that my xml file is divided between different topics such as finance and sports, whereas, the solution in that thread only has 1 topic. How can I parse this so that it behaves where if I trace(Data[0].filename) it will know to output 'vehicles' from the 'general' topic and if I trace(Data[1].filename) it will know to output 'helmet' from the sports topic? Please please help! Thanks much
tone
How To Find Key Of Associative Array?
Hello,
Does anyone know of an easy way to find the key value of of an associative array? This seems like it should be simple but I'm drawing a blank.
For example: I have an array that holds things like:
example_arr["CHILD1"] = "First Child";
example_arr["CHILD2"] = "Second Child";
...etc
If I know the value of the key then I can reference it like so:
example_arr[""CHILD1"]
However, I wont always know the key, hence lies the problem
Thanks!
Tommy
Traversing An Associative Array
OK, I have posted this like two times total in both this and another Flex forum - its gotten to the point that I cant even find my original posts because they get no replies!! So here I am trying again and will give a sample array so that you can see what I am trying to do
Here is my array:
Code:
[settings] => Array
(
[set_color] => Array
(
[label] => "Color"
[values] => "black, grey, white"
[input_type] => "combobox"
)
[set_text] => Array
(
[label] => "Name"
[values] => ""
[input_type] => "text"
)
[set_rank] => Array
(
[label] => "Rank"
[values] => "1-10"
[input_type] => "combobox"
)
)
This value is pulled from a DB and its returned by PHP in the associative array above. As you can see I am trying to dynamically add form element to my app depending on what values are in the "settings" index. I need to loop through each of array settings main key values (set_color, set_text, set_rank) and in turn loop through each of the values within each key (lable, values, input_type). By the input_type value I determine what type of component to create.
The array has a set depth like that above - for example the inner key "values" will NEVER point to a new array. so The settings array has two levels.
HOW DO I TRAVERSE THROUGH THIS ARRAY? Also how do I find out if the "settings" array contains any values. settings array can potentially also look like this: settings => Array() - an empty array
This is NOT WORKING:
ActionScript Code:
for (var key:String in myData.settings) {
Alert.show(myData.settings[key].label);
}
nor this:
ActionScript Code:
if (myData.settings.length > 0) {
Alert.show("success");
}
please help me....
Ampersand In The Key Of An Associative Array
I noticed something strange when I tried this:
Code:
var o:Object = new Object();
o["black & white"] = 0;
The key and value are not added to the object o. There is no error thrown either. But if I do this:
Code:
var o:Object = new Object();
o["black & white"] = 0;
it does work. The debugger shows the key (member variable) as black & white and the value as 0. Is this normal, because I sure did not expect it. Clearly the ampersand IS supported, but why do we need to use an entity like we do in XML?
Combining Associative Array?
How would you combining the following two associative array into one array?
ActionScript Code:
public var capital:Array = new Array;
capital['england']='london'
capital['france']='paris'
public var bossof:Array = new Array;
bossof['subeditor']='editor'
bossof['reporter']='subeditor'
For Loop In An Associative Array
Dear Colleagues,
I have created this associative array. Each of the individual variables are initially set to 0. On a specific frame, I am trying to check to see if the variables have all been set to 1. If they have, then allow the user to proceed. In the debugger, all of the variables go to 1, but it still does not call the enableNext function or report the trace. Any suggestions would be appreciated.
Cordially,
Jason
//On my first keyframe.
_root.topicsPassed = {workstation: 0, faxing: 0, deident: 0, shred: 0, disclosure: 0};
//Checking to see if they have covered all of the topics
for (var i in topicsCovered){
if (topicsCovered[i] == 0){
break;
}else{
trace ("hello");
enableNext();
}
}
Multidimensional Associative Array
Hi,
This is my first post in these forums and I greet you all!
I would like to create a multidimensional associative array so that I can refer to items using two keys i.e.:
aChessBoard["A"]["5"] = "Knight";
aChessBoard["A"]["3"] = null;
aChessBoard["B"]["5"] = "Bishop";
I have already tried
but this does not print anything. Any suggestions?
Attach Code
var _aBoard:Object;
_aBoard["A"]["1"] = "N";
_aBoard["A"]["2"] = "o";
for (var sKey:String in _aBoard) {
trace("KEY = " + sKey );
for (var sKey2:String in _aBoard[sKey]) {
trace(" KEY 2 = " + sKey2 + "ITEM = " + _aBoard[sKey][sKey2]);
}
}
IndexOf Associative Array?
var arr:Array = new Array( {food:'Hamburger', soda:'Rootbeer'}, {food:'Pizza', soda:'7up'} );
trace(arr.indexOf(food:'Hamburger'));
?? I know that doesn't work, but is there syntax to make it work, or does one have to write their own class to handle this?
Associative Array Syntax
I want to create an associative array, but using variables instead of hard coding.
example
instead of
assoc['field1']=data;
I want
assoc[fieldname]=data;
I've been reading for ages and cannot seem to find anything. I've tried the above and it doesn't work.
Any suggestions?
Iterating An Associative Array.
From what I read on the AS3 documents the Object class should be used to create an associative array.
Now this might just be my C++ knowledge getting in the way of how flash works but how do I remove keys? Another question is how do I iterate an associative array? There are no iterators in flash, so I'm guessing it's not possible.
My best idea is to just keep doing what I have now. I use an array that allows me to iterate and keep the associative array for look-up via an ID.
Is this what you guys do in this situation?
Associative Array Question
Hello all,
I am having an interesting problem on a flash game that I am trying to create. Basically, I am trying to create multiple copies of the same MC and allow users to position them in various places around the stage. Thus, I am trying to use an associative array to do this. Here is my code:
on the root:
Code:
var itemList:Object = new Object();
on the button to create the duplicate clip:
Code:
on (press) {
b++;
//Deskdragmovie.duplicateMovieClip("Deskdragmovie" + b, this.getNextHighestDepth(), {_x:400, _y:150});
//var mc2:MovieClip = eval("Deskdragmovie" + b);
var mc2:MovieClip = Deskdragmovie.duplicateMovieClip("Deskdragmovie" + b, this.getNextHighestDepth(), {_x:400, _y:150});
var objdesk:Object = new Object();
objdesk._name = mc2._name;
objdesk._x = mc2._x;
objdesk._y = mc2._y;
objdesk._rotation = mc2._rotation;
objdesk.depth = mc2.getDepth();
this._root.itemList[objdesk._name] = objdesk;
}
Finally - here is the code to trace the results:
Code:
on(press) {
for( var prop in _root.itemList){
trace(_root.itemList[prop]._name);
trace(_root.itemList[prop]._x);
trace(_root.itemList[prop]._y);
trace(_root.itemList[prop]._rotation);
trace(_root.itemList[prop].depth);
}
}
The problem is that on the trace, the _x, and _y are traced as _x:400, _y:150, just as the x/y that I set the duplicated clip to, even though it has been dragged to a different position. Also, the rotation is not working, although the name and depth are working fine.
I eventually want to store these positions in a database so that the user can return and see the room they designed with the MCs at a later date.
Thank you all so very much for your time and help!!!!
Rendering From An Associative Array
I briefly searched the forums, and I hope i'm not bringing up an old issue but I could use a hand with some syntax on a programming concept.
The concept is to create an associative array of objects and then to use that array to create a set of DisplayObjects based on a selected index of that array.
Specifically, i'm creating "tiles" and i'm getting my data from XML. My working code is this:
HTML Code:
var itemIndex:int = 0;
var collection:Array = new Array();
for (i=0; i<anXMLList.length(); i++) {
var tileObject:Object = {imgsrc:imgXMLList[i], caption:titleXMLList[i]};
collection.push(tileObject);
}
I have created a Tile class to handle creating the visual component. How would I use this array to create only three(3) Tiles based on the "itemIndex" ? (there are lots of tiles to create)
Static Associative Array In AS2.0?
Just a couple of quick questions, is it possible to define a static associative array property in AS2.0?
What are the disadvantages to doing something like this:
ActionScript Code:
class templatBuilder {
public static var NAMES:Array = ["one","orange","test"];
public static var FORMATS:Object={one:{_x:100, _y:100}, orange:{_x:200,_y:200}, test:{_x:300, _y:300}};
...
}
Thanks in advance for any input,
jase
MC Targets In Associative Array?
Does anyone know if there is a downside to using movieclip targets as keys in associative arrays?
For example:
Code:
some_array = [];
MovieClip.prototype.addToArray = function () {
some_array[this] = "test";
};
some_mc.addToArray();
It works fine for me, but I wasn't sure if it is "bad form" to use something like this. What do you think?
-Dan
Associative Array Question
Hi,
I've searched for associative arrays and multi-dimensional arrays in the forums. However did not find what I was looking for, I'm not even sure this is what I should be looking for. Here's what I'm trying to do, it was inspired by Lee's video accordion tutorial.
I have several videos on different frames and I'm using the same video control bar for all of them. Initially I had used clipStream_ns as the NetStream for all of them which allowed me to use the same control bar for all the clips. I was running into all kinds of problems and in Lee's tutorial I found that I needed to give each video it's own NetStream to avoid corrupting the video.
So, I've defined all my NetStreams (ie.)
var danStream_ns:NetStream = new NetStream(clip_nc);
var aliciaStream_ns:NetStream = new NetStream(clip_nc);
var paulStream_ns:NetStream = new NetStream(clip_nc);
etc.
Now I'd like to be able to associate the NetStream & flv to a name, like in the video accordion tutorial (ie.)
clip1.stream = danStream_ns;
clip1.flv = "danVideo.flv";
clip2.stream = aliciaStream_ns;
clip2.flv = "aliciaVideo.flv";
etc.
This way I can create a variable that keeps track of whatever video is currently playing by creating a variable such as (var clipPlaying) which allows me to still use the same video controls by using (clipPlaying.stream) for my NetStream and just defining clipPlaying at the begining of each frame where there is a video (ie.)
clipPlaying = clip1;
I'm not really sure how to accomplish this so any help would be greatly appreciated or even if someone could point me in the right direction I'd be happy to search Flash help, I'm just not sure what I should be searching for. Thanks,
Max
Shuffling An Associative Array
Okay, the more I use actionscript the more I see that it doesn't have a lot of native functions built in. So once again, a situation has come up where I need a function that it does not have.
Specifically, I need a function to shuffle an associative array. I've found a number of good functions that will shuffle a regular array, like
Code:
Array.prototype.shuffle=function(){
var Arr2 = new Array();
while(this.length>0){
Arr2.push(this.splice(Math.round((this.length-1)*Math.random()),1));
}
return Arr2;
}
The problem with this, however, is that it relies on the slice function, which expects numeric keys. Anybody know of a function that does a shuffle for associative arrays before I go trying to write this myself? Thanks in advance.
Obtaining Associative Array Key Names
Is it possible to print the name of a key in an Associative Array? I would like to print the key names, not the values at that key.
For example, if I have the following associative array of an XML node's attributes:
xmlNode.attributes.name
xmlNode.attributes.order
xmlNode.attributes.size
How could I go about printing the following string:
"The attributes for this node include: name, order, and size."
Thanks in advance for any help!
Aaron
Associative Array In Flash Mx2004 Pro
Hi,
I'm trying to create an assoc array in mx2004 pro:
code:
// create assoc. array
var tContent=[
{pTitle:"Home",tURL:"var/homeText.htm"}
{pTitle:"Contact Us",tURL:"var/contactText.htm"}
{pTitle:"About Us",tURL:"var/aboutText.htm"}
{pTitle:"Gallery",tURL:"var/galleryText.htm"}
{pTitle:"Materials",tURL:"var/matText.htm"}
{pTitle:"Hardware",tURL:"var/hardText.htm"}
{pTitle:"Quality",tURL:"var/qualityText.htm"}
{pTitle:"Ultra-Violet Information",tURL:"var/uvText.htm"}
{pTitle:"Links",tURL:"var/linksText.htm"}
{pTitle:"FAQ",tURL:"var/faqText.htm"}
];
I am getting the following error
output:
**Error** Scene=Scene 1, layer=Actions, frame=1:Line 5: ']' or ',' expected
{pTitle:"Contact Us",tURL:"var/contactText.htm"}
Total ActionScript Errors: 1 Reported Errors: 1
Can someone please tell me how to resolve this? Any suggestions are greatly appreciated!
Thanks
K
Associative Array, Sorting In Numerics
Hey all super peoples!
I've got an associative array that's mainly strings, but one index is all numerics. I've set up a table to display the data with sort functions that sorts the data alphabetically according to index. However the one index that's all numerics also sorts alphabetically thus the numbers don't sort how I want them to.
I want them to sort like this:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
But they are sorting like this:
1, 10, 2, 3, 4, 5, 6, 7, 8, 9
Does anyone know how I can sort my array numerically? Here's my code if it might help any of you:
Code:
function printer() {
slot._y = -x;
array.sortOn([sortMethod]);
for (i = 1; i < array.length; i = i + 2) {
//trace(typeof(array[i].rating));
duplicateMovieClip(slot, "slot" + i, i);
slot = eval("slot" + i);
slot._y += x;
slot.shootTitle = array[i].shootTitle;
slot.shootDate = array[i].shootDate;
slot.host = array[i].host;
slot.guest = array[i].guest;
slot.rigger = array[i].rigger;
slot.rating = array[i].rating; // this is the index that's all numerical.
slot.link = array[i].link;
for (j = 0; j < array.shootDate.length; j++) {
trace(array[i].shootDate);
}
}
}
MB
Help Dynamically Populating An Associative Array
I am trying to create an associative array and dynamically populate it with information from an XML file. I have no idea how to make a loop that can achieve this, all my attempts thus far have failed. Here is an example of what I need the array to look like.
code:
var selectionData:Array = [
{ title:"Thumb 1", thumb:"../images/thumbs/thumb_01.jpg", lowres:"../images/lowres/lowres_01.png", hires:"../images/hires/hires_01.jpg" },
{ title:"Thumb 2", thumb:"../images/thumbs/thumb_02.jpg", lowres:"../images/lowres/lowres_02.png", hires:"../images/hires/hires_02.jpg" },
{ title:"Thumb 3", thumb:"../images/thumbs/thumb_03.jpg", lowres:"../images/lowres/lowres_03.png", hires:"../images/hires/hires_03.jpg" },
{ title:"Thumb 4", thumb:"../images/thumbs/thumb_04.jpg", lowres:"../images/lowres/lowres_04.png", hires:"../images/hires/hires_04.jpg" },
{ title:"Thumb 5", thumb:"../images/thumbs/thumb_05.jpg", lowres:"../images/lowres/lowres_05.png", hires:"../images/hires/hires_05.jpg" },
{ title:"Thumb 6", thumb:"../images/thumbs/thumb_06.jpg", lowres:"../images/lowres/lowres_06.png", hires:"../images/hires/hires_06.jpg" }
];
Here is what my code looks like to populate a normal array.
code:
var image:Array = new Array();
var rootNode:XMLNode;
var total:Number;
var xmlData:XML = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("data/images.xml");
function loadXML(loaded) {
if (loaded) {
rootNode = this.firstChild;
total = rootNode.childNodes.length;
for (var i:Number = 0; i < total; i++) {
image[i] = rootNode.childNodes[i].nodeValue;
}
} else {
trace("Ahhhhhhh crap!");
}
}
String Keys In Associative Array
Hey all,
What's the actionscript equivalent of this kind of javascript array syntax:
Code:
var myArray = array("bob" => "jones" , "jenny" => "johnson");
I've tried the following...
Code:
var myArray = ["bob" => "jones" , "jenny" => "johnson"];
...and I keep getting this error:
Code:
Left side of assignment operator must be variable or property
What about my code ain't right?
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)
Dynamically Populate Associative Array
I am trying to create an associative array and dynamically populate it with information from an XML file. I have no idea how to make a loop that can achieve this, all my attempts thus far have failed. Here is an example of what I need the array to look like.
ActionScript Code:
var selectionData:Array = [
{ title:"Thumb 1", thumb:"../images/thumbs/thumb_01.jpg", lowres:"../images/lowres/lowres_01.png", hires:"../images/hires/hires_01.jpg" },
{ title:"Thumb 2", thumb:"../images/thumbs/thumb_02.jpg", lowres:"../images/lowres/lowres_02.png", hires:"../images/hires/hires_02.jpg" },
{ title:"Thumb 3", thumb:"../images/thumbs/thumb_03.jpg", lowres:"../images/lowres/lowres_03.png", hires:"../images/hires/hires_03.jpg" },
{ title:"Thumb 4", thumb:"../images/thumbs/thumb_04.jpg", lowres:"../images/lowres/lowres_04.png", hires:"../images/hires/hires_04.jpg" },
{ title:"Thumb 5", thumb:"../images/thumbs/thumb_05.jpg", lowres:"../images/lowres/lowres_05.png", hires:"../images/hires/hires_05.jpg" },
{ title:"Thumb 6", thumb:"../images/thumbs/thumb_06.jpg", lowres:"../images/lowres/lowres_06.png", hires:"../images/hires/hires_06.jpg" }
];
Here is what my code looks like to populate a normal array.
ActionScript Code:
var image:Array = new Array();
var rootNode:XMLNode;
var total:Number;
var xmlData:XML = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("data/images.xml");
function loadXML(loaded) {
if (loaded) {
rootNode = this.firstChild;
total = rootNode.childNodes.length;
for (var i:Number = 0; i < total; i++) {
image[i] = rootNode.childNodes[i].nodeValue;
}
} else {
trace("Ahhhhhhh crap!");
}
}
Problem Creating Associative Array
hi there I'm trying to create an associative array in the following ways but I get the errors under each sample - HELP!
Code:
// method 1:
var nodeData:Array = new Array();
nodeData[0].lft = "1";
TypeError: Error #1010: A term is undefined and has no properties.
// method 2:
var nodeData:Array = new Array();
nodeData[0]['lft'] = "1";
TypeError: Error #1010: A term is undefined and has no properties.
// method 3:
var nodeData:ArrayCollection = new ArrayCollection();
nodeData[0].lft = "1";
RangeError: Index '0' specified is out of bounds.
// method 4:
var nodeData:ArrayCollection = new ArrayCollection();
nodeData[0]['lft'] = "1";
RangeError: Index '0' specified is out of bounds.
I am manually creating an associative array that looks like this:
Code:
nodeData[0].lft = "1";
nodeData[0]['rgt'] = "18";
nodeData[0]['id'] = "337";
nodeData[0]['node_id'] = "102";
nodeData[0]['node_type'] = "0";
nodeData[0]['instance_name'] = "Acceptable_Country Inst 1";
nodeData[0]['success_filter_id'] = "101";
nodeData[0]['fail_filter_id'] = "0";
nodeData[0]['success_tier_id'] = "0";
nodeData[0]['fail_tier_id'] = "3";
nodeData[1]['lft'] = "2";
nodeData[1]['rgt'] = "15";
nodeData[1]['id'] = "267";
nodeData[1]['node_id'] = "29";
nodeData[1]['node_type'] = "0";
nodeData[1]['instance_name'] = "Ad Provider Inst 1";
nodeData[1]['success_filter_id'] = "102";
nodeData[1]['fail_filter_id'] = "0";
nodeData[1]['success_tier_id'] = "0";
nodeData[1]['fail_tier_id'] = "3";
nodeData[2]['lft'] = "3";
nodeData[2]['rgt'] = "12";
nodeData[2]['id'] = "336";
nodeData[2]['node_id'] = "101";
nodeData[2]['node_type'] = "0";
nodeData[2]['instance_name'] = "Check Tier 1 Views Inst 1";
nodeData[2]['success_filter_id'] = "0";
nodeData[2]['fail_filter_id'] = "104";
nodeData[2]['success_tier_id'] = "1";
nodeData[2]['fail_tier_id'] = "0";
............................
and so on and on. Thanks!
Variable Name For Category In Associative Array?
Making a real estate game in flash, and I have all the info for each property stored in an associative array which since the properties are randomly generated I always have to refer to the array for a particular property using a variable, so in this code my array looks like:
this["propnum"+totProps]
This code is supposed to randomly populate some values of this array, but it doesn't work the way I expected it to, its not adding categories and values to the array, except one undefined category. So obviously the [this[homeFeatures[randFive]]] part isn't doing its job correctly.
Not sure if what I'm trying to do here will make sense to anyone, or if anyone can help,
Code:
function setRatings(tempRating:Number):void
{
var homeFeatures:Array = ["Kitchen", "Bathrooms", "Electrical", "Plumbing", "Landscaping", "Driveway", "Siding", "Paint", "Insulation", "Roof", "Windows", "Doors", "Gutters", "Furnace", "Ducts", "Water Heater", "Cooling", "Pool", "Garage", "Pests", "Ceilings", "Walls", "Carpets", "Furnishings", "Floors", "Deck", "Trees", "Sidewalks", "Porch", "Spa"]
var fives:Number;
var fours:Number;
var threes:Number;
var twos:Number;
var ones:Number;
if (tempRating > 1.3) {fives = 10; fours = 20; threes = 0; twos = 0; ones = 0;}
else if (tempRating > 1.25) {fives = 9; fours = 20; threes = 1; twos = 0; ones = 0;}
else if (tempRating > 1.2) {fives = 8; fours = 21; threes = 1; twos = 0; ones = 0;}
else if (tempRating > 1.15) {fives = 6; fours = 22; threes = 2; twos = 0; ones = 0;}
else if (tempRating > 1.1) {fives = 4; fours = 23; threes = 3; twos = 0; ones = 0;}
else if (tempRating > 1.05) {fives = 2; fours = 24; threes = 4; twos = 0; ones = 0;}
else if (tempRating > 1) {fives = 1; fours = 24; threes = 5; twos = 0; ones = 0;}
else if (tempRating > .95) {fives = 0; fours = 24; threes = 5; twos = 1; ones = 0;}
else if (tempRating > .9) {fives = 0; fours = 22; threes = 7; twos = 1; ones = 0;}
else if (tempRating > .85) {fives = 0; fours = 20; threes = 8; twos = 2; ones = 0;}
else if (tempRating > .8) {fives = 0; fours = 18; threes = 10; twos = 2; ones = 0;}
else if (tempRating > .75) {fives = 0; fours = 16; threes = 11; twos = 3; ones = 0;}
else if (tempRating > .70) {fives = 0; fours = 14; threes = 11; twos = 4; ones = 1;}
else if (tempRating > .65) {fives = 0; fours = 12; threes = 11; twos = 5; ones = 2;}
else if (tempRating > .6) {fives = 0; fours = 10; threes = 12; twos = 6; ones = 2;}
else if (tempRating > .55) {fives = 0; fours = 8; threes = 13; twos = 6; ones = 3;}
else if (tempRating > .50) {fives = 0; fours = 6; threes = 14; twos = 7; ones = 3;}
else if (tempRating > .45) {fives = 0; fours = 4; threes = 15; twos = 8; ones = 3;}
else if (tempRating > .40) {fives = 0; fours = 2; threes = 16; twos = 8; ones = 4;}
else if (tempRating > .35) {fives = 0; fours = 0; threes = 17; twos = 9; ones = 4;}
else if (tempRating > .3) {fives = 0; fours = 0; threes = 16; twos = 10; ones = 4;}
else if (tempRating > .25) {fives = 0; fours = 0; threes = 14; twos = 12; ones = 4;}
else if (tempRating > .20) {fives = 0; fours = 0; threes = 12; twos = 13; ones = 5;}
else if (tempRating > .15) {fives = 0; fours = 0; threes = 10; twos = 15; ones = 5;}
else if (tempRating > .1) {fives = 0; fours = 0; threes = 8; twos = 16; ones = 6;}
else {fives = 0; fours = 0; threes = 6; twos = 17; ones = 7;}
this["propnum"+totProps]["fives"] = fives;
this["propnum"+totProps]["fours"] = fours;
this["propnum"+totProps]["threes"] = threes;
this["propnum"+totProps]["twos"] = twos;
this["propnum"+totProps]["ones"] = ones;
for (var i:Number = 0; i < fives; i++)
{
var randFive:Number = Math.floor(Math.random() * homeFeatures.length);
this["propnum"+totProps][this[homeFeatures[randFive]]] = 5;
homeFeatures.splice(randFive, 1);
}
for (var j:Number = 0; j < fours; j++)
{
var randFour:Number = Math.floor(Math.random() * homeFeatures.length);
this["propnum"+totProps][this[homeFeatures[randFour]]] = 4;
homeFeatures.splice(randFour, 1);
}
for (var k:Number = 0; k < threes; k++)
{
var randThree:Number = Math.floor(Math.random() * homeFeatures.length);
this["propnum"+totProps][this[homeFeatures[randThree]]] = 3;
homeFeatures.splice(randThree, 1);
}
for (var l:Number = 0; l < twos; l++)
{
var randTwo:Number = Math.floor(Math.random() * homeFeatures.length);
this["propnum"+totProps][this[homeFeatures[randTwo]]] = 2;
homeFeatures.splice(randTwo, 1);
}
for (var m:Number = 0; m < ones; m++)
{
var randOne:Number = Math.floor(Math.random() * homeFeatures.length);
this["propnum"+totProps][this[homeFeatures[randOne]]] = 1;
homeFeatures.splice(randOne, 1);
}
}
Associative Array From External Data
I need to know how i can create and fill an array of this kind via external source:
ActionScript Code:
myArray[0] = ["alfa",1,["subAlfa1","subAlfa2","subAlfa3"]];
myArray[1] = ["beta",1,["subBeta1","subBeta2","subBeta3"]];
...
The source can be an external text file or dynamic data form ASP
Please, give me a code snippet!!
Thanks in advance, Maxil
Associative Array And Extra Field
here's the MX code fragment:
Code:
function useRxid(remID){
var rxname = "rx" + String(this.rxid_used.length);
trace("---------");
trace("Current assoc is: " + this.rxid_used);
var audit = this.rxid_used.length == 0;
this.rxid_used[String(remID)] = rxname;
//if(audit)
//this.rxid_used.shift();
trace("New used assoc is["+remID+"]: " + this.rxid_used + " Length is: " + this.rxid_used.length);
return rxname;
}
When is use this, it always adds an extra blank value, but only when it inserts the first one. the array is initialied as rxid_used = new Array();
The trace after the first one gives: " , rx0". What's up with this blank on in the first index?
Associative Array With Unsigned Integers
Hello guys!
I have an associative array that is used in a special way: its keys are IDs as unsigned integers, but their order is random and some IDs are large numbers. That's why I have used an associative array. So, 2 questions:
1) Is this ok to use associative arrays this way? Because all I've read about associative arrays is that you usually use them with strings or objects, not int.
2) Is it fast to retrieve a value, given the key? Is it really hashed to be fast?
Thanks a lot!
Barbara
Deleting Element From As Associative Array
Hi. So there is a problem now. Lets show some code:
x = new Array();
x['kamil'] = new Object();
x['kamil'].name = "kamil";
x['madzia'] = new Object();
x['madzia'].name = "madzia";
then, an output:
Variable _level0.x = [object #1, class 'Array'] [
kamil:[object #2, class 'Object'] {
name:"kamil"
},
madzia:[object #3, class 'Object'] {
name:"madzia"
}
]
And now - QUESTION:
How to remove any element from that array when instead of indexes we have names; such as kamil or madzia.
pop, shift, slice, splice and so on... dont work at all.
Regards,
Kamil
Retrieving The Keys In An Associative Array
Hi,
If I have an associative array, say,
cars = {make: "Honda", year: "1997", model: "civic"}
is there an actionscript function to retrieve just the keys, (namely make, year, and model) ? If not, how could it be efficiently done?
Thanks.
Ben
Tracing The Length Of An Associative Array?
This should be an easy one for you guys.
I haven't doen this in so long I forget how its done...
Ok, so I got an assocaitive object array like this:
myArray = new Object();
myArray[0] = {item:"item1", price:"$1.99", active:0};
myArray[1] = {item:"item2", price:"$1.99", active:0};
myArray[2] = {item:"item3", price:"$1.99", active:0};
Now, how do I track the length of this object array.
I would have thought it was:
trace(myArray.length);
But thats not the solution.
Any ideas?
Thanks!
Associative Arrays: Array Or Object?
Dear all,
I am having a confusing night with Associative Arrays in Flash CS3. For example I wrote these lines:
HTML Code:
var listMC: Array = new Array ();
listMC["0"] = "instance0";
listMC["1"] = "instance1";
listMC["2"] = "instance2";
listMC["3"] = "instance6";
listMC["6"] = "instance8";
listMC["7"] = "instance5";
trace(listMC.length);
Result/ 8
Why 8? It seems flash assumes that it has to take into account those missing numbers (4,5). If I use a loop to see the content of the array I got:
HTML Code:
instance0,instance1,instance2,instance6,,,instance8,instance5
This confirms the assumption. And if I use:
HTML Code:
listMC["id0"] = "instance0";
listMC["id1"] = "instance1";
listMC["id2"] = "instance2";
listMC["id3"] = "instance6";
listMC["id6"] = "instance8";
listMC["id7"] = "instance5";
trace(listMC.length);
Result/ 0
No idea why!!!
So, I tried using objects and I got
HTML Code:
var listMC: Object = new Object ();
listMC["0"] = "instance0";
listMC["1"] = "instance1";
listMC["2"] = "instance2";
listMC["3"] = "instance6";
listMC["6"] = "instance8";
listMC["7"] = "instance5";
trace(listMC.length);
Result/ undefined
Not lucky again
A light in this world of darkness?
Thanks in advance
Associative Array Vs Data Object
Lately I have been getting into associative arrays and quickly found out that there doesn't seem to be a way to loop through one, for example:
ActionScript Code:
var myArray:Array = new Array();myArray['constructor_stage'] = new Array(0xFFFF00,100,200,"Level1");myArray['engineering_stage'] = new Array(0xFF0000,440,550,"Level3");
normaly you would do something like this, of course it doesn't work:
ActionScript Code:
for(var i:int = 0; i < myArray.length; i++){}
I went to live docs and they said to use the object class, so is there a way to loop through an object data properties:
ActionScript Code:
var dataObject:Object = {player1:{userName:"theUserName",password:"thePassword"},player2:{"theUserName",password:"thePassword"}}
Deleting Element From As Associative Array
Hi. So there is a problem now. Lets show some code:
x = new Array();
x['kamil'] = new Object();
x['kamil'].name = "kamil";
x['madzia'] = new Object();
x['madzia'].name = "madzia";
then, an output:
Variable _level0.x = [object #1, class 'Array'] [
kamil:[object #2, class 'Object'] {
name:"kamil"
},
madzia:[object #3, class 'Object'] {
name:"madzia"
}
]
And now - QUESTION:
How to remove any element from that array when instead of indexes we have names; such as kamil or madzia.
pop, shift, slice, splice and so on... dont work at all.
Regards,
Kamil
Retrieving The Keys In An Associative Array
Hi,
If I have an associative array, say,
cars = {make: "Honda", year: "1997", model: "civic"}
is there an actionscript function to retrieve just the keys, (namely make, year, and model) ? If not, how could it be efficiently done?
Thanks.
Ben
Can You Create A Dynamic Associative Array
This is what i have:
ActionScript Code:
thisname = my_xml.firstChild.childNodes[k].childNodes[i].nodeName;
thisvalue = my_xml.firstChild.childNodes[k].childNodes[i].childNodes;
I would like to create a completely dynamic associative array....
right now i have:
ActionScript Code:
createGrid_array.push({stock: stockno}); //shortened
i tried
ActionScript Code:
createGrid_array.push({thisName: thisValue}); // shortened
but that doesnt work! Can this be done, and if so, what am i missing?
thanks again.
tania
Dynamic Nested Associative Array Question
I have an object (or associative array... or hash.. whatever) named
Code:
_root.aaa
. The associative array has these other associative arrays,
Code:
_root.aaa.title="Page";
_root.aaa.link="http://www.google.com";
_root.aaa.bbb={};
. The _root.aaa.bbb is another object (or associative array) inside the associative array _root.aaa. I can also assign a .title, .link, or whatever to it.
What I'd like to do is this:
Code:
//I have an array named "navTree" which contains the elements
//"bbb" and "ccc"
navTree=["bbb", "ccc"];
//Just as "bbb" is a property of "aaa", I want "ccc" to be a property of "bbb"
//(or really a property of _root.aaa.bbb)
//So now I will try to create the associative array
_root.aaa[navTree.join(".")={};
What this code has actually done, instead of creating an object _root.aaa.bbb.ccc (in which ccc is a property of aaa.bbb), it has created an object "bbb.ccc" which is a property of "aaa". So when I debug the movie I get:
aaa
-----bbb
-----bbb.ccc
instead of
aaa
-----bbb
----------ccc
weird eh? If I say:
Code:
_root.aaa[navTree[0]][navTree[1]]={};
instead it works. But anyway, does someone know how I can say _root.aaa[MYARRAYHERE] and have the "." in the array be interpreted so the stuff to the right of the "." is a property of the stuff to the left of the "."?
The help would really be appreciated. I think this is just a programming nuance of actionscript... I'm working on this for an XML parser I'm almost done with.. (but this part is the most important!).
Thank you in advance
T.C.
How To Submit An Associative Array From A Flash Form
im using a cms called drupal, with a flash header.
in my flash header, i have a search box. this box posts to the /search page which requires by default the search keywords to be in the edit[keys] post variable, which looks this this via php print_r:
Array
(
[edit] => Array
(
[keys] => test
)
)
how can i get flash to post this kind of array? i have tried using edit.keys, edit["keys"] but none of these show up in php.
thanks
|