Reading An Array - If (array ==1)
>>Hi there, thanks for reading i hope you can help.. >> i have created an array called _root.clip1
_root.clip1 = new Array (); _root.clip1 = [0,0,0,0,0,0,0,0,0];
>> and also two variables which have the values:
xvariable = 1 yvariable = 5
>> when put into the following code
TEST = "_root.clip" + xvariable + "[" + yvariable + "]";
>> make the "TEST" variable = _root.clip1 [5]. i want to take this variable and put it in an if statement to see if the variable = 1 but the following codes havn't worked?
if (test == 1) if (eval(test == 1)) if (("_root.clip" + xvariable + "[" + yvariable + "]") == 1)
Any ideas?
Many thanks.
FlashKit > Flash Help > Flash ActionScript
Posted on: 02-14-2002, 10:02 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Reading Array, Not Setting Array
Sorry everyone, I think I'm making a simple mistake but I just can't see it.
I'm using an array to store the order of something, I also make a backup of that array as a reference to remember what that first array looked like.
The problem comes when I'm using the values of that backed up array to populate the first array. What happens is that the backed up array gets it values overwritten, when all I wanted to do was read its values, not set its values.
Heres what I'm up to :
Code:
// Sets initial array
var ButtonOrder = new Array("One", "Two", "Three", "Four");
// Makes a backup of the initial array
ButtonOrderBackup = ButtonOrder;
// Changes the initial array with values from the backup
// (This is where I think the problems at)
ButtonOrder[0] = ButtonOrderBackup[3];
ButtonOrder[1] = ButtonOrderBackup[2];
ButtonOrder[2] = ButtonOrderBackup[1];
ButtonOrder[3] = ButtonOrderBackup[0];
// Trace Backup array
for (i = 0; i < ButtonOrderBackup.length; i++)
{
trace("Backup " + i + " " + ButtonOrderBackup[i]);
}
trace("");
// Trace initial array
for (i = 0; i < ButtonOrder.length; i++)
{
trace(i + " " + ButtonOrder[i]);
}
trace("");
Heres what the debugger feeds back to me :
Code:
Backup 0 Four
Backup 1 Three
Backup 2 Three
Backup 3 Four
0 Four
1 Three
2 Three
3 Four
I was wanting the initial array to have the values: Four, Three, Two, One. And the backup array to be how it was originally : One, Two, Three, Four.
What have I done wrong, thank you.
Reading Array
I have a array in a MC, pt = new Array(2, 4, 2, 3, 8, 6, 7, 8, 6, 9, 1, 4);
Second MC pt2 = new Array(1, 4, 2, 4, 8, 5, 7, 2, 8, 1, 4, 2);
A random number will be choosed from array1 and for array 2, for example Number 2 and Number 5.
Number 2 in the first array is the Number 4
Number 5 in the second array is the number 8
They are not the same so nothing will happen, but now comes my problem.
How can you make a action if both numbers are equal.
Something like If the number in array pt == Number in pt2
Please can anyone help me?
Reading From Array
I'm trying to make a photo gallery that loads thumbs from an array and when you click the thumb, it brings up the larger image. Pretty straight forward.
The problem is that I don't know how to tell which thumbnail the user clicked on, so that I can pull the appropriate larger image.
---------------
var thumbArray:Array = new Array("s1.jpg", "s2.jpg", "s3.jpg");
var arrayCount:Number = thumbArray.length;
//placement on stage
var startX:Number = 100;
var startY:Number = 100;
var count:Number = 0;
var shift:Number = 0;
while (count != arrayCount) {
//draw array images
var myThumbLoader:Loader = new Loader();
var url:URLRequest = new URLRequest(thumbArray[count]);
myThumbLoader.load(url);
myThumbLoader.x = startX;
myThumbLoader.y = startY + shift;
addChild(myThumbLoader);
myThumbLoader.addEventListener(MouseEvent.CLICK, makeMeBig);
//shift the next image below it
count = count + 1;
shift = shift + 150;
}
function makeMeBig(e:Event):void {
// what goes here?!
}
Reading Array Value
Hello, I have a sprite object which contains a textfield.
I have saved that sprite into an array.
How do I construct a trace statement to read the value of the textfield within the sprite, within the array.
thanks for any help.
Reading Array Variable
Code:
stop();
for(i=0;i<6;i++){
myHitArea = "ha" + i;
trace(eval(myHitArea));
eval(myHitArea).onRollOver = function() {
locateInArray = i;
var mcLabel = leadership_ary[locateInArray];
var mcName = mcLabel + "_mc";
eval(mcName).gotoAndPlay("rollOver");
}
eval(myHitArea).onRollOut = function() {
var mcLabel = leadership_ary[i];
var mcName = mcLabel + "_mc";
eval(mcName).gotoAndPlay("rollOut");
}
}
why won't the locateInArray variable locate the position in my array? It just says it is undefined. But when I put a 0 in there, it reads it fine!?!?
-Kac
Probes Reading An Array..I Think.
hi,
I need to get the information in the array left to be reflected in the the red box. using a small circle that changes color depending on the contents of the array cell.
In frame 1 of the root movie a prototype called drawCircle sets out the code to draw a single circle. I then created a function to pass this prototype the x,y and c_color for the circle, but for some reason in stead of drawing a grid of circles reflecting the array It just draws in the same spot or moves diagnal off the screen.
At the moment it just reads the last cell of the array and places it in the location of the first circle......
Please can someone take a look at the FLA file?
the main part of the actionscript is in frame 3 as follows
Code:
// this script scrolls through each cell starting @ 0.0
do {
for (grid_y=0; grid_y<10; grid_y++) { // moves accross left to right +1 each pass
// start turn/pass, every this untill end turn pass will be exicuted untill the all
// cells are calculated
rand_color =random(3); // creates random number between 0 and 2
grid[grid_x][grid_y] = rand_color; // inserts a random number between 0 and 2
c_color = (grid[grid_x][grid_y]); // reads the number/color of the current cell
circle(grid_x, grid_y, c_color); // call to function to draw circle
gridarray = (grid); // sends the text array to a var for display on stage
// end turn/pass
};
grid_x++; //moves the target down 1
} while (grid_x<10); // checks to see if last line of grid. if so contine
function circle(x, y, c_color) {
x = grid_x+6;
y = grid_y+6;
switch (c_color) {// selects hex number for color of each circle
case 0:
hex_color = 0x000000 ;
break;
case 1:
hex_color = 0xff0000 ;
break;
case 2:
hex_color = 0x0000CC ;
break;
default:
trace ("the cell has not been assigned a color")
}
var c = this.createEmptyMovieClip("c", 1);
c.lineStyle(1, 0x000000, 100);
c.beginFill(hex_color, 100);
c.drawCircle(10, x , y);
c.endFill();
}
Reading From Array PROBLEM
ok this is my code:
var myArray = new Array();
myArray = ["c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8"];
Button:
on (press) {
mc = myArray.splice(random(myArray.length), 1);
}
// this returns: from c1 to c8 randomly, fine
now here is the problem
on (release) {
_level0.cont.mc._alpha = 10;
}
It just do NOTHIG - I've got 8 movieClips inside "cont" MC
i want'em to change their alpha randomly taking the names from the array.
Reading Xml Data Into An Array
hi,
the code below should read the data from an xml file into an array then into a datagrid but its not working? i get the errors:
"TypeError: Error #1009: Cannot access a property or method of a null object reference.
at xmlreader_fla::MainTimeline/LoadXML()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader:nComplete()"
I'm not sure what any of theses errors really mean so i can't really debug the below code??
the function is called by
Code:
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
Could someone explain the errors to me?
Code:
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
trace(xmlData);
var nodes = xmlData.firstChild.childNodes;
for(var i:int =0;i<nodes.length;i++){
trace("New Data In Array"+i);
var xml_array:Array = new Array(nodes[i].firstChild.nodeValue);
}
for (var x:int = 0; x < xml_array.length; x++) {
var User_Login:String = xml_array[x];
dataGridMain.addItem({Username:User_Login});
}
dataGridMain.setStyle("fontFamily", "Verdana");
dataGridMain.setStyle("headerColor", "0xA6CBDD");
dataGridMain.setStyle("alternatingRowColors", ["0xF0F0F0", "0xFFFFFF"]);
dataGridMain.setStyle("rollOverColor", "0xDCEBF1");
dataGridMain.setStyle("selectionColor", "0xFFF97D");
dataGridMain.setStyle("selectionDuration", 300);
}
the xmlData variable holds data becuase it gets traced so i know the variable has values in it.
Thanks
Jon
Reading Array Problem
I cannot figure this one out. Maybe there is a key concept I am missing here and hopefully you guys can help.
The trace commands illustrate the problem - The playString function does not seem to be able to read the array created by the getChord function. I guess my question is why? It reads the default values listed below. Any guidance is greatly appreciated.
private var chordArray:Array = ["6,0","5,0","4,0","3,0","2,0","1,0"];
private var chordArrayCopy:Array = new Array();
A little background - getChord function is called from one class file and playString function is called from another. I don't know if this has anything to do with it. But that's why these are public functions within a public class.
Thanks in advance.
Attach Code
public function getChord(arr:Array):void {
chordArray = arr;
trace(chordArray); //6,1,5,0,4,0,3,0,2,0,1,0 (successful)
updateChordArray();
}
public function updateChordArray():Array {
chordArrayCopy = chordArray;
trace(chordArrayCopy); //6,1,5,0,4,0,3,0,2,0,1,0 (successful)
return chordArrayCopy;
}
public function playString(str:String):void {
var tmpArray:Array = updateChordArray();
for (var i:int; i < tmpArray.length; i++) {
var nestedNoteArray:Array = tmpArray[i].split(",");
if (nestedNoteArray[0] == str) {
playSound(tmpArray[i]);
trace(tmpArray); // 6,0,5,0,4,0,3,0,2,0,1,0 (UNSUCCESSFUL)
} else {
}
}
}
Reading Info Into 2d Array
hey
ive got a page "news.php?search=" outputting this:
id1=1&titel1=owaaa&text1=content2222212&ort1=Tranå s&
id2=4&titel2=sadas&text2=test tesxt Aneby&ort2=Aneby&
id3=9&titel3=titasd&text3=ingassdssadsdset&ort3=An eby Tranås ÖdeshÖG&
this is just an example of a possible output.
The output varies with what search criteria was given , there could be anywere from 0 to 400 hits, were they are listed in this way.
now im wondering how i would get this into a two dimensional array in flash
so that (array[row,column])
array[0,0]=variable id1, array[0,1]=contents of variable titel1 ... and so on..
so the 4 variables are listed in horizontal manner and
array [1,0]= content of the variable id2 and array[2,2]=contents of titel2 ..a nd so on ..
hope this wasent to confusing
thanks
//VoS
[AS] Loop Not Reading Array
I can't get my button's to trace out; it's not reading my rollovers. When I manually write it out (bottom) it works. Any help with what's wrong would be appreciated.
var btnAction:Array = new Array (homeBut, aboutBut, portBut, contBut);
// var btnAction:Array = [homeBut, aboutBut, portBut, contBut];
for (var i = 0; i < btnAction.length; i++) {
this.menuMC.btnAction[i].onRollOver = this.menuMC.btnAction[i].onDragOver = function() {
//this._parent.homeTxt.gotoAndStop("on");
trace("bob");
}
};
Written out it works.
/*
this.menuMC.homeBut.onRollOver = this.menuMC.homeBut.onDragOver = function() {
this._parent.homeTxt.gotoAndStop("on");
};*/
Reading Info Into 2d Array
hey
ive got a page "news.php?search=" outputting this:
id1=1&titel1=owaaa&text1=content2222212&ort1=Tranå s&
id2=4&titel2=sadas&text2=test tesxt Aneby&ort2=Aneby&
id3=9&titel3=titasd&text3=ingassdssadsdset&ort3=An eby Tranås ÖdeshÖG&
this is just an example of a possible output.
The output varies with what search criteria was given , there could be anywere from 0 to 400 hits, were they are listed in this way.
now im wondering how i would get this into a two dimensional array in flash
so that (array[row,column])
array[0,0]=variable id1, array[0,1]=contents of variable titel1 ... and so on..
so the 4 variables are listed in horizontal manner and
array [1,0]= content of the variable id2 and array[2,2]=contents of titel2 ..a nd so on ..
hope this wasent to confusing
thanks
//VoS
Reading The Array Works, Then It Doesnt...
hell there...i have this function that is supposed to build a menu:
Code:
//create menu items
rnMenu = new Array("Getting Started", "Starting Your Shift","Working With Basic Patient Information",
"Working With Exisisting Orders", "Working With Stage and Transfer Orders",
"Updating Patient Care Data", "Placing Orders", "Shift Change Procedure");
//build main menu
function mainMenu (whichMenu){
trace (whichMenu);
//set starting point for first menu item
startX = 26;
startY = 57;
//loop through array for menu button labels
for (i=0; i<whichMenu.length; i++){
attachMovie (menuButton, "menuButton" + i, i);
//pull button name from menu array
//and assign it to the dynamic text field
//inside the "menuButton" movie clip
_root["menuButton" + i].buttonText = whichMenu[i];
trace (_root["menuButton" + i].buttonText);
//position menu Items
_root["menuButton" + i]._x = startX;
_root["menuButton" + i]._y = startY;
//update startY for next menu item
startY = startY + _root["menuButton" + i]._height;
}
}
i call it with:
Code:
mainMenu (rnMenu);
the first trace in the function works fine, but when i try the second time it comes back as undefined, and the movie clips arent attaching at all.
[F8] Problem Reading Array Value In Function
does anyone know why "aButtons[i]" inside the "if" and "else" statements are not returning any values? do i have the correct syntax? thanks
code:
function ButtonFade(currentButton):Void {
trace(currentButton);
for (var i:Number = 0; i<aButtons.length; i++) {
trace (aButtons[i]);
if (aButtons[i] == "mcButton"+currentButton) {
trace ("mcButton" + currentButton + " if");
mcTween(aButtons[i], 0, 0, 0, 0, 30, 0);
aButtons[i].useHandCursor = false;
} else {
mcTween(aButtons[i], 0, 0, 0, 0, 100, 0);
aButtons[i].useHandCursor = true;
}
}
}
[F8] Reading Entire Contents Of 2D Array
I've got a 2D object array that hold varying data:
StudentArray[0].FirstName
StudentArray[0].LastName
StudentArray[1].FirstName
StudentArray[1].LastName
StudentArray[1].Grade
StudentArray[2].FirstName
StudentArray[2].LastName
StudentArray[2].Address
Each index number can hold different attributes (some might have "grade", others "address"), and we don't know what each in each set, as they are read in via outside data sources.
The question: How can I loop through each array element and whatever info might be stored in it, without knowing the name of the attributes ahead of time?
Thanks in advance!
Reading From An Array Into A Dynamic Txt Field
hi
i have 25 arrays setup (all following the same format) that hold info about a company and share prices for 5 days.
eg.
PHP Code:
company1_arr = new Array("Company1 name", "99.99", "88.88", "77.77", "88.88", "77.77")
these variables are stored in a seperate movie file that loads in at level 100
i then have dynamic txt fields in another movie where i am trying to load in relavant info from the arrays. i have tried the following but it does not work
PHP Code:
for (i=1; i<=25; i++){
// set company name
shares_mc.cName_txt.text = _level100["company"+i+"_arr"][0];
// set days share price
shares_mc.sPrice_txt.text = _level100["company"+i+"_arr"][dayNum];
}
the day num variable is used elsewhere but i've also used it to strip out the share price for each day as it will match the relevant element number in the arrays.
any help is greatful
cheers
[MX] Question On Reading Array Information
Hello, I'm working on making Back and Forward buttons (like browser buttons) for the projector file I'm creating. I have looked briefly at swfaddress, but I don't think that will work on my case since I want the file to run as a standalone movie, not in a browser. Anyhow, my question is how can I read the last value in my array? Or even better, how can I read the second to last value in my array? I've got the back button to work slightly by using the .pop() function. I ran into a problem though doing it that route. I don't necessarily need the information stripped from the array, I simply want to have Flash read the data within it. As I was typing this I had an idea and tried it, it seems to work out for the most part, some bugs still, but hey. I'm going to post the .fla to get opinions anyhow. Is there a better route to take then what I'm doing? Is there a more efficient way? Appreciate any comments. Thanks.
Mo
P.S. the forward is yet to be coded, and to nav you use the "2, 3, 4, and 5" keys. "Back Arrow" is to go back.
[CS3] Yahtzee: Reading Array Values
Hi, I'm new. Please don't kill me with your überness, as I am quite brittle.
As the game Yahtzee is typical Norwegian Easter entertainment, I decided to try to make a Maxi Yahtzee (6-die Yahtzee) game as my first large Actionscript project (that is not fiddling around with a tutorial). Been working tonight and I've managed to make the 6 dices roll when I want, and hold when I want, as well as getting the die values into an array after 3 rolls by converting it from the separate die values.
PHP Code:
on (release) {
var points = [trn1,trn2,trn3,trn5,trn5,trn6]; //putting the 6 die (Norwegian: terning, abbr. trn) values into the array "points"
gotoAndStop("points",1); // going to scene "points" where the scoreboard is
}
Now, I can use the Array.sort to make them fall into place "numerically", but what I need is to make Flash understand what numbers are actually there.
For example, a large straight is 2, 3, 4, 5, 6 and another die value that is not put into consideration. I can make the actionscript recognize an array of "2,3,4,5,6,4" as a "Large Straight", but when these are put numerically, the array read "2,3,4,4,5,6", which wouldn't be read as a "Large Straight".
Is there a way to use if statements to check if an array contains a 2, a 3, a 4, a 5 and a 6 individually of placement in the line? If I knew this, the rest wouldn't be more than if's and else's and some lists, so I'd probably manage it on my own.
I use Actionscript 2.0 for this, as it is the one I'm most familiar with, but I guess I could transfer the project to 3.0 if I had to.
If someone could either tell me a way of achieving this, or point me to somewhere where a way is explained, I'd love the person(s) long time.
If this should be in the Game board, please move it. I just thought that this would be an array question more than a game question, so I put it here.
Reading Into A Nested Array Problem
hey all, now i have done some looking, and have seen many threads with how to look into a nested array, but i suppose since i never done one, most of things i see are too complex for me to get a grapple on this....
so here i go, i have let's say 3 arrays with images i'm nesting in an another array, and i want to trace to individual images inside each array, but all i can trace is through the images in the "allImges" array. i need another loop inside but don't understand how to trace individual imgs ...
PHP Code:
var web_pre = ["images/i_1.jpg", "images/i_2.jpg", etc ...]
var print_pre = ["images/p_1.jpg", "images/p_2.jpg", etc ... ];
var photo_pre = ["images/f_1.jpg", "images/f_2.jpg", etc ...];
//
var allImages_pre = [[web_pre],[print_pre],[photo_pre]];
//
objNum =30; // this is the amount of clips I'm loading imgs into will be more then length of my array
//
for (var i = 0; i < objNum; i ++) {
trace(i+" "+_root.allImages_pre[i%_root.allImages_pre.length][0]); //getting images in arrays here
for (var j = 0; j < allImages_pre.length; j ++) {
trace(_root.allImages_pre[i][j]); // how do i get imgs here?
}
}
i'd appriciate any help, as this must be really simple to lots of you....
Reading In An Array From A Text File
I'm trying to use a text file to load in some configuratin data (using actionscript 3) I have it working ok for simple stuff like gamename=Chess&gamescore=100 , etc... but some of the data needs to be in an array. Can someone please point me in the right direction to how I can read in an array from a text file?
Thanks!
Problem With Reading Object # In Array
Hello,
I've written some php (w/ help from hans and some others, thanks!) and loaded it into to flash to make a list of images to read into a photo gallery. Then I wrote the function in order to be able to change images:
ActionScript Code:
function changeSlide(number) { if (number>=0 && number<images.length-1) { currentSlide = number; loadMovie(images[number], "_root.placeholder"); }}
The length-1 part has to do with an extra string once the php is split, so dont worry. The images change on clicking buttons, which have the following codes:
forward
ActionScript Code:
on(release){ changeSlide(_root.currentSlide + 1);}
back
ActionScript Code:
on(release){ changeSlide(_root.currentSlide - 1);}
I am making an image count (ex. 1 of 12) or (ex. currentslide of total).
Now, the problem is. I've figured out how to dynamically make flash figure out how many image filenames were loaded (total):
ActionScript Code:
total.text = images.length-1;
but I can't figure out how to load the number slide it is on into a dynamic text field. This, for example, outputs [type Function] into the textfield:
ActionScript Code:
slidenum.text = number;
I tried a few things but basically I'm stuck. Any help or advice is extremely appreciated. I tried searching believe me its my last resort to actually post. If anyone needs more info about this to clarify, tell me I'll post it.
Thanks in advance!
Problem With Reading Object # In Array
Hello,
I've written some php (w/ help from hans and some others, thanks!) and loaded it into to flash to make a list of images to read into a photo gallery. Then I wrote the function in order to be able to change images:
ActionScript Code:
function changeSlide(number) { if (number>=0 && number<images.length-1) { currentSlide = number; loadMovie(images[number], "_root.placeholder"); }}
The length-1 part has to do with an extra string once the php is split, so dont worry. The images change on clicking buttons, which have the following codes:
forward
ActionScript Code:
on(release){ changeSlide(_root.currentSlide + 1);}
back
ActionScript Code:
on(release){ changeSlide(_root.currentSlide - 1);}
I am making an image count (ex. 1 of 12) or (ex. currentslide of total).
Now, the problem is. I've figured out how to dynamically make flash figure out how many image filenames were loaded (total):
ActionScript Code:
total.text = images.length-1;
but I can't figure out how to load the number slide it is on into a dynamic text field. This, for example, outputs [type Function] into the textfield:
ActionScript Code:
slidenum.text = number;
I tried a few things but basically I'm stuck. Any help or advice is extremely appreciated. I tried searching believe me its my last resort to actually post. If anyone needs more info about this to clarify, tell me I'll post it.
Thanks in advance!
Reading Array Values From A Text Field
if you want to pull values out of an array in actionscript, it's easy... but how would you do it if you want a text field to reflect array values?
myArray.1 and myArray[1] don't pull the value correclty; the only way i could get it to pass was if i first defined a NEW variable that was always equal to the slot I needed, and then to reference that variable in the text field variable name. am i missing something?
Reading Of Array Items Works Until Online
I have a pre-loader code that loads all of my exteranl XML text files. When I click on a link several frames later, the appropriate file is pulled from the resulting Array and placed on the stage. It works perfectly offline, but as soon as I upload it I get random text files loaded instead of the correct one. Any ideas?
Thanks!
Code below:
//combine all the arrays into one and send it to the preloader
allText = new Array().concat(introText,textForCard1,textForCard2 ,textForCard3,
textForCard4,textForCard5,textForCard6);
textForContent = allText;
//text preloader starts here
var counter:Number = textForContent.length, ii:Number = 0;
for (var i:Number = 0; i<counter; i++) {
xmlToLoad = textForContent[i];
this["xmlData"+i] = new XML();
this["xmlData"+i].load(xmlToLoad);
// Check if data loaded
this["xmlData"+i].onData = function(src:String) {
if (src != "undefined") {
AfterData(src, num);
}
};
}
AfterData = function (src:String) {
++ii;
if (ii<counter) {
_level0["xmlToDisplay"+ii] = src;
} else {
_global._level0["xmlToDisplay"+ii] = src;
//stop();
play();
}
};
//hard coded line sends #2 in this case to function that places text on stage
textForStage = _level0.xmlToDisplay2;
Reading Variables From Text File And Putting It Into An Array In Flash
Hi FlashGods!!!
I badly need your Help.
I have a txt file where two variables are declared. Both the variable's values are more than one. Now I want to import it into Flash and put it into an Array so that they are easier to call anytime, and those values can be changed without touching the fla or swf. Simply I have to make changes in the text file.
Now the problem is, I am getting my output, but on the click of a button, I don't want this, I want everything to be done through framescript. How is it possible, Can somebody help me Please......
Array, Array HELP - Importing A External File Into N ARRAY - Almost There
I am reading and external file with the following code:
ActionScript Code:
on (release, keyPress "<Enter>") {
lv = new LoadVars();
lv.onLoad = function() {
questions1 = this.filelist0.split(",");
answers1 = this.filelist1.split(",");
for(i=0;i<questions1.length;i++)
//trace(questions1[i]+" "+answers1[i]);
trace(questions1[i]);
//assumes same number of scores in each list
};
lv.load("questions.txt");
}
When I parse the file it puts it into an columar format as it should...however I need it to look like this:
questions1=new Array ("2+4=?","What is the capital of Illinois?","What color is the sky?","10x(5+2)=?");
answers1=new Array ("8","springfield","blue","70");
How do I do that?
Text file look like this:
&questions1=2+4=?,What is the Capital of Illinois?,What color is the sky?,10x(5+2)=?")&
&answers1=8,springfield,blue,70&
"gallery" Reading From Array, Next And Previous Button Headache
Alright, I'm doing this to make a catalogue better for people on dial-up.
Theres two movie clips, one will be hidden at all times, the next image is loaded into the hidden movieclip.
The next button is working fine, although the previous is not, the objIndex changes down although that array index is not called in loadMovie();
I plan to switch over to colin moocks' preloader later when I get this working, make it draw/attach a preloader into each movieclip incase the movie has not loaded before the user presses "next".
Anyway, code is below, looks fine to be but I've been looking at it too long.
Any ideas folks?
Code:
var objIndex = -1;
picPath = "";
pics = ['winterrangep1.jpg', 'winterrangep2.jpg', 'winterrangep3.jpg', 'winterrangep4.jpg', 'winterrangep5.jpg', 'winterrangep6.jpg'];
_root.createEmptyMovieClip("holder_mc", 1);
_root.holder_mc.createEmptyMovieClip("image_1", depth++);
_root.holder_mc.createEmptyMovieClip("image_2", depth++);
var mc_1 = _root.holder_mc.image_1;
var mc_2 = _root.holder_mc.image_2;
mc_2._alpha = 0; // set the second to be hidden *IMPORTANT*
mc_2._x = 500; // move it outta the way while testing so I can see whats going on
MovieClip.prototype.loadPic = function(i, action) {
thisObj = this;
objIndex = (objIndex+i)%_root.pics.length;
thisObj.loadMovie(picPath+_root.pics[objIndex]);
if (objIndex<0) {
objIndex += _root.pics.length;
}
};
MovieClip.prototype.swapVis = function(action) {
trace(this._name+": "+action+" objIndex = "+objIndex);
if (this._alpha == 100) {
this._alpha = 0;
if (action == "prev") {
this.loadPic(-1, "prev");
} else if (action == "next") {
this.loadPic(1, "next");
}
} else if (this._alpha == 0) {
this._alpha = 100;
}
};
mc_1.loadPic(1, "next");
mc_2.loadPic(1, "next");
nextButton.onRelease = function() {
mc_1.swapVis("next");
mc_2.swapVis("next");
};
prevButton.onRelease = function() {
mc_1.swapVis("prev");
mc_1.swapVis("prev");
};
"gallery" Reading From Array, Next And Previous Button Headache
Alright, I'm doing this to make a catalogue better for people on dial-up.
Theres two movie clips, one will be hidden at all times, the next image is loaded into the hidden movieclip.
The next button is working fine, although the previous is not, the objIndex changes down although that array index is not called in loadMovie();
I plan to switch over to colin moocks' preloader later when I get this working, make it draw/attach a preloader into each movieclip incase the movie has not loaded before the user presses "next".
Anyway, code is below, looks fine to be but I've been looking at it too long.
Any ideas folks?
Code:
var objIndex = -1;
picPath = "";
pics = ['winterrangep1.jpg', 'winterrangep2.jpg', 'winterrangep3.jpg', 'winterrangep4.jpg', 'winterrangep5.jpg', 'winterrangep6.jpg'];
_root.createEmptyMovieClip("holder_mc", 1);
_root.holder_mc.createEmptyMovieClip("image_1", depth++);
_root.holder_mc.createEmptyMovieClip("image_2", depth++);
var mc_1 = _root.holder_mc.image_1;
var mc_2 = _root.holder_mc.image_2;
mc_2._alpha = 0; // set the second to be hidden *IMPORTANT*
mc_2._x = 500; // move it outta the way while testing so I can see whats going on
MovieClip.prototype.loadPic = function(i, action) {
thisObj = this;
objIndex = (objIndex+i)%_root.pics.length;
thisObj.loadMovie(picPath+_root.pics[objIndex]);
if (objIndex<0) {
objIndex += _root.pics.length;
}
};
MovieClip.prototype.swapVis = function(action) {
trace(this._name+": "+action+" objIndex = "+objIndex);
if (this._alpha == 100) {
this._alpha = 0;
if (action == "prev") {
this.loadPic(-1, "prev");
} else if (action == "next") {
this.loadPic(1, "next");
}
} else if (this._alpha == 0) {
this._alpha = 100;
}
};
mc_1.loadPic(1, "next");
mc_2.loadPic(1, "next");
nextButton.onRelease = function() {
mc_1.swapVis("next");
mc_2.swapVis("next");
};
prevButton.onRelease = function() {
mc_1.swapVis("prev");
mc_1.swapVis("prev");
};
Pls Help: Need To Create New Array Taking 3 Random Entries From An Existing Array
Hello
I have a 2d array:
qTeeth[1] = [How many teeth do we have?, 1-10, 11-20, 21-30, 11-20]
etc.
It goes [question, option1, option2, option3, real answer]
I now just want to extract 3 or so of these entries and create a new array with them. Since I want to just use 3 or so questions randomly from a large array of questions.
Does anyone know a good tidy script to do this with??
Thanks in advance,
Ben.
Array Text Into Textfield And Creating New Line For Each Array Element
I have an array called dropTarg1 which stores dropped-in items.
I want to loop through this array and in a textfield, display each array item on a new line of this text field
I think I need to use something like Array.join("/n") but I can't get it working properly. I hope that the /n would create a new line of the text field called reviewBoxContentText.
for(var i:Number = 0; i<dropTarg.length; i++){
with(reviewBoxContent.reviewBoxContentText){
autoSize = true;
text = dropTarg1.join("/n");
}
}
All that is happening though is that the text field displays on a single line with /n in between each array element.
Calling A Function With An Array Variable As Arguments Is Resetting Array?
I'm going to post the full code of the two functions, disregard the "fluff" unrelated to the two functions as it is all working flawless, I've tested this HEAVILY and cannot understand why it keeps setting the entire array to undefined!
Any help would be grateful.
ActionScript Code:
// processReplace Function function processReplace(transferFiles) { var processArray:Array = transferFiles.slice(); var fileName:String = new String(); var filesArray:Array = new Array(); var replaceArray:Array = new Array(); var exists:String = new String(); var error:String = new String(); var promptResult:String = new String(); // Check for (i=0; i<processArray.length; i++) { // This is where it bugs up <b>exists = processSearch(transferFiles[i][1]);</b> if (exists == "replace") { replaceArray.push(processArray[i]); } else { filesArray.push(processArray[i]); } } // Prompt if (replaceArray.length>0) { error = "Replace "+replaceArray.length+" item(s):
"; for (i=0; i<replaceArray.length; i++) { error += " - "+replaceArray[i][1]+"
"; } promptResult = mSystem.messageBox(error, "Replace Existing Files?", 4); } // Action if (promptResult == "NO") { transferFiles = filesArray; } else if (promptResult == "YES") { transferFiles = filesArray.concat(replaceArray); } processTransfer(transferFiles); }
The processSearch
ActionScript Code:
// == processSearch Function function processSearch(sentInfo) { for (i=0; i<_global.boxFiles.length; i++) { if (_global.boxFiles[i] == sentInfo[1]) { return "replace"; break; } } }
Basically it's supposed to check to see if the file exists and return as true if it does and add it to a replace array, then the replace array is processed into a single string and put into a dialog box through the flash wrapper prompting them to "replace the files or not".
It makes the replace array just fine, it actually even has the right "count" in it but it's setting all the "filenames" to undefined because of the exists = processSearch function.
I even tried to make a new array and run the search just from that one and set the values from the old one and it's still failing.
Is it because of the "break" or can anyone figure it out? Iknow it's hard because you can't use the code
ANY Solution ideas are welcome, even if you think it's dumb
Thanks!
Array.splice Works But Array.slice Doesnt?
This should be simple enough. I have an array of objects, and I want to SLICE a piece of the array and assign it to a new array. All of my attempts have failed. SPLICE works, and I could duplicate my original array into a temp array and splice out what I want, but surely slice is supposed to save me this trouble, right?
I'm a bit baffled, but here's the code:
Code:
private function createGlist() {
var glistObj:Glist = this;
xml_object = new XML();
xml_object.ignoreWhite = true;
xml_object.onLoad = function(success:Boolean):Void {
if(success) {
var i:Number = 0;
for (var this_node = this.firstChild.firstChild; this_node != null; this_node = this_node.nextSibling) {
glistObj.thumb_array.push(new Gthumb(glistObj, glistObj.thumb_array_mc.getNextHighestDepth(), this.firstChild.childNodes[i]));
i++;
}
var load_start:Number = 2;
var load_count:Number = 2;
glistObj.thumb_load_array = glistObj.thumb_array.slice(load_start,load_count);
trace(glistObj.thumb_load_array); //no result, no error
trace(glistObj.thumb_array.slice(load_start,load_count)); //no result, no error
trace(glistObj.thumb_array.splice(load_start,load_count)); //outputs [object Object],[object Object]
} else {
//error
}
}
xml_object.load(xml_url);
}
Array Copy Points To Original Array Instead Of Duplicating
Hey all.
Spent a long time trying to figure out what was wrong with my code. Then I remembered about arrays being objects instead of primitive variables. My question is, how can I make a duplicate copy of an Array?
Details:
So this code
PHP Code:
package{
import flash.display.*
public class tester extends MovieClip{
var a:Array = [1,2]
public function tester () {
var b = a
trace (a)
b.splice(1,1)
trace (a)
}
}
}
results in this output:
PHP Code:
1,2
1
How can i make b an actual duplicate of a, instead of a pointer?
PHP Code:
b = new Array
b = a
doesn't work either.
Thanks!
DHP
Creating Multi-dimentional Array From Single Array
I have an array
myArray=[hello,bye,fred,1,2,3,4,5,6];
I need to convert it to a multi-dimentional array that would look something like below
array1=[hello,bye,fred];
array2=[1,2,3];
array3=[4,5,6];
newArray=[array1, array2,array3];
I am not sure how to split the array can anyone help? myArray.length/3 would give me the number in each of the new arrays but I am puzzled after this?
Associating Array Elements With Another Array Keeping The Order.
hi, i have already posted this problem yesterday but i haven't solved it yet.
i have two arrays:
array_1[a,b,c,d]
array_2[01,02,03,04]
the first array represents mcs in my stage - the buttons of the menu.
the second represents other mcs, containing some text.
when i rollOver each element of array_1 i would like to show each element of array_2 in the same order and hide it when i rollOver another menu button to show a new one.
I mean, it always has to be showing a with 01, b with 02, c with 03...
any suggestions?
Array Of Movie Loaders/array Of Image Files
Alright. I'm fairly new to Actionscripting, so if we can somewhat lame out the tech talk to mild to medium I'd appreciate it. what I am trying to do is create an swf movie that will interact with a PHP script. first lets start with saying the PHP script reads the directory that it is currently in and filters out any file that is not a GIF,PNG, or JPG and then it suffes all of this into a URL encoded string and the directory path ,such as :
?pictures=image1+image2+image3+image4&path=http://servername/directoryPath
now i have flash load the variables "pictures" and split the images and stuff those into an array and the directory path of course stays in its own seperate variable. ive gotten this far with no problems.
so what im trying to do now with this info is create a bit of a slide show. I want to take the array of pictures and load those into an empty movie clip displaying each picture consecutively. Ive made several attempts but no such luck. Ive tried to use a for() loop to cycle through the array of pictures loading them into the empty clip. im still very new and rather lost with these objects and class use i. Im sure im probably not using a listener of somesort that i need and what not. I am sorry i am probably not giving enough info for all this. the whole idea of this clip is to be able to display an indefinite amount pictures , so the flash player will not know ahead of time how many pictures till the php script has sent all the names of what is in the directory. this movie needs to be able to dynamically load any images that are in that directory.so any suggestions on what i can do with an array an an empty clip? thank you to anyone who can make suggesions.
How Do I Lope Through Array, Delete Clip And Remove From Array
I have a function that creates an instance of a movieClip and adds it to an array.
In my gameloop I loop through the array and change some values. Now I want a cleanup function that loops through the array, and if the y value exceeds a certain value, I want to delete the clip instance and remove the record in the Array.
Could someone please help me with the syntax for that? I will lay the code out below.
Thankyou
Attach Code
var myClipArray = new Array();
public function createClipInstance() {
var myClipInstance:myClip = new myClip();
myClipInstance.y = 0;
addChild( myClipInstance );
myClipArray.push(myClipInstance);
}
// loop through array and check y value
// if y > 400: Delete clip and remove from array
public function cleanClips() {
for (var n:int = 0; n<myClipArray.length; n++){
if (myClipArray[n].y > 400) {
// DELETE CLIP AND REMOVE FROM ARRAY
trace("this is where I need help");
}
}
}
Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...
ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.
the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...
is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?
any suggestions would be grand.
this is what i have on my controller clip:
onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}
Load Xml Images-->Array-->Duplicate Array: AHAA
Hello Kirupians!
[Summary]
I want to load images from an XML, then store the images inside an array, then duplicate that array into other clone arrays so that I can addChild() copies of the images into stage whenever i want (and be able to change their properties).
Basicly i have to create two duplicates; big_img and icon_image
[SYMPTOMS]
Everything is loaded fine;the big_imgloads and positions correctly, but, when i try to load icon_image the first big_img disappears! as if the new array has hasn't duplicated the original array (as if it's only a shortcut, not a real copy).
The cody thing:
ActionScript Code:
// total images read from XMLvar axiLength=Accessoir.length();// main image container arrayvar axxARR:Array = new Array();// add images to arrayfor (var k=0; k<axiLength; k++) { var axxLoader:Loader = new Loader(); axxLoader.load(new URLRequest(Accessoir.PHOTO.text()[k])); axxARR.push(axxLoader); axxLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, axxLoaded);}function axxLoaded(e:Event):void { // show big image if (axiLength==axxARR.length) { axxShow(0); }}function axxShow(ID_AXX:Number) { // duplicate images array var axxImage:Array=axxARR.concat(axxARR); // reposition it axxImage[ID_AXX].x = product_details_swf.axx.x+(axxImage[ID_AXX].width/2)-5.5; // Add init image to accessoires axxImage[ID_AXX].name="axxImage"; product_details_swf.axx.addChild(axxImage[ID_AXX]);}// here i got an event listner to a button, once rolle over is triged it // should make small copies of the whole array images and put them on stage//....function rollover_button(ID_AXX:Number) { for (var i=0; i<axiLength; i++) { axxCreate(i); } function axxCreate(ID_AXX:Number) { var axxPic:Array=axxARR.concat(); imageResizer(axxPic[ID_AXX], 50, 50); axxPic[ID_AXX].name="axxPic_"+ID_AXX; axxPic[ID_AXX].x=product_details_swf.axx.getChildByName("axxBG_"+ID_AXX).x+axxPicSpacingX; axxPic[ID_AXX].y=product_details_swf.axx.getChildByName("axxBG_"+ID_AXX).y+axxPicSpacingY; product_details_swf.axx.addChild(axxPic[ID_AXX]); }}
[MORE INFORMATION]
I tried array duplication using; concat and slice but not work, it doesn't creat copies of the orriginal array, but just a shortcut to it!
thanx for any tips!
Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...
ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.
the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...
is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?
any suggestions would be grand.
this is what i have on my controller clip:
onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}
Copying Loaded Array Into A Local Array
I'm loading an array through loadVariablesNum (into level 0). The script properly returns array values... I've checked by using text boxes on my stage. But, when I try to store the loaded array within a local Actionscript array for manipulation, it doesn't seem to be able to read the loaded values. It's as if the stage and the frame Actionscript were independent of each other. Can anyone help?
Thanks
Inserting An Array Into An Array To Make It Multidemensional
hi there,
Using an ASP script I've managed to get strings into flash
at the moment the strings come in like this:
array1=data1,data2,data3,data4,data5
array2=celeb1,celeb2,celeb3,celeb4,celeb5
currently I'm doing this:
webfoldercontents = new Array();
webfoldercontens = websubfolders.split(",");
which creats a 2d array. what I need is this:
multidemesionalarray = [array1[array2]]
any help v.appreciated!
Danny
Saving An Array Then Importing Saved Array?
I am creating a kids activity. At the moment I am working on the stamp tool that allws them to stamp a shape in different colours over the canvas... this is working fine, however I need to track the position and colour (and maybe more later) so that the child can save the activity and go back to it later.
So far I have managed to create an array for each propery (_x position, _y position and colour) in seperate arrays as a new stamp is attached it is given a number (1,2,3,4...) and in each array entry of that number are the position or colour properties. When I save these arrays (using FSCommand in Flash5) I think thay form a string in the text document.
When I loads the array from the text document, that looks like this:
&colourArray=255,255,255,16711680,16711680,1671168 0,16711680,16711680,16711680,16711680&XposArray=23 3,420.95,389,262,556.95,674.95,619.95,481.95,458.9 5,280&YposArray=109,167,313,211,301,158,80,105,174 ,451.95
I cannot pull out the data from the arrays (colourArray[2] traces as undefined) What I want to do is a loop based on the lenght of one the arrays that attaches the stamp MC in the correct position and colour.
Hope someone can shed light on this for me... I think I need to find a way to convert the text file data from a string to an array?!?
Cheers
Oll
Copying Array Inside Array Of Arrays
Hi,
I've got an array made up of other arrays, and I need to copy one of the arrays to a tempory array (so i can copy it)
I've tried using...
TempArray = ArrayList[0].splice();
but TempArray just shows (in debugger) as undefined, any idea's??
thanks
phil.
Tracing An Array :: Sending Array Through JS Proxy
Correct me if I'm wrong, but I thought when you traced an Array, the output was [object]. For example:
code:
var x = new Array();
x.push("one");
x.push("two");
x.push("three");
x.push("four");
trace(x);
Would output: [object Object], not the array as a comma delimited string, correct?
Having a problem where I'm passing an Array to a JS function throuh the JS proxy (flash-javascript kit) and JS picks it up as a string.
How To Duplicate Array?Array.slice() Can Not Work
I test it, and Array.slice() can not work.
var arNew:Array = new Array();
var arOld:Array = [
{checked:0},
{checked:0},
{checked:0}
];
arNew = arOld.slice();
for(var i = 0; i < arNew.length; ++ i)
{
arNew[i].checked = 1;
}
for(var i = 0; i < arOld.length; ++ i)
{
trace(arOld[i].checked);
}
It seems that "arOld" had been changed and "arNew" is not a copy of "arOld", but a reference of "arOld".
How should I copy a array?
thanks for any help
Given An Array Return An Array With Only Unique Elements
if i have an array of elements like 1,2,2,1,3,3,1,2,...
I want to return only
1,2,3
so to strip out duplicates, I thought this would be easy but its proving harder than I thought.
thanks
|