Array Values..HELP
I want to create a memory game, but i got stuck here:
on (release) { bricka=new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 ,19,20,21,22,23,24); for (i=1; i<13; i++) { arrayPos=random(bricka.length); frameNum=myArray[arrayPos]; _root[bricka(i)]=frameNum; myArray.splice(bricka,1); } }
the _root[bricka(i)]=frameNum; is wrong somehow. it set bricka[1]=2,bricka[2]=3,bricka[3]=4 and so on, instead of the random numbers that comes out from arrayPos.
what am i doing wrong ?
FlashKit > Flash Help > Flash General Help
Posted on: 02-06-2003, 03:04 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
[MX] Weirdness With Values Used By Array Populated Clip Values.
Hi,
I have used invisible buttons on top of some text, as part of a volume control interface.
The text buttons are set out as 0 – 25 – 50- 75 -100 referring to the % that a music tracks volume will change to once a button is pressed – so far so good.
Now to give values to the text buttons in order for them to make the text clip that they are on top of go to & stop & the right frame I have used arrays to give a reference the location of the text clip:
numbs_array = [_root.volHold_mc.vol0, _root.volHold_mc.vol25, _root.volHold_mc.vol50, _root.volHold_mc.vol75, _root.volHold_mc.vol100];
I then reference that in a home made “release” function as “this.monica.gotoAndStop(2);” “monica” being the reference to the address of the clip.
It all works fine except the code seems to make the movie play clips in an order that they have not been designated in the array – Like a button on top of the “25”% value will play the animation for the “75”% clip?
The whole problem is probably much better seen through the movie – the problem section of which i have attached below.
Database Values To Array Values
Hi all,
I've created a movie which uses a number of arrays to construct the elements of a flash-based gallery.
What I need is a practical method of getting values from a database into an array via an ASP page.
The plan was to load the variables into these arrays using the an asp page and a loadvars object to create a string (basically the array values in quotes separated by commas) which was then to be inserted into the parameters for the creation of the array. Needless to say this hasn't worked- the create array object seems to interpret the whole string as the first value in the array, i can't find a way of populating the array from just a single asp page.
I've given up with this method and really need a few pointers.
Thanks
Setting Array Values To Variables In Another Array
I have some variables created on the main timeline and a mc called options which will be where those variables can be manipulated.
A way I've tried to this is by creating a first array(array1) and populating it will all the variable names found on the main timeline, and another array(array2) containing the values of the variables the user has changed(which are displayed on some dynamic text fields). To make these changes, an "apply" button is pressed which will set the values found in array2 to the variables in array1.
So...
Code:
PHP Code:
//variables on the main or root timelinevar1 = 1; var2 = 2; //... //within options mc timelinearray1 = [var1, var2]; array2 = [var1Display, var2Display]; apply.onRelease = function() { //set values in array2 to variables in array1 and update the main timeline's variables//... }
How would you do this so that var1, var2... are updated properly according to the values found in array2?
And because array2 contains strings(read from dynamic textfields), how do you deal with that since var1 and var2 are numbers?
hope this all makes sense to everyone
Populate An Array Values From An Array
ok i have this xml file
Code:
<artworkinfo>
<movieinfo>
<artLocation>cover1.jpg</artLocation>
<movie>Live Free or Die Hard</movie>
<plot>John McClane takes on </plot>
</movieinfo>
<movieinfo>
<artLocation>cover2.jpg</artLocation>
<movie>Meet the Robinsons</movie>
<plot>Lewis is a brilliant inventor </plot>
</movieinfo>
</artworkinfo>
the xml will tell where the cover art is the movie title and plot.
i want to populate my movie with this info what is the best approach to create empty movieclips using actionscript or create individuals MC , i try the second one and create 4 movieclips (cause the xml have 4 elements just post 2) and make an array of mc but i can find how to match the xml array to the mc array , this is the code for better explaining,
Code:
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
movie = [];
plot = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
movie[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
plot[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
}
placeholder=new Array(loader1,loader2,loader3,loader4);
placeholder_total = placeholder.length;
for (e=0; e<placeholder_total; e++){
placeholder[e].contentPath=this.image[i];
}
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("movieinfo.xml");
the stage have 4 movieclips name loader1,loader2,ect... each mc have 2 dynamic text field one for title and one for the plot.
Add Up All Values In An Array
Hi there
I need a bit of help I am have loads of trouble adding all the variables
In an array together. I just not sure how to go about doing it.
I have try using a for loop but the out put does match up with the
To the total of all the values.
Code:
for (k=0; k<totalprice.length; k++) {
allprice = parseInt(totalprice[k-1])+parseInt(totalprice[k]);
}
I know there is some thing wrong with this code but I am not sure what
Think I’ve been looking at it for to long.
Hope you can help
Thanks
Mac-10
Array Values Into A For()
I'm trying to use the following values in a for so I don't have to type them out all the time.
But it ain't working [obvioulsy]!
Also I'd like to put it into a function so that I only have to type out the array values then call the function rather than repeating the for code all the time.
Any clues?
squares = Array("s2","s11","s19","s27","s30");
opacity = Array("15","22","40","17","12");
for (x = 0; x < squares.length; x++) {
_root.Grid[squares[x]].gotoAndStop(1);
setProperty(_root.Grid[squares[x]], _alpha, opacity[x]);
}
Array Values?
Hi,
I have two arrays which attach random movie clips to the stage. One array contains pictures and the other contains words. So for example the word array contains the words "apple" "dog" "cat" and the picture array contains pictures of an apple, dog and a cat. Ive got the movie clips to display randomly when you click a button, so a picture and a word displays at the same time.
Is it possible to assign a number to each item in the array, so for example the dogword = 1 and the dogpicture = 1
appleword = 2 and the applepicture = 2
catword = 3 and the catpicture = 3
so if the dogword and dogpicture are on the stage at the same time it is possible press a button to say that they match and then to add a point to the score?
Could anyone tell me if this is possible?
this is the code i am using to display my movie clips randomly
on (press) {
_root.blankpicture.attachMovie(_root.pic[random(3)], pic1, 0);
_root.blankword.attachMovie(_root.word[random(3)], word1, 0);
}
and then my arrays are:
pic = new Array ("applepic", "dogpic", "catpic");
word = new Array ("appleword", "dogword", catword");
I am using flash mx
thanks
Array Values
I am Using Flash MX 2004........
Ok i have an array with 4 elements wich are coordinates that i will be using for another function in my application.... they are as such
test[0]=12;
test[1]= 205;
test[2]=167;
test[3]=355;
now i have a function that will take the the array element values and do what they do with them.... for right now that function looks like this
function makeButton(x1,y1,x2,y2) {
trace(x1 + ", " + y1 + ", " + x2 + ", " + y2);
}
Now i know i can access the aray element values independently but i dont want to do that, what i want to do is concatenate the array and use its resulting string as the parameter values for the function when i call it....the Problem is it is not working and im not sure if can be done when ...I tried using test.join() and i also tried using test.toString() both of these output
12,205,167,355 which is exactly what i need to pass to my Function but even after setting a variable equal to these the output of the function is....
12,205,167,355, undefined, undefined, undefined.............. which means that the entire array.join() value is only being passed as the x1 value......Is there away around this? Help if you can...Thanks
Suzy
[F8] _x And _y Values From MC's In Array
Hi
I have created an Array with 5 duplicated movieclips. I am now trying to use the _x and _y values of these movie clips, but this value comes out as UNDEFINED. What am I doing wrong?!
Code:
for (var i:Number = 0; i < 5 ; i++) {
duplicateMovieClip(dot_mc, "dot_mc_" + i, this.getNextHighestDepth());
_root.dot_mc._x = Math.floor(Math.random() * Stage.width);
_root.dot_mc._y = Math.floor(Math.random() * Stage.height);
aDotArray.push("dot_mc_" + i);
trace(aDotArray[i]._x);
}
Array 2 Values
By any chance can I have 2 values per item?
line a name and a price?
Thanks
Array Values
Hi,
I have two arrays which attach random movie clips to the stage. One array contains pictures and the other contains words. So for example the word array contains the words "apple" "dog" "cat" and the picture array contains pictures of an apple, dog and a cat. Ive got the movie clips to display randomly when you click a button, so a picture and a word displays at the same time.
Is it possible to assign a number to each item in the array, so for example the dogword = 1 and the dogpicture = 1
appleword = 2 and the applepicture = 2
catword = 3 and the catpicture = 3
so if the dogword and dogpicture are on the stage at the same time it is possible press a button to say that they match and then to add a point to the score?
Could anyone tell me if this is possible?
this is the code i am using to display my movie clips randomly
on (press) {
_root.blankpicture.attachMovie(_root.pic[random(3)], pic1, 0);
_root.blankword.attachMovie(_root.word[random(3)], word1, 0);
}
and then my arrays are:
pic = new Array ("applepic", "dogpic", "catpic");
word = new Array ("appleword", "dogword", catword");
thank you.
Using Values From Array
ActionScript Code:
function setButtonDefaults(){
buttonPropertiesArr=["buttonOne``150", "buttonTwo``110", "buttonThree``128];
for(i=0; i<buttonPropertiesArr.length; i++){
var tempArr:Array = buttonPropertiesArr[i].split("``");
_root.tempArr[0].button_tpl_ins.outer._x=0;
_root.tempArr[0].button_tpl_ins.outer_orange._x=0;
_root.tempArr[0].button_tpl_ins.inner._x=0;
trace("arr length: "+buttonPropertiesArr.length+", arr: "+_root.tempArr[0]+", "+_root.tempArr[1]+", orange x: "+_root.tempArr[0].button_tpl_ins.outer_orange._x+", button: "+_root.tempArr[0]+", orange x buttonOne: "+_root.buttonOne.button_tpl_ins.outer_orange._x);
}
}
Ok, inside the function, for example:
tempArr[0] - traces as something valid
_root.buttonOne.button_tpl_ins.outer_orange._x - traces as something valid
_root.buttonOne.button_tpl_ins - traces as something valid
yet as soon as I replace a static value with an array value it becomes undefined:
_root.tempArr[0].button_tpl_ins.outer_orange._x - traces as undefined
_root.tempArr[0].button_tpl_ins - traces as undefined
I don't understand, and I don't know what to search for to find the answer...
Array Values
Hi everyone! I'm trying to assign values to my array. Here is what I have so far.
Code:
_root.createEmptyMovieClip("Placement", 2);
var shapes:Array = new Array("square", "circle", "triangle");
function selectshape():String {
//get the index for the letter
var index:Number = random(shapes.length);
//assign the letter to a var
var s:String = shapes[index];
//display letter
return s;
}
trace(selectshape());
//calls the function that will place the shapes on the stage
pulltogether(shapes);
function pulltogether(test:Array) {
for (var i = 0; i < test.length; i++) {
Placement.attachMovie(shapes[i], shapes[i], i+10, {_x:random(200), _y:random(200)});
}
}
What I want to do is say if "circle" is selected than I want to assign a value of "yellow circle".
Code:
if ("circle" ){
storedvalue="yellow circle"
]
else if ("square"){
storedvalue="blue square"
}
else if ("triangle") {
storedvalue="green triangle"
}
Hope this makes sense???
Array Values
I'm trying to load a random .swf into a holder .swf, basically a random ad on the screen. I'm attempting to do this by calling a random item from an array. I'm wondering if my new array is referencing the external .swfs (which are in the same directory) or if that is just some empty data that I created myself in flash. I'm pretty confussed on how all of this works and how to actually reference external assets like movies and images, in an array.
ActionScript Code:
productClip = new Array("catClip.swf", "QCClip.swf", "OPOSClip.swf");
productClip[0] = "catClip.swf";
productClip[1] = "QCClip.swf";
productClip[2] = "OPOSClip.swf";
function loadOne() {
loadMovie(productClip[random(2)+1], "_root.loadMC");
}
I'm not even sure if this is how I should go about doing this or if there's an easier way.
shagPun
Add Up All Values In An Array
Hi there
I need a bit of help I am have loads of trouble adding all the variables
In an array together. I just not sure how to go about doing it.
I have try using a for loop but the out put does match up with the
To the total of all the values.
Code:
for (k=0; k<totalprice.length; k++) {
allprice = parseInt(totalprice[k-1])+parseInt(totalprice[k]);
}
I know there is some thing wrong with this code but I am not sure what
Think I’ve been looking at it for to long.
Hope you can help
Thanks
Mac-10
Adding Values In An Array?
i have a bunch of numeric values in an array and i cant figure out how to add them up. What is the best way to go about this?
Dispaly All Values Of An Array?
i am storing all the characters entered by users into a textbox,into an array.Now i manuplate some of these(e.g changing case etc.) and again store these into new array ,how can i display all the values of this array(in a new dynamic text box) on click of a button?
Values Disappearing From Array
Hi,
i'm filling an array from a xml-file somehow like this:
Code:
[i]
_root.bild[i][j][2] = menuItem[i].attributes.name+"/"+subItem[j].attributes.url;
trace("Fotograf "+i+", Bild "+j+" = "+_root.bild[j][2]);
The trace-command at this stage shows the value alright, but some values seem to disappear from the array if I try to use it later.
The code is rather long, I posted the files here:
http://files.ueberland.net/array.zip
The relevant lines are from 134 to 224 - I'm traceing the actual problem there.
You can see in the output-window after the "where are they gone" that some values seem to have vanished.
Any help would be greatly appreciated.
PS: Isn't it a bit... odd to use []-brackets to format the forum-posts since it's the way you handle arrays in actionscript?
Assign Array Values
FLASH MX
hi, i have a problem about arrays...
i want to assign values to array elements through a .txt file, then load the .txt from the movie..
so it's like, i have created an array in the movie, then i would load the .txt using loadVariables
how should i assign values in text file??
can i assign it by using:
arrayA[0] = 0123;
arrayA[1] = 4567;
please help...
Array Values Into Variables
OK, so i have an array defined by a query to the database.
myEntry[][]
What i'm looking to do is define variables from the array using part of the array as the variable name.
ie:
myEntry[0][0] = myEntry[0][1]
The value stored in [0][0] should be the variable name and the [1] value needs to be set as the value of that variable.
Obviosly the above example would simply just redefine the array myEntry[0][0] - but how would I do what I'm trying to do?
Any clues?
many thanks!
Adding Values Box For Array
I'm looking for a way to add a "values" list box where users can enter values into an array.
What I'm looking for is the "values" list box that you get when you click on the magnifying glass in the components properties panel.
Any ideas as to how I can add this would be most appreciated.
Thanks.
Remove Values In A 3D Array?
Hey,
I'm not sure if 3D array is the right word... but whatever
Ok, I've got this array for my ISO-RPG-Game wich stores the tile-data:
Code:
map = [
[[6], [2], [2], [2], [2] ],
[[2,1,5],[2], [2], [3], [2] ],
[[2], [2], [2], [2], [2,1,4]],
[[2], [2], [5], [2], [2] ],
[[2], [3], [2], [2], [2], ]];
If a cell only consists of: [number], there's nothing special. It will just add a tile...
But if a cell says [number,number,number] there's something special going on. I shall explain the most left one: [2,1,5]
The first number (2) is just the tile, 2 stands for grass so it'll add a grass tile.
The 1 means an item should be placed on that tile.
The 5 means it's item number 5 that should be placed there.
Now when the hero picks up the item I want: [2,1,5], to be replaced with [2]...
I'm now using:
Code:
map[1][0][1] = null;
map[1][0][2] = null;
But when I then trace that part of the array it says: 2,null,null so the data is not realy removed...
So the question... how can I remove it?
How To You Reset Array Values
Hi everyone, im creating a game and i need to know how to reset Array values. I have a timer set so that my enemys are called every 5 seconds (just for testing purposes) but the problem is that their speeds keep on increasing each time the enemy code is called....
////////////////////
myInterval = setInterval(initCounter, 5000);
function initCounter(){
initEnemy2();
}
/////////////////////////////
function initEnemy2() {
Enemy2Array = new Array();
// start enemy1 at number 0
Enemy2Num = 0;
// create three large enemy2, 100%, at random locations
for (i=0; i<10; i++) {
enemy2 = newEnemy2(100);
enemy2MC._x = 400*Math.random();
enemy2MC._y = - 10;
}
}
function newEnemy2(size) {
// create a new enemy2
enemy2MC = attachMovie("enemy2", "enemy2"+Enemy2Num, 300+Enemy2Num++);
// random speed and direction
//enemy2MC.dx = 5*(Math.random()-.5);
enemy2MC.dy = 5*Math.random() + 1;
enemy2MC.dy = Math.round(enemy2MC.dy);
// move every 25 ms
setInterval(moveEnemy2,25,enemy2MC);
// store in array
Enemy2Array.push(enemy2MC);
return (enemy2MC);
}
function moveEnemy2(enemy2MC) {
// move enemy1
//enemy2MC._x += enemy2MC.dx;
enemy2MC._y+=enemy2MC.dy;
//trace(enemy2MC.dy)
for (var i = Enemy2Array.length-1; i>=0; i--) {
if (Enemy2Array[i]._y>=600) {
Enemy2Array[i].removeMovieClip();
Enemy2Array.splice(i, 1);
}
}
}
Selecting All Values Of An Array?
Is there a way that I can select all of the values of an array instead of just using one?Like, what I am using it for is that I have answers to a test, and I want all of the answers in the array:"ans" to be shown. Any help would be greatly appreciated!
Update Array Values?
maybe someone can solve this one too:
i have an array like this:
code:
for(i=0; i<ap.length; i++)
{
storePositions.push(this._parent._parent["mcItem"+i]._x)
}
now i want to update all the values with a value of +160
how can i do that?
Spliting Array Values
Hi
my problem is that i create an array consisting of external valuse. One of the array dimensions is made of xml element attributes which works dandy for all the later processing. But i am also trying to display each of the attributes on a list box for the user to see what is available.
this does work but atm says for example
wheels,steeringWheel,Brakes,Engine
instead of
Wheels
SteeringWheel
BRakes
Engine
this is the code
for (i = 0; i < myXML.childNodes.length; i++)
{
this[myXML.childNodes[i].nodeName] = new Object();
this[myXML.childNodes[i].nodeName].name = myXML.childNodes[i].nodeName;
this[myXML.childNodes[i].nodeName].isa = myXML.childNodes[i].attributes.isa;
this[myXML.childNodes[i].nodeName].has = myXML.childNodes[i].attributes.has.split(",");
parseArray.push(this[myXML.childNodes[i].nodeName]);
hasDisplay.addItem(myXML.childNodes[i].attributes.has.split(","));
} // end of for
where hasDisplay is the list box I dont really want to change the structure of the array because that is used later on and works fine just wondered if anyone knows how i could split the attribute values when it reaches a comma?
thanks.
[F8] Unique Array Values From XML
Hi everyone,
I'm trying to make a combo box display attributes from some XML, but unique values from my XPath array.
Here's my XML
PHP Code:
<?xml version="1.0" encoding="UTF-8"?>
<animations>
<animation link="1lat" key="none" label="Healthy">Whole Body (Healthy)</animation>
<animation link="2lat" key="mAct" label="Healthy">Leg Muscle Activation (Healthy)</animation>
<animation link="3lat" key="none" label="Healthy">Ground Reaction Forces (Healthy)</animation>
<animation link="4lat" key="jMoKey" label="Healthy">Joint Moments (Healthy)</animation>
<animation link="1post" key="none" label="Healthy">Whole Body (Healthy)</animation>
<animation link="2post" key="mAct" label="Healthy">Leg Muscle Activation (Healthy)</animation>
<animation link="3post" key="none" label="Healthy">Ground Reaction Forces (Healthy)</animation>
<animation link="pressurepoints" key="none" label="Healthy">Pressure Points (Healthy)</animation>
<animation link="1lat" key="none" label="Rheum">Whole Body (Rheumatoid Arthritis)</animation>
<animation link="2lat" key="mAct" label="Rheum">Leg Muscle Activation (Rheumatoid Arthritis)</animation>
<animation link="3lat" key="none" label="Rheum">Ground Reaction Forces (Rheumatoid Arthritis)</animation>
<animation link="4lat" key="jMoKey" label="Rheum">Joint Moments (Rheumatoid Arthritis)</animation>
<animation link="1post" key="none" label="Rheum">Whole Body (Rheumatoid Arthritis)</animation>
<animation link="2post" key="mAct" label="Rheum">Leg Muscle Activation (Rheumatoid Arthritis)</animation>
<animation link="3post" key="none" label="Rheum">Ground Reaction Forces (Rheumatoid Arthritis)</animation>
<animation link="pressurepoints" key="none" label="Rheum">Pressure Points (Rheumatoid Arthritis)</animation>
<animation link="vidLat" key="none" label="Healthy">Whole Body (Healthy)</animation>
<animation link="vidPost" key="none" label="Healthy">Whole Body (Healthy)</animation>
<animation link="vidLat" key="none" label="Rheum">Whole Body (Rheumatoid Arthritis)</animation>
<animation link="vidPost" key="none" label="Rheum">Whole Body (Rheumatoid Arthritis)</animation>
</animations>
and here's the AS Code that I thought would strip out the repeats:
PHP Code:
while (a < titleArray.length)
{
duplicateArray [a] = titleArray [a].attributes.label;
a ++;
}
for (i = 0; i < duplicateArray.length; i ++)
{
element = duplicateArray [i];
for (n = 0; n < duplicateArray.length; n ++)
{
if (element == duplicateArray [n] && n != i)
{
duplicateArray.splice (n, 1);
}
}
}
for (d = 0; d < duplicateArray.length; d ++)
{
content_mc.page3_mc.main_mc.condition_cb.addItem (duplicateArray [d]);
}
Is there a spelling mistake somewhere or something? I can't see one, and the code works partly, but in my comboBox I get Healthy, Healthy, Rheum. So something somewhere has gone wrong!
For Loop With Array Values
Ok, the issue is with the enabling of the buttons on my stage. I run a loop to deactivate them all when one is clicked, then I want to turn them back on, EXCEPT the one which was clicked. I thought I could start off with an array of MC names and simply delete them from the array. But I can't get my head around exactly how to read in the array contents as MC names...
Any help would be greatly appreciated.
Mike
PHP Code:
//declare the team variables
var TeamA:Number = 0;
var TeamB:Number = 0;
var btns:Array = Array("btn1", "btn2", "btn3");
disableBtns = function () {
for (var i = 1; i<=3; i++) {
this["btn"+i].enabled = false;
}
};
//////////////////////////////////////
enableBtns = function () {
for (var i = _root.btns; i<=_root.btns.length; i++) {
this[i].enabled = true;
}
};
Displaying Values Of An Array
Hi all,
Hope you can help me, I think this is a simple one but I cant figure it out.
What I need to do is display the last element, the second last element and the third last element of an array in dynamic text boxes that have variables numbercalled1, numbercalled2 and numbercalled3. The Array is always changing so this is what I have come up with am I doing something simple wrong??? usednumbers is the array that I want to pull the values from.
mary = usednumbers.length
mary2 = usednumbers.length-1
mary3 = usednumbers.length-2
numbercalled1 = usednumbers.toString([mary]);
numbercalled2 = usednumbers.toString([mary2]);
numbercalled3 = usednumbers.toString([mary3]);
Will this display the elements as I have discribed or am I going about this all wrong. I cant use the pop method as I dont want to change that array but just display the elemants in the text boxes.
Also is there any way that I can do this with usednumbers.slice()
Thanks for your help.
Showing Values Of An Array
Hi all,
I am working on a movie with a timer, each time the viewer goes to the next page the time gets recorded to a variable (timer_txt) - I have made an array with timer_txt and page_txt (number of page they are on) - I'd like to show the data somehow (new text filed, or xml file, ...anywhere) - like in the output window.
here is my array code:
timeSpent = new Array();
timeSpent[0] = timer_txt;
timeSpent[1] = page_txt;
trace(timeSpent.join(" on pages "));
Thanks for any help - I've looked through tutorials, library and the forums...
Anna
Array Values Linked
I have a situation where I am assigning one array to a new variable. for some reason any changes made to the new array, in this case newPortfolio, are carried through to the array that was assigned to it(portfolio). In other words changing a value in newPortfolio, changes the same value in the original portfolio. Why are these arrays linked? There are Arrays of Objects if that makes any difference. Please advise.
Code:
var newPortfolio:Array = portfolio;
formatNewPortfolio(newPortfolio); //changes values in newPortfolio, also changes the values in portfolio
Adding Values To The Array
Hi, I m new to actionscript-forum. though i have been using the tutorials for past 2 years.
I would like to have some help, that is, i have a array called storeArray. when i click on a word say Tree, it should check in storeArray. If the word doesn't exists, then it should save in that array. else it should give a message saying the word already exists.
Thanks. You help will be appreciated.
mach1
Increment Array Values
hello my friend,
if var array:Array = new Array(); is defined on the root timeline and i = 1, is is there a difference between
array[1] =2000;
and
_level0[array[i]] = 2000;
??
i am noticing that when i set _level0[array[i]] = 2000, the values for all of my array[] indices = 2000
specifically my problem is herein:
for(i=0; i<40; i++){
if(this.hitTest(_level0["gunk"+i+"_mc"])){
_level0[hitCount[i]]++;
if((_level0[hitCount[i]] > 20)){
new mx.transitions.Tween(_level0["g"+i+"_mc"], "_alpha", Strong.easeOut, 25, 0, 1, true);
_level0[hitCount[i]] = 2000;
}
if(_level0[hitCount[i]] == 10){
new mx.transitions.Tween(_level0["g"+i+"_mc"], "_alpha", Strong.easeOut, 50, 25, 1, true);
}
if(_level0[hitCount[i]] < 1){
new mx.transitions.Tween(_level0["g"+i+"_mc"], "_alpha", Strong.easeOut, 100, 50, 1, true);
}
}
}
// So if hitCount[i] > 20, I want to set its value to 2000, so that it's alpha value will not change anymore. But when I set a value to 2000, hitCount[i+1] also equals 2000. I don't want that to happen. What am I missing here?
Thanks
Pushing XML Values Into An Array...
I need to push values from an XML file into the array. The problem is there may be 2-6 possible values... for example:
Code:
<options>
<option1>here's the first one</option>
<option2>here's the second one</option>
<option3>here's the third one</option>
</options>
but there could be 2, 4, 5, 6, etc. options in the <option> area.
I'm using this tutorial to create a quiz, but modifying it to load the data from XML: Create a Quiz Application Using AS3 Classes
In the tutorial the quiz pieces are pushed into an array like so:
Code:
quizQuestions.push(new QuizQuestion("What color is an orange?",
1,
"Correct",
"Incorrect",
"Orange",
"Blue",
"Purple",
"Brown"));
The first 4 things are easy to push in from my XML document:
Code:
quizQuestions.push(new QuizQuestion(quizXML.quiz.items.question[i].question,
currentCorrectAnswer, //CORRECT ANSWER
quizXML.quiz.items.question[i].correctFeedback,
quizXML.quiz.items.question[i].incorrectFeedback
//CHOICES SHOULD GO HERE
));
But I don't know how to push the choices into the array because it could be as many as 6 to as few as 2... how would I go about this? I don't need exact code, just an idea, but code can help for an example...
Adding Values Of An Array
How would I add the values of an array?
Example if the values of an Array were (50, 40, 20, 60);
how would I add those numbers to get their total?
Is is possible to display the value of the deleted item in an Array?
Example if the original values of an Array were (50, 40, 20, 60), and I used the splice method to delete 40 from the array, is there a way to display the 40 in a text box or use that value in a method?
Thanks
Import Array Values From Php
how can i take the array video.list and import the values from php
Code:
myVideo.contentPath = "firstvideo.flv";
// Set Videos Behavior
// Create a videos object to hold a video
// playlist and event handler functions...
var videos:Object = new Object();
// Set up to 7 video feeds in a single component
videos.list = new Array();
videos.list[0] = "italian.flv";
videos.list[1] = "junction.flv";
videos.list[2] = "ejn.flv";
videos.list[3] = ""; //you don't have to use them all. You can do up to 7
videos.list[4] = "";
videos.list[5] = "";
videos.list[6] = "";
videos.loop = true;
videos.length = 1;
videos.loaded = false;
// Path to FLVPlayback components
var m = this.myVideo;
// Set the path of the first video feed
m.contentPath = videos.list[0];
// Set a 'ready' event handler to load the videos
videos.ready = function( evt:Object ):Void
{
if(!this.loaded){
this.loaded = true;
for( var n=1; n<this.list.length; n++ ){
if( videos.list[n].indexOf(".flv") != -1 ){
m.activeVideoPlayerIndex = n;
m.contentPath = videos.list[n];
this.length++;
}
}
m.activeVideoPlayerIndex = 0;
}
}
m.addEventListener("ready",videos);
// Set a 'complete' event handler to load the next video
videos.complete = function( evt:Object ):Void
{
var nextIndex = Number(evt.vp)+1;
if( nextIndex == this.length){
if( this.loop ){
nextIndex = 0;
}else{
return;
}
}
m.activeVideoPlayerIndex = nextIndex;
m.visibleVideoPlayerIndex = nextIndex;
m.play();
}
m.addEventListener("complete",videos);
// End Set Videos Behavior
LoadMovie Using Array Values
I am trying to load a jpg into a blank movie clip using the value of an array but can't make it work. The movie is just 1 frame in total.
My code looks like this
In my actions layer I set the Array and values
var players = new Array();
players[0] = "blake.jpg"
players[1] = "ferrero.jpg"
players[2] = "gasquett.jpg"
players[3] = "hass.jpg"
players[4] = "henman.jpg"
players[5] = "hewitt.jpg"
players[6] = "roddick.jpg"
players[7] = "safin.jpg"
stop();
Within a blank movie clip with the instance name of player1 I have the code
onClipEvent (load) {
loadMovie(players[0],"player1"));
}
This does not throw up an error but at the same time it does not load in the jpg as I expected. The image is in the same folder as the swf so it should be able to see it.
I also did a trace for the array value within the movie clip instance and it came back undefined.
Please help!
Array Values Looping
Ok heres what im trying to do:
Thes + and - buttons next to a stake box, an array called incrementArray which contains 26 values i.e. 0.10 , 0.20, 0.30 , now what im trying to do is code it so that when the button is pressed either + or - , and the user has entered a value in the box, the value is checked and the incrementor starts so that the 1st value is higher than the one in the box, or lower is the decrementor is pressed instead of blindly starting from 1 no matter what is entered.
Example:
what i want:
I enter £1.00 into box, press + button. amount goes upto £1.50
At the moment:
I enter £1.00 into box, press + button. amount goes to £0.10 ( the first array value)
box is called = root.mainWin.betWin.pBet0
array is called = incrementArray
This is only the increase stake function , once the code is done for this its just a case of copy +past into decrease stake function.
function increaseStake()
{
// loop through array values
for (i=0;i<_root.incrementArray.length;i++)
{
// trying to check that the current array value is lower than the stake box
//amount and that the next array value is higher than the stake box amout.
//in which case the next value should be used as the 1st increment value.
if (_root.mainWin.betWin.pBet0>_root.incrementArray[i] && _root.mainWin.betWin.pBet0<_root.incrementArray[(i+1)])
{
// set stakebox to = the array value which is more than the current stake
_root.mainWin.betWin.pBet0 =_root.incrementArray[(i+ 1)];
}
}
--------
thanks
-arran
Concatenate Array Values
Hi all,
Like the subject says, I'm having trouble concatenating array values in the scope chain, or whatever the heck you call the path to you object (I'd love to know what it's called so I don't look like an idiot when I try to ask questions).
You can see in my code example what I'm trying to do. I've tried it a couple of ways, sort of fumbling around ignorantly. Then I figured I'd just cheat, and turn the array values that I want to concate in to variables, but those variables give me the same undefined. Please help!
ActionScript Code:
function tabRollOver(){
tabPartsArr=["tabCenter``center", "tabCutLeft``cutLeft", "tabLeft``left", "tabRight``right"];
for(i=0; i<tabPartsArr.length; i++){
var tempTabOverArr:Array = tabPartsArr[i].split("``");
temp1=tempTabOverArr[0];
temp2=tempTabOverArr[1];
trace("Before onEnterFrame: "+temp1+", "+temp2); //variables are good but...
trace("Before onEnterFrame: "+temp1.temp2); //they just don't work here, undefined
this.onEnterFrame = function(){
//would prefer to work it similar to below, instead
//of making extra variables for no reason.
trace("got tabRollOver, this: "+this+", arr pieces: "+this[tempTabOverArr[0]]tempTabOverArr[1]);
//thought I was tricky here, but still undefined.
trace("got tabRollOver, this: "+this+", arr pieces: "+this.temp1.temp2);
if(this[tempTabOverArr[0]][tempTabOverArr[1]]._alpha > 0){
this[tempTabOverArr[0]][tempTabOverArr[1]]._alpha -= 5;
trace("alpha change: "+this[tempTabOverArr[0]][tempTabOverArr[1]]._alpha+", ");
}
}
}
}
Update Array Values?
maybe you can solve this one too:
i have an array like this:
ActionScript Code:
for(i=0; i<ap.length; i++)
{
storePositions.push(this._parent._parent["mcItem"+i]._x)
}
now i want to update all the values with a value of +160
how can i do that?
Load XML Values Into An Array
Hi,
I am having problems loading XML values into an array, here is my code:
var budgetImpactValues:Array = new Array();
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(success) {
if (success) {
importData();
trace(budgetImpactValues.value.toString());
} else {
// error
}
};
myXML.load(mdm.Application.path+"myFile.xml");
function importData() {
for (n=0; n<myXML.firstChild.childNodes.length; n++) {
var value = myXML.firstChild.childNodes[n].firstChild.nodeValue;
budgetImpactValues[n] = value;
}
}
When I attempt to do a trace on budgetImpactValues, I get undefined, however if I do the trace from within the function the values are there, can anyone see what I am doing wrong here please?
Thanks for your advice
Comparing Array Values
I have an Array with the following values : MyArray(1,2,3,4,5,6);
I need to compare 1 of the values inside MyArray in a if-else statement.
Example :
arrayValue = MyArray.splice(0,1);
if (arrayValue == 1) {
//do something
}
But this comparison doesnt work .. how can i compare the value in the array ..
i need that value to do something...
Anyone can help ? Thanks~
How To Get Dynamic Array Values
i am wanting to display the names of the tracks in a folder on the server for my mp3 player. I do not want to populate the array manually... so here is my code i am trying to work with.
var musicFolder:String = "http://www.kirupa.com/tutorials/";
var tracksArray:Array = new Array(musicFolder.length)
trace(tracksArray.name[0]);
in the trace.. i want to display the "name of the file"....
thanks everyone.
Delete Array Values, How?
hi folks,
ive got a little problem...
lets say i have an array called numbers with these values: 0,1,2,3,4,5,6,7,8,9,10
i want to call a random number of that array, something like this:
ActionScript Code:
rand = Math.round(Math.random()*(_root.numbers.length-1)); no = numbers[rand];
then when ive got my value (no) i want to delete it from the array... and thats the problem... i tried to convert the array to a string and then slice it up... but because the '10' has 2 characters it all goes wrong... this is the code i've got sofar and i would really appreciate it if you can help me further...
ActionScript Code:
numbers = 11;answers = new Array();for (i=0; i<11; i++) { answers.push(i);}Array.prototype.shuffle = function() { this.sort(function () { return random(2); });};answers.shuffle();function bla() { rand = Math.round(Math.random()*(_root.answers.length-1)); no = answers[rand]; str = answers.toString(); pos = str.indexOf(no); begin = str.slice(0, pos); end = str.slice(pos+2); newstr = begin.concat("", end); if (answers.length<1) { trace("that's it"); } trace(begin + " -- " + no + " -- "+ end); answers = newstr.split(",");}
Update Array Values?
maybe someone can solve this one too:
i have an array like this:
ActionScript Code:
for(i=0; i<ap.length; i++){ storePositions.push(this._parent._parent["mcItem"+i]._x)}
now i want to update all the values with a value of +160
how can i do that?
Getting Values From A Multidimensional Array
Hi all,
This question may get pretty long winded but if you could help me, it'd be much appreciated because I'm really struggling with this piece of actionscript!
Basically I'm trying to create a quiz, and I thought the best way to do this would be to create a form based flash ap, which loads the questions and answers from an xml file.
Once I've loaded the xml file I want to put it's contents into an array, so I can extract questions/answers/alternate answers etc from it with greater ease than with xml.
It's at this point I'm really struggling. I get no compile time errors and when I run the file it seems to put all the values into their arrays and these arrays into other arrays. But once I'm outside of this storing loop all of the values have gone. Now I'm pretty sure this isn't down to a typo (If it is, I swear I'll go crazy!)
I figure it's best to give some code.. so here goes:
the XML I'm using looks something like this:
Code:
<scenario title="Scen A" name="Tom">
<question><p>How many roads does..</p></question>
<answer correctAns="2"><p>The correct answer is..</p></answer>
<altAnswer altselection="3"><p>I dunno</p></altAnswer>
</scenario><scenario title="Scen B" name="Bob">
<question><p>Meaning of Lifep></question>
<answer correctAns="2"><p>42 isn't it?</p></answer>
<altAnswer altselection="3"><p>Maybe it was 43?</p></altAnswer>
</scenario>
and the actual actionscript which is trying to rip all that apart is this:
Code:
var answers:XML = new XML();
answers.ignoreWhite=true;
answers.load(xml);
answers.onLoad = function(sucess:Boolean):Void {
if (sucess == true) {
var scenarios:Array = new Array();
for (var i:Number=0; i<this.childNodes.length; i++) {
var secondLvlData:Array = new Array();
//This for loop will pull attributes from top level nodes (Scenario nodes)
for (attr in this.childNodes[i].attributes) {
secondLvlData[attr] = this.childNodes[i].attributes[attr];
}
//This for lopp will pull data from 2nd level nodes (question, Answer, Alt)
for (var j:Number=0; j<this.childNodes[i].childNodes.length; j++) {
var thirdLvlData:Array = new Array();
for (attr in this.childNodes[i].childNodes[j].attributes) {
thirdLvlData[attr] = this.childNodes[i].childNodes[j].attributes[attr];
}
thirdLvlData[this.childNodes[i].childNodes[j].nodeName] = this.childNodes[i].childNodes[j].firstChild;
}
//none of these traces work!
trace(secondLvlData)
secondLvlData["data"] = thirdLvlData;
trace(secondLvlData["Data"]);
scenarios.push(secondLvlData);
}
} else {
trace("Loading of xml file failed");
}
};
I'm really sorry it's such a beast of a question, but if anyone can give me any pointers it'd be greatly appreciated!
Cheers,
daf
Convert Certain Xml Values Into An Array
hi all,
another quick question:
how can I assign certain values from an XML document to an array?
e.g., when I trace 'myXML.firstNode.firstNode', I get:
Code:
INTRODUCTION
ABOUT
WORK
CONTACT
Except, is it possible to convert each one of those values to a new avlue in an array so the array would look like this:
Code:
(INTRODUCTION, ABOUT, WORK, CONTACT)
Thanks again.
|