Using Multi-dimensional Array And Pass Values To Functions
I just learned Action Script yesterday. I've managed to use the Tween class, but my code grew to over 100 lines just to animate 11 objects becuase I wrote seperate functions/event handlers for each one. So I had the bright idea to use a multi-dimensional array and pass it to a global function instead and cut the code in half. Well, i do not recieve any errors, but the code doesn't work. Any assistance is much appreciated!!
Code: import mx.transitions.*; import mx.transitions.easing.*;
//Global Tween Functions
function alphaDown(obj) { new Tween(obj, "_alpha", Regular.easeIn, obj._alpha, 40, 1, true); }
function alphaUp(obj) { var a = new Tween(obj, "_alpha", Regular.easeIn, obj._alpha, 100, .5, true); }
function myMotion(obj,pos,spd) { var a = new Tween(obj,"_y",Strong.easeOut,contentBox._y,pos,spd,true); }
//background transition TransitionManager.start(background, {type:Fade, direction:Transition.IN, duration:3, easing:None.easeNone});
//Object Array, [objName,stagePosition,transitionSpeed, timeoutDelay] function objAnim(arr){ var len = arr.length; for(var i=0; i<len; i++){ setTimeout (function(){ var b = myMotion(objArray[i][0],objArray[i][1],objArray[i][2]); }, objArray[i][3])}};
var objArray = new Array(); objArray[0]=[contentBox,4,1,4000] objArray[1]=[btn10,648.9,2,5500] objArray[2]=[btn09,584.5,2,6000] objArray[3]=[btn08,515.9,2,6500] objArray[4]=[btn07,441.9,2,7000] objArray[5]=[btn06,377.5,2,7500] objArray[6]=[btn05,308.9,2,8000] objArray[7]=[btn04,234.8,2,8500] objArray[8]=[btn03,170.5,2,9000] objArray[9]=[btn02,101.8,2,9500] objArray[10]=[btn01,27.9,2,10000]
objAnim(objArray);
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 11-10-2006, 09:31 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Multi-multi-dimensional Array?
Can you have an array structured like this?
The idea being that'd we'd have a whole bunch of stores with the same data
School[0] = Store's full name
School[1] = Number of store employees
School[1][0] = Employee 1
School[1][0][0] = Janitor (Title)
School[1][0][1] = Employee 1's hire date
School[1][1] = Employee 2
School[1][1][0] = Sales person (Title)
School[1][1][1] = Employee 2's hire date
And on and on and on
Set Var Of A Multi Dimensional Array
This is probaly a really dumb question but can I do this
__________________________________________________ ___________________
_level0.menu1sub1[0] = "blabladibla";
__________________________________________________ ___________________
even if i do it like this it doesn't seem to work???
__________________________________________________ ___________________
_level0.menu1sub1[0]= new Array();
_level0.menu1sub1[0]= "blabladibla";
__________________________________________________ ___________________
Is it just not possible like this or what
please help, thanks
Multi Dimensional Array
Hi,
I have a problem. I want to use an multi dimensional Array( style = ([lkj,lk],...)), but the problem is I have to put all my dimensions in the array from the start. But sometimes I don't know how many entries I'll have. Isn't there a kind of function like in vb redim...
Any help would be appreciated.
regards,
kilikMX
Multi-dimensional Array Or Something?
Okay, so I have this project where I need to call two things from two different arrays...like this...
"call value 1 from this array out of another "holder" array
maybe like
pens = new array();
colors = new array();
pens[1] = colors[3]
anyone?
[F8] Multi-dimensional Array - Why Why Why?
Code:
_root.map_walls = new Array(_root.map_height);
for (i=0; i<_root.map_height; i++) {
map_walls[i] = new Array(_root.map_width);
}
for (i=0; i<=_root.map_walls.length; i++) {
for (j=0; j<=_root.map_walls[0].length; j++) {
_root.map_walls[j][i] = random(2);
}
}
can someone please explain to me why i can set _root.map_walls[j][i] but not _root.map_walls[i][j] ?
if i change the i and j around flash locks up and asks me to abort the script!!!
thanks
Multi-dimensional Array
I need to display a message indicating which elements of my array have not been validated ie. when a user has not entered the text matching the string in my multi-dimensional array.
Here is the code:
checkAnswer = function() {
guess.text = guess.text.toLowerCase();
var score = 0;
for (var i=0; i<=numPhrases-1; i++) {
for (var j=0; j<=options; j++) {
if (_root.guess.text.indexOf(answers[i][j]) != -1) {
score++;
}else{
/*I need to display a message from an array of messages[i] matching
the indexes of the answers[i] array when one is wrong or absent
The following statement just displays the last message. I'm thinking a temporary array of elemets not validated when this loops.
*/
display.text = message[i];
}
}
}
//calculate and display the score in a dynamic text box
_root.displayTotal = Math.round((score/numPhrases)*100/1);
}
Multi-dimensional Array
quick question...
if you push arrays into a multi-dimensional array is there any way you can trace the names of the sub-arrays? eg...
Code:
var questionList = [];
var animalList = ["cat", "dog"];
var placeList = ["liverpool", "manchester"];
questionList.push(animalList);
questionList.push(placeList);
trace(questionList);
The trace actually just lists all the elements rather than the names of the 2 arrays
Any help would be great
Cheers
Multi Dimensional Array
Hello I have the fallwoing code to create a multi-dimensioanl array to hold data but somehow it doesnt work. Any ideas ? Thanks
Code:
function fnDofeatured() {
var featured:Array = new Array();
var featuredRoot = _root.data_xml.childNodes[1];
var count = featuredRoot.childNodes.length;
trace(count);
for(var i=0; i<count; i++) {
var cat_id = featuredRoot.childNodes[i].attributes.cat_id;
var idx = featuredRoot.childNodes[i].attributes.idx;
var info = featuredRoot.childNodes[i].attributes.info;
var name = featuredRoot.childNodes[i].attributes.name;
var count = featuredRoot.childNodes[i].attributes.count;
var desc = featuredRoot.childNodes[i].attributes.desc;
// featured[i].push(cat_id,idx,info,name,count,desc);
featured[i]=[cat_id,idx,info,name,count,desc];
trace(featured[i][5]);
}
trace(featured[0][4]);
}
XML To Multi-dimensional Array
I'd like to take the data from an XML file and populate a multi-dimensional array. I can parse one attribute from each node, but I'm unsure about how to create a complex array that can organize the data nicely.
XML:
http://www.jonrossway.com/US/screen.xml
Sorting A Multi-dimensional Array
Hi
Can anyone help me with this?
If I had a multi-dimensional array like this:
Code:
Variable _level0.GamesLinks = [object #23, class 'Array'] [
0:[object #24, class 'Array'] [
0:"ConnectGames",
1:"http://www.connectgames.co.uk",
2:"a fab site"
],
1:[object #25, class 'Array'] [
0:"Blah blah",
1:"blah",
2:"test"
]
]
how could I sort it by the first element of each sub-array? So after sorting it would look more like this:
Code:
Variable _level0.GamesLinks = [object #23, class 'Array'] [
0:[object #24, class 'Array'] [
0:"Blah blah",
1:"blah",
2:"test"
],
1:[object #25, class 'Array'] [
0:"ConnectGames",
1:"http://www.connectgames.co.uk",
2:"a fab site"
]
]
since 'B' of 'Blah blah' comes before 'C' of 'ConnectGames' in the alphabet
Thanks in advance, any help would be greatly appreciated
Multi-dimensional-array (some Help Needed This Way)
hi there,
was wondering if any one could explain how to create a mc matrix ??
or in other terms a 'multi-dimensional array' ??
i know how to make the columns, but am struggling to make the rows..
this is what im doin at the mo to get my x axis..
function assembleStatic() {
for(w=0;w<staticImage1.length; ++w) {
this.attachMovie("static","topstatic"+w,(w+6000))
this["topstatic"+w]._x = ((w+1)*15+490);
this["topstatic"+w]._y = 100;
}
}
eg something like this...
<::> <::> <::> <::> <::>
what i want to get is something like ...
<::> <::> <::> <::> <::>
<::> <::> <::> <::> <::>
<::> <::> <::> <::> <::>
<::> <::> <::> <::> <::>
i know that you can use two 'for loops' (one in the other) to do it,
but id like to learn how to do it rather than steal someones
code...
thanks
Help Passing Multi-dimensional Array From Swf To Swf
Hello I am hoping for some help here. I need to pass a multi-dimansional Array from one flash movie to to different flash movie. I can pass simple data fine with the FSCommand SetVariable
Code:
javascript:
function dataEntry_DoFSCommand(command, args) {
var dataEntryObj = InternetExplorer ? dataEntry : document.dataEntry;
var theVarFromFlash = args;
window.document.renderMap.SetVariable("problem", theVarFromFlash);
}
but i can't see to get it to work for my array. this is the data structure of my Array:
Code:
actionScript:
problem = new Array(""
,[""
,0
,[""
,""
,["","","",""]
,[1]]
,[""
,""
,["","","",""]
,[1]]
,[""
,""
,["","","",""]
,[1]]]
,[""
,0
,[""
,""
,["","","",""]
,[1]]
,[""
,""
,["","","",""]
,[1]]
,[""
,""
,["","","",""]
,[1]]]
,[""
,0
,[""
,""
,["","","",""]
,[1]]
,[""
,""
,["","","",""]
,[1]]
,[""
,""
,["","","",""]
,[1]]]
,[""
,0
,[""
,""
,["","","",""]
,[1]]
,[""
,""
,["","","",""]
,[1]]
,[""
,""
,["","","",""]
,[1]]]
);
the data works fine locally, but when I pass it to the new window it will not work. I am having a hard time debuggin this because by the time i test I am out of flash and testing in IE.
here what i am working on:
http://65.16.246.152/flash_to_flash.htm
the yellow button in the top movie passes the data to the bottom movie(will later be in it's own window), and displays it in the text box. The "DRAW" button should draw out the picture. The "RESET" button mannually set the data locally to some made up values -- that is just to test to see if my BUILD function is working.
any ideas on how to get my data to pass in the form that I want it to?? Is there a SetObject FSCommand or soemthing like that? Can I convert the data to a String or something before i send it? I have tried all kinds of options with no luck ...
thanks for any help
--freaking out...
--mm
Loading A Multi Dimensional Array From XML
FlashMX 2004
I need some help with code to load a multi dimensional array on the fly either from other arrays or from XML. This will give you idea of what I'm trying to accomplish:
I've got an XML song playlist:
<?xml version="1.0" encoding="UTF-8"?>
<songs>
<song title="Title 1" path="audio/audiofile1.mp3" text="text/audiotext1.txt"/>
<song title="Title 2" path="audio/audiofile2.mp3" text="text/audiotext2.txt"/>
<song title="Title 3" path="audio/audiofile3.mp3" text="text/audiotext3.txt"/>
</songs>
And I want to load that data in to a single multi-dimensional array:
songList = new Array(
["Title1","audio/audiofile1.mp3","text/audiotext1.txt"],
["Title2","audio/audiofile2.mp3","text/audiotext2.txt"],
["Title3","audio/audiofile3.mp3","text/audiotext3.txt"]);
And here's how I tried to do it without success:
playlist = "audiolist.xml";
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = loadData;
data_xml.load(playlist);
function loadData(success) {
if (success) {
musicList = new Array();
audioTracks = new Array();
audioTracks = this.firstChild.childNodes;
totalTracks = audioTracks.length;
for (var i=0; i<totalTracks; i++) {
if (audioTracks[i].nodeName == "song") {
musicList[i] [0] = audioTracks[i].attributes.path;
}
}
for (var i=0; i<totalTracks; i++) {
if (audioTracks[i].nodeName == "song") {
musicList[i] [1] = audioTracks[i].attributes.text;
}
}
for (var i=0; i<totalTracks; i++) {
if (audioTracks[i].nodeName == "song") {
musicList[i] [2] = audioTracks[i].attributes.score;
}
}
for (var i=0; i<totalTracks; i++) {
if (audioTracks[i].nodeName == "song") {
musicList[i] [3] = audioTracks[i].attributes.title;
}
}
status = "Status: Playlist - Loaded";
} else {
status = "Status: PlayList - Not Loaded";
}
delete audioTracks;
delete data_xml;
}
trace(musicList);
My trace give me "undefined." I also tried each load loop as:
for (var i=0; i<totalTracks; i++) {
if (audioTracks[i].nodeName == "song") {
musicList[i] [0].push(audioTracks[i].attributes.text);
}
}
How do you load these things???
TIA
Len
Populating Multi-dimensional Array?
Hi!
My script should fill up an array with a few numbers.
I've got 12 rows. Every row has 9 columns.
The array should save values of this field.
Like:
row0: 4, 7
row1: 3, 6, 7
row2: 2, 8
The array should look like:
tochange[0][0] -> 4
tochange[0][1] -> 7
tochange[1][0] -> 3
tochange[1][1] -> 6
tochange[1][2] -> 7
tochange[2][0] -> 2
tochange[2][1] -> 8
The arrays are filled up in a random way. So an element of tochange[0] is added, then an element of tochange[2], then an element of tochange[1],...
So i thought this kind of code would be nice, but since it's definitely wrong, i ask you how this would look like, if it would be a working code:
tochange[0]=tochange[0].push(4);
tochange[2]=tochange[2].push(2);
tochange[1]=tochange[1].push(3);
So what would be a working code for filling this multidimensional field? Thanks for your help!
Multi Dimensional Array W/ XML Data
issue trying to populate a dynamic container from library with data.
I have an mc that lives in the library with a linkage identifier of "container".
It has a empty_mc labeled "holder" for the loaded image and a text field labeled "name". When I run the script it places 2 instances of the container mc on the stage but it should be placing 10 and it also doesn't populate the textfield with the name value. What am I doing wrong?
Code:
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function(success:Boolean):Void {
if (success) {
var i:Number;
var itemMens:Array = XPath.selectNodes(this, "/departments/department[@name='MENS']/item");
var itemWomens:Array = XPath.selectNodes(this, "/departments/department[@name='WOMENS']/item");
//For loop to attach our container movieclip and pass the array information
//Starting x & y values
var xPos = 60;
var yPos = 60;
for (i=0; i<itemMens.length; i++) {
//attach the container clip
attachMovie("container", "new"+i, i, {_x:xPos, _y:yPos});
//increase the y postion each time
xPos += this["new"+i]._width+5;
//add the information
this["new"+i].name.text = itemMens[i].attributes.name;
this["new"+i].interest.text = itemMens[i].attributes.price;
this["new"+i].link = itemMens[i].attributes.url;
this["new"+i].image = itemMens[i].attributes.image;
trace(itemMens[i].attributes.price);
}
} else {
trace("Error Loading XML");
}
};
xml.load("content.xml");
If I add trace (itemMens.length) inside the for loop it outputs 10 so why is it not places ten instances of container on the stage.
Multi-dimensional Array Duplicate Mc
I am trying to create a mc dynamically that I will duplicate and populate with xml data. Issue is I am able to create the container clip with script but when I try to duplicate it in a for statement nothing appears on the stage not even the first rectangle named container.
Here is the code:
Code:
/////////////////////////////
// -- Rectangle Function
/////////////////////////////
function drawRectangle(mcClip:MovieClip, nWidth:Number, nHeight:Number):Void {
mcClip.lineTo(nWidth, 0);
mcClip.lineTo(nWidth, nHeight);
mcClip.lineTo(0, nHeight);
mcClip.lineTo(0, 0);
}
/////////////////////////////
// -- Draw Rectangle
/////////////////////////////
var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
_root.container.lineStyle(1, 0x000000, 0);
_root.container.beginFill(0x332211, 50);
drawRectangle(container, 60, 60);
_root.container.endFill();
/////////////////////////////
// -- Variables
/////////////////////////////
var xPos = 60;
var yPos = 60;
/////////////////////////////
// -- Create Thumb
/////////////////////////////
for (i=0; i<10; i++) {
_root.container.duplicateMovieClip("new"+i, i, {_x:xPos, _y:yPos});
xPos += _root["new"+i]._width+5;
if (xPos>400) {
xPos = 60;
yPos += 60;
}
}
XML Or String To Multi-dimensional Array?
Does anybody know an easy way to convert a string/xml text node into a multidimensional array?
I'd like to take something like this: <aoe>[[0,0],[1,0],[2,0],[3,0],[4,0]]</aoe> and extract the array as (gasp) an Array. If this was javascript I'd just be doing an eval on it, which no longer exists in as3, and I don't even think the AS2 parser could eval that.
Updating A Multi-dimensional Array From A Mc
what code would i need to update a single value in a multidimensional array as a mc enters a certain frame, and to overwrite any previous values in that slot, not the whole array just update one of 10 values in an array. would i use splice?! not sure getting confused please help e.g. _root.myarray [53][9] <-just change the value of line [53] value [9] and not all values for line [53] in my array and to overwrite any exsisting values.
-thanks
-arran
Multi Dimensional Array Problem
Hi Frnds
I am need to help u in muti dimensional array.
i want to know how to create it and how to fatch the value from it.
If u expalin it 3D array then it is better for me to understading more in depth.
Multi-dimensional Array Needed?
Here's my scenerio: in my product info MC, user can select from 4 categories which gotoAndStop a nested MC. Each of the 4 categories has 5 hit areas on an "imagemap". The problem that I'm running into is that on each of those hit areas (mc's), I have actionscript - so that's 5 x 4 of essentially the same actionscript. Only difference is text information and _x & _y co-ord's (code is for caption/images boxes) Could I store all that data in an array in the product info MC rather than having 20 blocks of actionscript??
Any ideas would be awesome!
Thanks.
Jason
Multi-dimensional Array Needed?
Here's my scenerio: in my product info MC, user can select from 4 categories which gotoAndStop a nested MC. Each of the 4 categories has 5 hit areas on an "imagemap". The problem that I'm running into is that on each of those hit areas (mc's), I have actionscript - so that's 5 x 4 of essentially the same actionscript. Only difference is text information and _x & _y co-ord's (code is for caption/images boxes) Could I store all that data in an array in the product info MC rather than having 20 blocks of actionscript??
Any ideas would be awesome!
Thanks.
Jason
Multi-dimensional Array Weirdness
you know, every once in awhile, Flash likes to puzzle me with seemingly EASY solutions that aren't easily solved...
I can't figure out why
this works...
ActionScript Code:
BANK += aPrizeSet[2][nAltPrize];
while this doesn't
ActionScript Code:
BANK += aPrizeSet[nPlaceBets-1][nAltPrize];
// nPlaceBets == 1, 2, or 3 exclusively
go figure...anybody know if there is some kind of weird Flash quirk I don't know about?
Copy A Multi-dimensional Weird Array
Hey Fk, I have got a big weird array and I need a copy of it but I can't use the = because then I can modify one of the two array without modifying the other one. Please...help ^^
How Do You Construct A Multi-dimensional Array Dynamically?
Ok, I've never used multi-dimensional arrays before. The examples in books show you:
ActionScript Code:
var myArray:Array = new Array(["Adam","12345"],["Bert","54321"],["Carlos","67890"]);
And variations on this with for loops.
What I want to do is create a multi-dimensional Array dynamically. Each index of _newTextsArray contains a number of words separated by spaces like this:
_newTextsArray[0] = "if you are obsessive compulsive press one repeatedly"
_newTextsArray[1] = "if you are co dependent ask someone to press two for you"
etc.
I want to split the words into a new array within the original array, if that's possible, so that I can access it with _newTextsArray[0][1], which should therefore be "you", and _newTextsArray[1][4], which should be "dependent"
Here's what I've got:
ActionScript Code:
private function splitWords():void {
for(var i:int = 0; i < _newTextsArray.length; i++){
var _splitWordsArray:Array = new Array();
_splitWordsArray.push(_newTextsArray[i].split(" "));
_splitSentencesArray.push(_splitWordsArray);
trace(_splitSentencesArray[i]);
}
}
So how do I create this dynamically?:
_newTextsArray[0] = ["if","you","are","obsessive","compulsive","press", "one","repeatedly"]
_newTextsArray[1] = ["if","you","are","co","dependent","ask","someone", "to","press","two","for","you"]
etc...
Multi-Dimensional Array. Unassigned Size For X & Y
Hi all,
I've got a problem while still at the planning stage for a site. I'm giving a client some XML data with a project, which he will be able to change to edit his site (obviously). One problem I am having while considering the site is building a multi-dimensional array that allows for non-declaration of size for both vectors of the array, as I have no prior knowledge of how many different sub categories my client will eventually want to use, and would rather work around this than impose upper limits!
what I've used in the past is :-
Code:
list1 = new Array();
list2 = new Array();
list3 = new Array();
main_list = new Array(list1,list2,list3);
But obviously this isn't great if he wants more than 3 mp3 lists, so how can I get this second vector "delimited" as it were....?
Code:
myArray = new Array([],[]);
This kind of setup would be useful, but I just cannot figure this one out.
Thanks in advance guys and gals!!!!
[AS2.0/XML] Multi Dimensional Array From XML - Nodes Keep Swapping
I've been trying to resolve this for a while now....
Images I am loading from XML are associated with the right record on first load but then on refresh they swap places !!!! WHY!?
I am loading XML and creating arrays.
Then I pass the array data to objects using loop functions.
the AS counts how many books there are in total then and creates the objects and passes informations regarding each book into the individual objects.
when I trace the array data just before starting the loop function I get a good consistent read:
>
Images:images/Gordon_Ramsays_Sunday_Lunch.jpg,images/Easy_Italian.jpg,images/Healthy_Foods.jpg
Text: Gordon Ramsay's Sunday Lunch,Easy Italian,Healthy Food
Links: Gordon Ramsay's Sunday Lunch link,Easy Italian link,Healthy Food link
Prices: £19.99 hardback,£8.99 paperback,£8.99 paperback output
>
so the XML loading is not the problem.
Is it something to do with the way I am using 'loadClip();'
This is the code building the page:
//---------------------------------------------------------
/*
* This frame we will build the navigation
*/
stop();
//
trace("Images: "+astrImages);
trace("Text: "+astrText);
trace("Links: "+astrLinks);
trace("Prices: "+astrPrice);
//
for (var i = 0; i<nTotalButtons; i++) {
navHolder_mc.createEmptyMovieClip("navButton"+i,i) ;
// make new MovieClip and set to newly created button
var navButton:MovieClip = navHolder_mc["navButton"+i];
// load images
image_mcl.loadClip(astrImages[i],navButton);
}
// Invoked when the actions on the first frame of the loaded clip have been executed
mclListener.onLoadInit = function(target_mc:MovieClip) {
// add link property
target_mc.linkURL = astrLinks[nCounter];
// add events
target_mc.onPress = buttonClick;
//
var bookImgHeight:Number = target_mc._height;
var bookImgWidth:Number = target_mc._width;
//reposition the new istance of the book object
target_mc._y = Math.round(yPosition);
yPosition += bookImgHeight+10;
//
//--title text--
// place the text
target_mc.createTextField("titleText",nCounter,130 ,0,400,30);
// set properties of title text
target_mc.titleText.border = false;
target_mc.titleText.selectable = false;
target_mc.titleText.wordWrap = true;
target_mc.titleText.styleSheet = my_css;
target_mc.titleText.htmlText = "<.buttonStyle>"+astrText[nCounter]+"</.buttonStyle>";
// reposition the price text
target_mc.titleText.autoSize = true;
var nMiddle:Number = (bookImgHeight/2);
target_mc.titleText._y = nMiddle-(target_mc.titleText._height/2+60);
//
//
//--price text--
// place the text
target_mc.createTextField("priceText",nCounter+1,1 30,0,200,30);
// set properties of price text
target_mc.priceText.border = false;
target_mc.priceText.selectable = false;
target_mc.priceText.wordWrap = true;
target_mc.priceText.styleSheet = my_css;
target_mc.priceText.htmlText = "<.priceStyle>"+astrPrice[nCounter]+"</.priceStyle>";
// reposition the price text
target_mc.priceText.autoSize = true;
var nMiddle:Number = (bookImgHeight/2);
target_mc.priceText._y = nMiddle-(target_mc.priceText._height/2+30);
//
//
nCounter += 1;
};
image_mcl.addListener(mclListener);
//---------------------------------------------------------
this the simple XML code:
http://www.thecliffsoncape.com/xml_t...navigation.xml
this the test site:
http://www.thecliffsoncape.com/xml_t...on_Flash8.html
load once, notice the position of the book covers.
load again, it al goes swappy !!
HELP PLEASE!
thank you.
How To Declare A Multi-dimensional Array In Flash 5?
How to declare a multi-dimensional array in Flash 5?
Something like:
myarray[x][y]=new Array();
does not work, so I had to initialize every single array within a for loop.
Is this the conventional method to declare a multi-dimensional array in Flash MX also?
Retrieving Height Property In Multi-dimensional Array
Hi all,
I'm having a problem retrieving the height property of instances placed within a multi-dimensional array.
Specifically, I have a For loop that is using the attachMovie() method to place multiple instances of a movieclip with a dynamic textfield. That textfield is populated through an XML file, and it's height is variable. I need to retrieve the height property so that I can "stack" the instances on stage. My code is looking like this:
Code:
holder.attachMovie("news_mc","mc_item"+i,100+i, {_x:xPos,_y:yPos});
yPos += holder["mc_item"+i]._height+5;
But the _height property being returned is the actual height of the movieclip in the library, not the height of the instance on stage. The result is all of the instances being seperated by the height of the movieclip, rather than taking into account the varying heights of the instances.
Additionally, I've tried retrieving the height of instance at the end of the For loop, after it has been populated with data, but then they all just return "12", and I have no idea where that is coming from.
Lastly, I created an additional For loop on frame 20 that traces each instance's height. On that frame, all of the heights are tracing properly.
My only conclusion is this has something to do with the XML not being fully loaded while I'm trying to retrive the height property initially, but I'm not sure how to get around that since I need to be setting the x/y position of each instance within the for loop.
Phew! That was a mouthful. Can anyone shed any light on this? I'm running out of ideas, so any thoughts are greatly appreciated.
Thanks!
Variable Reference Point In Multi-dimensional Array
I'm working on presentation based on a huge multi-dimensional array. As a user navigates through the presentation, their place in the presentation is tracked by another array, corresponding to where they are in the huge masterArray (ie: tempArray = (0, 1, 3) represents masterArray[0][1][3]).
Following is a function that converts the position tracking array (tempArray) to a string that is the path to the current place in the multi-dim array (masterArray):
ActionScript Code:
var masterArray:Array = new Array(new Array("mary", new Array("joe", "mike", "bert", "ernie"), "tim"), new Array("bob", "fran", "louie"));
var tempArray:Array = new Array(0, 1, 3);
var tempString:String = "masterArray";
var currentPosition = function () {
for (i=0; i<tempArray.length; i++) {
tempString += "["+tempArray[i]+"]";
}
};
currentPosition();
The output to trace(tempString); gives us "masterArray[0][1][3]" which correctly reflects the current place of our intrepid user.
What I need however, is for this string to actually reference that point in the masterArray. If I trace "masterArray[0][1][3]" I correctly get "ernie". But how to convert that string to a array position?
If I were referencing a movieclip, I could just put a string variable inside brackets proceeded by this - this["myMC"] - and it would essentially convert that string to part of the path. But using - this[tempString] - does not work.
Ideas anyone (before I pull out all my remaining hair)?
Thanks!
Creating Multi-Dimensional Delimited Array In ActionScript
Hi, I haven't even gone so far as to try any kind of prototyped idea of this as I just do not want to get myself bogged down on any wrong route, as from past experience, I don't want to waste a weeks worth of time and hair.
here's the problem.........
I am currently poulating a Flash production for a client with XML generated data, simply so that I can give my client a piece of work which they themselves can update easily. The problem comes from the fact that I could have quite a lot of information hanging around in the form of a multi dimensional array structure where the XML data will be placed after parsing.
Ideally I would like the ability to create a delimited Multi-dimensional array, which can dynamically update it's size, without me having to declare an array of 32000 cells each time, which could waste system resources to a stupid proportion.
any help with this would be appreciated.
I have tried:-
Code:
_global.myArray = new Array();
but it didn't seem to initialise the array unfortunately....
Tanks!!!
X-Post From XML Forum: Advanced Multi-dimensional Array / Tree Structure Question.
I've been stuck for about a week on this one, so please offer any help you can. What I'm trying to create is a multi-level dynamic menu system that is similar to the ones posted in the tutorials section by Daafy, but different in the following way: Daafy's menus only allow for 1 level of submenus, and I need to allow for up to 3.
so... my xml looks like this (pulled from a database using ASP) (sorry for the wierd formatting, but this is the only way this message board will display it so it's readable):
[buttons]
...[btn]
......[label]home[/label]
......[link]http://www.rusmo.com/[/link]
......[level]1.0[/level]
...[/btn]
...[btn]
......[label]music[/label]
......[link]empty[/link]
......[level]1.1[/level]
...[/btn]
...[btn]
......[label]bands[/label]
......[link]bands.html[/link]
......[level]1.1.0[/level]
...[/btn]
...[btn]
......[label]images[/label]
......[link]empty[/link]
......[level]1.2[/level]
...[/btn]
[/buttons]
every main button can have 0..n sub-buttons, and every sub-button can have 0..n sub-buttons. as shown, this is 1 level of complexity greater than Daafy's menu system.
the level tag tells me who the button's parent is. the "bands" button is a sub-button of the "music" button. I hope that is apparent from the details I have supplied so far.
Thus the menu is really a hierarchical tree structure, with parents, children, and siblings (much like the ActionScript XML Object). However, I chose to model it this way in XML because the datasource is a 2-dimensional database table and I'm limited by that.
So when this XML is loaded into flash, it comes in as a 2-level structure...the buttons and their properties. It's easy enough to parse the XML to get each button's properties. What I'm trying to do is use the level property to construct a multidimensional array that correctly matches the menu's tree structure, like this:
buttonList
-0
---label
---link
---subs
----0:
-----|-label
-----|-link
-----|-subs
-----|---0:
-----|----|-label
-----|----|-links
-----|----|-subs
----1:
-----|-label
-----|-link
-----|-subs
-1:
---label
---link
---subs
From this hierarchical structure, I think it'll be easier for me to navigate and correcty do the duplicateMovieClip's and attachMovieClip's.
My feeling is that I've unnecessarily complicated things, and there's probably a couple good recursive algorithms out there that would make my life easier.
Anyone have any suggestions for an easier way to do this?
Thanks in advance for your time.
Will.
Pass Values Through Functions
Hello, I'm trying to write a function for smooth transitions through event methods, please see:
ActionScript Code:
_global.elast = function() {
$goTo = 300;
var gap = this._x - this.$goTo;
this._x -= gap * 0.6;
}
myMC.onEnterFrame = elast();
Needs fixing, but I don't know where....
Thank you very much
m.
Pass Array Values To Function Arguments
hi all,
Maybe someone could help me !
it's possible to do this ?
I have an array with some values and i want to pass this values to a function arguments.
example
var theArray:Array = new Array("test1","teste2","teste3");
function hello(t:Number,a:Array){
// do something
test(a)
}
hello(5,theArray)
function test(arg1,arg2,arg3){
// do something
}
I now that i can do like this:
test(theArray[0],theArray[1],theArray[2])
but there is another way to do that ?
thanks in advance,
Multi-Dimensional Arrays
Hello,
I have a movie clip where the user enters 8 dollar values. In frame 1 I set a variable called totalcorrect=0.
After the user enters the dollar values into an input box, they click a button to continue. On that button I have the following array:
on (release) {
spaanswers = new Array([1353.15, "1353.15", "1,353.15"], [91563, "91563", "91,563", "91,563.00", 91563.00], [2790, "2790", "2,790", "2,790.00", 2790.00], [773.97, "773.97"], [1353.15, "1353.15", "1,353.15"], [91563, "91563", "91,563", "91,563.00", 91563.00], [2790, "2790", "2,790", "2,790.00", 2790.00], [780.11, "780.11"]);
for (counter=1; counter<=spaanswers.length; counter++) {
(spaanswers[counter-1][answera] == ["spastudy"+counter]);
var totalcorrect = totalcorrect+1;
}
if (totalcorrect == 8) {
var spastudyfeedback = "good";
} else {
var spastudyfeedback = "bad";
}
}
As you can see, I have the various ways they can enter the dollar value to get the question correct.
What I want to do is check this to see if they got all 8 correct. If so, a dynamic textbox says good, if not it says bad.
The input boxes in frame 1 are titled spastudy1, spastudy2, etc.
When I test this I always get bad, even if all of my answers are correct.
Please help.
Thanks in advance!
Multi-dimensional Arrays
I am having trouble with the following array. all _root.xxx are movie clip instances.
deckSorted = [ [ _root.11, _root.12, _root.21, _root.22 ],
[_root.31, _root.32, _root.41,_root.42 ],
[_root.51, _root.52, _root.61, _root.62 ],
[_root.71, _root.72, _root.81, _root.82 ],
[_root.91, _root.92, _root.101, _root.102 ],
[_root.111, _root.112, _root.121, _root.122 ] ];
Multi-dimensional Arrays
I am having trouble with the following array. all _root.xxx are movie clip instances. it keeps expecting either a , or ] in line one and two. I've gone over the syntax a million times and it all looks right to me. Maybe another persons eyes will see what mine are missing. Thanks for your help
deckSorted = [ [_root.11, _root.12, _root.21, _root.22],
[_root.31, _root.32, _root.41,_root.42],
[_root.51, _root.52, _root.61, _root.62],
[_root.71, _root.72, _root.81, _root.82],
[_root.91, _root.92, _root.101, _root.102],
[_root.111, _root.112, _root.121, _root.122]];
-PhishinPhree
Can I Use Multi Dimensional Arrays In My As?
hellow, i'm wondering if there is a way to create and use multidimensional arrays in actionscript,
i saw this entry in the flash help:
Code:
var recArray = new Array();
recArray.push( { name: "bob", city: "omaha", zip: 68144 } );
recArray.push( { name: "greg", city: "kansas city", zip: 72345 } );
recArray.push( { name: "chris", city: "burlingame", zip: 94010 } );
recArray.sortOn("city");
// results in the following:
recArray[0] = name: "chris", city: "burlingame", zip: 94010
recArray[1] = name: "greg", city: "kansas city", zip: 72345
recArray[2] = name: "bob", city: "omaha", zip: 68144
which sure looks like each array entry has a couple keys(name,city,zip) and values
how would one access these in actionscript by key?
for instance, i want to trace just the city for recArray[1]
trace(recArray[0].city);
trace(city.recArray[0]);
trace(recArray[0][city]);
trace(recArray[0]["city"]);
nothing works, see i am just stabbing in the dark here, i'd really like to use multi-dim arrays, and i thot they were illegal in flash, until i saw this, but am so confused because in the array entry it says that keys can only and always be integers.
thanks,
dross
Multi Dimensional Arrays
2 questions:
can AS arrays have more than 2 dimensions?
if so, how?
i assumed it would be like java, but that didnt work
Multi-dimensional Arrays?
I'm trying to create a 2 dimensional array for my tile-based game to hold the tile numbers by column, then row.
For example if tile number 17 was at position x=3, y=5 in the tile grid, then to get that information I want to be able to find column three, row five's value in the array.
I was going to do this using nested arrays but I read on this website: http://lab.polygonal.de/ds/ that using a single linear array to simulate a multi-dimensional array is quicker - however how to do this stumps me, could anyone explain how to do this?
Multi-dimensional Arrays
Thanks for tutorial ... Big help on getting me started with remoting. I have one question .... could I put a multi-dimensional array right into flash? Like $_SESSION['AUTH_username'],$_SESSION['P000']['Exp_name'] , and $_SESSION['P000'][1]['ITEM_desc']. Could I just send over the $_SESSION var? If so how does flash convert over these variables?
Thanks
Multi Dimensional Arrays
HELP ME SOMEONE PLEEEEASE!!! I need to create a multi-dimensional array...(?) - and thats all I know.... (well almost!)
Multi-dimensional Arrays
I can create them no propblem but say i have soimething like
multArray[62]=(23,34,63)
if I just wanted to change the 34 value only how would I do it, or if I only wanted the 3rd value to exist and the other 2 as null
Z
Sorting Multi-dimensional Arrays
is it possible to sort multi-dimensional arrays by one of its dimensions? if so, can someone show me an example of how that would be done?
tia
Multi-dimensional Arrays AGHHHH
I have little knowledge of multi-dimensional arrays. My big question is that I am going to put user data into the array, so how would i put all that information in?? Would i have to declare an array, make a for loop to make it a multi-dimensional?? If you know of any tutorials or have suggestions they are welcome'd!! Thanks in advance
-Corey-
Sorting Multi-dimensional Arrays?
Ok so I know how to sort single arrays but am having trouble sorting multi-dimensional. Do you just set up the sort in the same way!?
Thanks in advance
Corey
Multi-dimensional Arrays - The Question Is... HOW?
My feeble attempts at making an array that will store the cell with the location of "11x11" of a 23x23 grid stores a value of 1: (wow thats a mouthful)
Code:
Cellarrayone = new Array(23);
for (x=0; x<=23; x++) {
Cellarrayone[x] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}
Cellarrayone[11][11] = 1;
While i'm asking questions PROBLEM #2 (unrelated to above)
How to use attachmovieclip correctly?
Code:
_root.cell[y], [t].attachMovie("NormalCell", "NormalCell[t],[y]", 2["16x16"]);
_root.cell[y], [t].moveTo(trace(8*(x+1)), trace(8*(y+1)));
}
HA~! my feeble attempts briong about a laughter from my diaphragm... POST NOW!!! patience of which have i little, caffiene, of which the drink of cuba provides, is in large quantity in my surroundings...
EDIT: I have a hunch, a hunch, a hunch, that these questions are commonly asked, quite so, quite so, this answer will bring about a change in this threeeaaaadddd... and now its dead.
Dynamic Multi-Dimensional Arrays
hello all - again i must ask the superbrain of kirupa for help
following on from B.Rich's great Multi-Dimensional Arrays and attachMovie tutorial, i'm trying to load the array from an external source.
i've got a text file that outputs:
myArray=samuel price,28,http://www.hybred.co.uk|becky
holland,28,http://www.hybredproductions.co.uk|mark
ovenden,31,http://www.hybred.co.uk/mark
i then try to break this down in flash into a multi-dimensional array that provides info for dynamic buttons:
var myVars:LoadVars = new LoadVars();
var newArray:Array = new Array();
myVars.onLoad = function(success) {
if (success) {
newArray = recreateArray(this.myArray);
trace(newArray);
//Starting x & y values
var xPos = 250;
var yPos = 100;
for (i=0; i<newArray.length; i++) {
attachMovie("container", "main"+i, i, {_xPos, _y:yPos});
yPos += this["main"+i]._height+5;
this["main"+i].name.text = newArray[i][0];
this["main"+i].interest.text = newArray[i][1];
this["main"+i].link = newArray[i][2];
}
}
}
myVars.load("textfile.txt");
function recreateArray( textArray:String ) : Array {
var multiDimentionArray:Array = new Array();
var singleDimentionArray:Array = textArray.split("|");
for (x = 0; x < singleDimentionArray.length; x++) {
multiDimentionArray.push(singleDimentionArray[x].split(","));
}
return multiDimentionArray;
}
however its not working at all. i'm not sure if its because the attachMovie loop is not getting initiated or what...
if anyone could spare a few minutes to help there would be serious apriciation
pre emptive thanks!!
|