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




Adding Quotations To An Array



Hi,

I have an admin system that creates the following array in an XML file.

(valueOne, anotherValue, something else, another)

I need to take those values and add them to a combo box. However they first need to be converted to be:

("valueOne", "anotherValue", "something else", "another")


Is there a simple way I can take the values of an array and convert them to be comma delimitated and in quotations ?


Thanks
Stephen



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 11-13-2008, 05:10 PM


View Complete Forum Thread with Replies

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

Random Quotations
I want to write a script that loads in a random quotation on every new visit to the page. My first thought was to create an array with all the quotes and use the Math.random function to load a different quote on each new page load.

However, I'm not quite sure on the best way to extract an element from the array and pass it to the textfield.

I'm using Flash MX 2004, AS 2.0.

Can anyone offer any help? Or possibly suggest an alternative solution?

Thanks

Various Quotations In Random Order?
Hi again...

I would like to have an ongoing 'movie' on my flash site where various quotations are displayed in random order. (So that you don't get the same quote every time you visit).

Any ideas on how to do this? Is it too complicated for a newbie like me?

Much thanks!

FlashVars And Quotations, A Question
I use FlashVars for a site but they occationally contain quotation marks I know that I can use the URL type coding but this is not always an option is there anyway to allow quotation marks in my FlashVars.

Quotations In Action Script Text Ack
I am trying to utilise an image scroller, yet when I use action text that has quotes in it I get errors as it signifies something to the script..
ie:

_level0.masker.contentText:contentText = " he said,"what the heck is going on" , he shrugs and tries the board";


anybody know a solution?

Quotations In Dynamic Text Fields...
alright... they don't show up when loading an external text file... i've embeded everything... to i need to replace all the (")'s with a code or something? and if so can someone out there post a link? thanks

When I Put Quotations Marks ", He Chokes
I have in my flash some animation with MCs and dynamic filds, I am pulling some texts from my PARAM in the HTML, and he works normal, but now I got some problems.
The first Product in de PARAM from my HTML I have this (NOVO+Produto+1+")
when I put quotations marks ", he stop de animation from my MCs, it does not bring the outhers texts, he chokes.
I try to put quotations marks ", dynamic text "Character" but nothing.
I have this in my PARAM HTML.

Code:
'barra17?i1=imagemVertical&t=Destaques&n1=NOVO+Produto1+"&n2=Descrição.......'
Somebody knows because it does not appear the quotations marks ", or somebody knows what I have that to do for he works.

Sorry about my English.

Double Quotations: Escape Character For Xml?
I'm pretty new to xml concept. Anyway I was playing around with xml/flash and thought of use the double quotations with escape character to see the effect something like this xml file: example="blah blah blah "blah" and example='blah blah blah's blah' but Flash seem doesn't support the escape method. Is there any method that flash/xml will support the escape character?

Thanks,

jace

When I Put Quotations Marks ", He Chokes
I have in my flash some animation with MCs and dynamic filds, I am pulling some texts from my PARAM in the HTML, and he works normal, but now I got some problems.
The first Product in de PARAM from my HTML I have this (NOVO+Produto+1+")
when I put quotations marks ", he stop de animation from my MCs, it does not bring the outhers texts, he chokes.
I try to put quotations marks ", dynamic text "Character" but nothing.
I have this in my PARAM HTML.

Code:
'barra17?i1=imagemVertical&t=Destaques&n1=NOVO+Produto1+"&n2=Descrição.......'
Somebody knows because it does not appear the quotations marks ", or somebody knows what I have that to do for he works.

Sorry about my English.

Dynamic Text Box - Useing Quotations Within
I have problem and didn't know if there was a simple solution. I would like to use AS to fill the contents of a dynamic text box but I want to include quotations. such as

mytext.text = " The man said "Howdy."";

but of course the quotes cause problems with that. I know I could call an external text file to do this, and perhaps even use a variable that has a value of a " but didn't know if there was something obvious I was missing.

Thanks!

Double Quotations: Escape Character For Xml?
I'm pretty new to xml concept. Anyway I was playing around with xml/flash and thought of use the double quotations with escape character to see the effect something like this xml file: example="blah blah blah "blah" and example='blah blah blah's blah' but Flash seem doesn't support the escape method. Is there any method that flash/xml will support the escape character?

When I Put Quotations Marks ", He Chokes
I have in my flash some animation with MCs and dynamic filds, I am pulling some texts from my PARAM in the HTML, and he works normal, but now I got some problems.
The first Product in de PARAM from my HTML I have this (NOVO+Produto+1+")
when I put quotations marks ", he stop de animation from my MCs, it does not bring the outhers texts, he chokes.
I try to put quotations marks ", dynamic text "Character" but nothing.
I have this in my PARAM HTML.

Code:
'barra17?i1=imagemVertical&t=Destaques&n1=NOVO+Produto1+"&n2=Descrição.......'
Somebody knows because it does not appear the quotations marks ", or somebody knows what I have that to do for he works.

Sorry about my English.

Adding To An Array
If I was making an array that held size, xpos, and ypos.
my question is how to load it.
sdot=newArray();
//code;
sdot[i] =(xsc,xpos,ypos);

Thanks

Adding To An Array
I have an array full of numbers...


build = new Array(2, 0, 1, 0, 2, 0, 2, 0, 1, 0, 2, 0, 2, 0, 1, 1, 2, 0, 2, 0, 1, 1, 2, 0, 2, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 2, 0, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0, 2, 0, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0, 2, 0, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0)

and if I want to add a set of number (according certain rules.. ) to this existing array example.... 2, 0, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0 to make...

build = new Array(2, 0, 1, 0, 2, 0, 2, 0, 1, 0, 2, 0, 2, 0, 1, 1, 2, 0, 2, 0, 1, 1, 2, 0, 2, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 2, 0, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0, 2, 0, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0, 2, 0, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0, 2, 0, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0)


how would i do this.. whats the syntax... to add numbers to the end of an array...

[HELP]Adding An Array To Another
How do you add an array to end of a previous array? I'm pretty sure I've seen it somewhere but I can't find it. I want something different from concat(), I want to just add to one array, not make a new one.

Adding To An Array?
Hi
I have an array named "numbers" and I want to add to one of the values inside it.
It looks like this originally:
numbers = ["25", "10"];
and I want to add a variable from a input text box called "txtbox"
but when i use:
numbers[0] = numbers[0] + txtbox
and i put 22 in the txtbox, numbers[0] = 2522
How can I actually add the numbers together rather than put them after each other?

thanks

Adding Up A Array
Trying to add up all the quantities in the array, it looks like it should work but it does not.


Code:
totalQty += aItem[i].quantity;
trace(totalQty);


trace come bask as null

Must be something I overlooked but what, any ideas?

Adding To An Array
this doesn't work (nothing gets added to the array):

array += i;


this also doesn't work (i get NaN for the index):

var a;
a += i;
array = a;


can you see where i'm going with this? how do i achieve it?

Adding To A 2d Array?
How do I do this? I just want to be able to access its contents by array[x][y], but apparently that doesn't work for setting them, only reading. Anyone know?

Adding To An Array
This is sort of a snippet of my initial question, but I have a slider and I want to capture it's location in an array every time it's moved. So, eventually, I can have an mp3 or flv file play and when the user moves the slider, i can get the info like [ slider=60 mp3time=00:15 ] Where the slider would be a rating scale - the user took it up to 60 at 00:15 into the mp3. Please help!

Help With Adding To An Array
Agian im asing for help but this is what we all are here for right? Anyway, I have an array

inventory = [];

I add to the array by clicing on the item and changing the ID to what the item is.

_root.ID="Axe";

Then I enter an amount in which to buy

_root.amount=_root.amount_mc.new_amount_txt.text;

How to I add my ID into the array as many times as I have in the amount.

Adding To An Array
I can’t figure this out. I have an XML document that I want to use to add a changeable list. When you click on the button I want the first list to disappear and the new one to be put in its place.

This is the XML:

PHP Code:



<?xml version="1.0" ?><presentation skin="skin2.png"><modules> <module type="Introduction"><title>This is experimental and I am so getting it!</title><bullets ><bullet>bullet 1</bullet><bullet>bullet 2</bullet><bullet>bullet 3</bullet><bullet>bullet 4</bullet><bullet>bullet 5</bullet><bullet>bullet 6</bullet></bullets></module><module type="Introduction"><title>text 2 in da hizzy</title><bullets ><bullet>second tier</bullet><bullet>second tier</bullet><bullet>second tier</bullet><bullet>second tier</bullet><bullet>second tier</bullet><bullet>second tier</bullet></bullets></module> <module type="Introduction"><title>text 2 in da hizzy</title><bullets ><bullet>third tier</bullet><bullet>third tier</bullet><bullet>third tier</bullet><bullet>third tier</bullet><bullet>third tier</bullet><bullet>third tier</bullet><bullet>third tier</bullet></bullets></module> </modules></presentation>




This is the as:

PHP Code:



var nodes:Array = new Array();var bulletPlace:Array = new Array();var pound:Array = new Array();var j:Number = 0;/////////var my_xml:XML = new XML();my_xml.ignoreWhite = true;my_xml.onLoad = function() { ///parent node nodes = this.firstChild; bulletPlace = nodes.firstChild.firstChild.childNodes[1].childNodes; for (j=0; j<bulletPlace.length; j++) {  pound[j] = attachMovie("bulletedText", "clip"+j+"_mc", j, {_y:(j*30), _x:20});  pound[j].listerTxt.text = bulletPlace[j].childNodes;  pound[j].listerTxt.autoSize = "left"; }};my_xml.load("lesson2.xml");////////////////////rv.onRelease = function() { //what am I missing?};///////////////////  fw.onRelease = function() { //what am I missing?}; 




As you can see I have one node called “bullets” in each of the three nodes called “module”. I want to have the first set of bullets placed in dynamically created clips on the stage and when I press the next button I want that list to be replaced with the next one.

I have attached the fla and xml.

I have been banging my head against the wall with this for a while now. Any help at all would be greatly appreciated!

Thank you.

Adding To A 2d Array?
How do I do this? I just want to be able to access its contents by array[x][y], but apparently that doesn't work for setting them, only reading. Anyone know?

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?

Adding Total Of Array
hi,
how do I find out the total sum of an array?
say for example: say myarry had the vaules 2,5,3 stored in it, how do I find the total (eg 10) ....not the length (eg 3)


thanks,
Kaan.

Adding An Array To A Function ?
Hello,

I am trying to dynamically code a dart game. I have the main function that will determine score based on mouse click right now. I cannot seem to understand how to add an array of 3 darts into where the distance is determined by mouse click. This is the variable that sets the distance....

var distx = board._xmouse;
var disty = board._ymouse;

I have an array of 3 darts. How can I add this array to the distance variable in place of mouse coordinates?


Code:
myDart = new Array();
myDart[0] = _root.dart1.anim1.hit1;
myDart[1] = _root.dart2.anim2.hit2;
myDart[2] = _root.dart3.anim3.hit3;
for (i=0; i<3; i++) {
for (var i = 1; i<=3; i++) {
myDart[i-1] = _root["dart"+i]["anim"+i]["hit"+i];
}
}
somehow needs to take the place of var distx and var disty


Code:
function land() {
if (dartNum>3) {
newTurn();
}
dartNum++;
var distx = board._xmouse;
var disty = board._ymouse;
var dist = Math.sqrt(distx*distx+disty*disty);
var angle = Math.atan2(disty, distx)*180/Math.PI;
if ........................

Thx for looking
~GD~

Adding Data To An Array
If you have an Array that looks like this for example:

Code:
name_of_array = ["value1","value2","value3"];
What kind of code would you use to add another value. I'm kind of aware of the "push" but lets say I want to add this value somewhere on the timeline. What would the code be on the timeline so that when that instance happens it puts it into my Array? Any thoughts?

Adding To A Blank Array
alright, what I'm making is a level editor, and i've got the block placement onto a grid working, but then I can't add which block is where to an array.

I've got this code to find out which cell the block is put in:

xspacing = 75;
yspacing = 20;
xpos = _xmouse-61;
ypos = _ymouse+312.95;
row = Math.ceil(xpos/xspacing);
column = Math.ceil(ypos/yspacing);

So that gives me the row and column the block is put in. Heres the next bit of code.

map[column][row] = blockplaced;

I set up map as a new array earlier, and blockplaced is just a value from 1-3. But when I do trace(map); all I get is a blank line in the output window. My question is how to correct this so that it displays the correct blockplaced number into my array.
Thanks in advance.
I'm using flash MX

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.

Adding Objects To An Array
Hi

I'm trying to create a 2 dimensional array where each value is within 2 objects. I want to access the final thing like this:

foo = grid[i][j].book.title;
bar = grid[i][j].car.colour;

What I don't want to do is access it like this:

foo = grid[i][j][k][l];

I've tried:
grid[i][j].book = new Object();
grid[i][j].book.title = new Object();

Adding Array To Preloader
Hello,I have a standared bar perloader witch im having troble adding a array to it so I can dynamicly load some images.

Preloader Script

Frame 1:
isDemo = false;
iDemoCount = 0;

Frame 2:
if (isDemo == false) {
iFileLoaded = _root.getBytesLoaded();
iFileSize = _root.getBytesTotal();
}
if (isDemo == false) {
iPercentLoaded = Math.round((iFileLoaded/iFileSize)*100);
} else {
iPercentLoaded = iDemoCount;
iDemoCount++;
}
pBar._xscale = iPercentLoaded;
sStatus = iPercentLoaded add "%";

Frame 3:
if (iPercentLoaded == 100) {
gotoAndPlay(_currentframe+1);
} else {
gotoAndPlay(_currentframe-1);
}
stop();
_root.play();


This is my image array script:

var imageArray = new Array();
imageArray.push("images/1.jpg");
imageArray.push("images/2.jpg");
imageArray.push("images/3.jpg");
imageArray.push("images/4.jpg");
imageArray.push("images/5.jpg");
imageArray.push("images/6.jpg");
imageArray.push("images/7.jpg");
imageArray.push("images/8.jpg");
imageArray.push("images/9.jpg");
imageArray.push("images/10.jpg");
imageArray.push("images/11.jpg");
this.createEmptyMovieClip("container", 0);
container._visible = true;
container._x = 0;
container._y = 123.4;
for (var n =0; n<imageArray.length; n++) {
var thisImage = container.createEmptyMovieClip("image" + n, n);
thisImage.loadMovie(imageArray[n]);
}

How Would I go about combining the two ?

Also the image gallery I set up uses a sliding nav where images get drawn in to MC's using the loadMovie() action. the images load into "container" fine but are still lagey when loading into the seperate littel MC's

take a look at what I have http://www.shmooze.ca/newnight/test2.htm

2d Array Adding Rows
Using Flash 8:

How do I insert a row into a 2d array? I want to keep the same amount of rows, but just have them move down one row, get rid of the last row, and add the new one to the top.


Code:
_root.ballIndex = 0;
Mouse.hide()
map = [["0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0"],
["k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k"],
["0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0"],
["k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k"],
["0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0", "k", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]];

trace(map[0].length);
var mapheight = map.length;
var mapwidth = map[0].length;
var i = 0;
while (i<mapheight) {
var j = 0;
while (j<mapwidth) {
if (map[i][j] == "k") {
_root.ballIndex = _root.ballIndex+1;
randomnumber = Math.floor(Math.random()*6);
randomnumber++;
_root.attachMovie("ball"+randomnumber, "ball"+_root.ballIndex, _root.ballIndex);
_root["ball"+_root.ballIndex]._x = j*11.5+113;
_root["ball"+_root.ballIndex]._y = i*-21+335;
map._y = map._y=100;
}
++j;
}
++i;
}
I would like to eventually add a timer, so after every 30 seconds a row would be added to the top and the rest would move down, keeping the same amount of rows. This is for a game similar to "Bust-A-Move" if anyone is wondering my intentions with it.

Thanks

[F8] Adding A Multidimensional Array Together?
I've got a m.d array which I am filling with values. Is there a quick way to add up every item? Maybe a function built in?

Adding A Loop To This Array
Can anyone help? I want the first image in the sequence to reappear after the last.

(Flash 8)

var NumberOfImages = 13;
var LocationToImages = "places/";
var FileType = ".jpg";
var MyImageWidth = 600;
var MyImageHeight = 511;
var x = 0;
MyImagesHolder._visible = false;
var MyArray = new Array();
var i = 0;
MyArray[i] = LocationToImages+i+FileType;
i++;
}

_global.Next = function() {
MessageDisplay = "";

x = x+1;

if (x<=NumberOfImages) {
loadMovie(MyArray[x], _root.MyImagesHolder);

_root.preloaderloader.gotoAndPlay(2);
} else {
x = NumberOfImages;
trace("No more images available");

}
};
_global.Previous = function() {
MessageDisplay = "";
x = x-1;
if (x>=0) {
loadMovie(MyArray[x], _root.MyImagesHolder);
_root.preloaderloader.gotoAndPlay(2);
} else {
x = 0;
trace("No more images available");
}

};
ButtonNext._visible = false;
ButtonPrev._visible = false;
stop();

[CS8 AS2] NaN Error When Adding Value In Array
Hi All,

I'm having trouble adding numbers into an array. I thought I understood this (from previous assistance), but I apparently don't.

Here's my code:


Code:
var allTotalSales:Array = new Array();
var combTotalSales:Array = new Array();

function getTotalSales(){
var all2008 = rebateData.childNodes[0].childNodes;

// get all sales
for(var i=0; i < all2008.length; i++){
allTotalSales.push(parseInt(rebateData.childNodes[0].childNodes[i].childNodes[2].childNodes[0].nodeValue));
}

// combine sales by same vendor and place in array
for(var i=0; i < allTotalSales.length; i++){ // FYI - this length is 2912
for(var j=0; j < sortedVendors.length; j++){ // FYI - this length is 229
if(rebateData.childNodes[0].childNodes[i].childNodes[1].childNodes[0].nodeValue == sortedVendors[j]) {
combTotalSales[j] = parseInt(combTotalSales[j]) + allTotalSales[i];
}
}
}

trace(combTotalSales); // NaN, NaN, NaN...
}
I thought the problem was because combTotalSales wasn't an number, but an array (which is what I want). And I thought using parseInt would resolve that. It doesn't. I still get "NaN" errors. The xml childnode value being called is a number, as is all items in the "allTotalSales" array.

I'm not understanding why the value in the array can't be changed.

The end result would be something like:

combTotalResults[0] = 123
combTotalResults[1] = 234
combTotalResults[2] = 345

Thanks.

- Stephen

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

Keep Adding Element To Array
Hello,

I'm trying to extract the data out from the array and put them into a new array consisted of name, x location, and y location. Somehow I can't keep adding them, the result of the new array will show only 1 element. can somebody help please?

thanks


ActionScript Code:
function doDub1(){
    var myLV:LoadVars = new LoadVars();
    myLV.onData = function(src:String) {
        var words = (src.split(" "));
        //trace(words);
       
        _global.wordArray = new Array();
        wordArray = src.split(" ");
        _global.n = wordArray.length;
       
            trace("Output Data = ");
            for (i = 0 ; i < wordArray.length ; i++){
                trace(" wordArray[" + i + "] = " + wordArray[i]);
            }
        for (i=0; i<wordArray.length; i++) {
           
            _global.mc = attachMovie("Word", "noun"+i, 100+i, {msg:wordArray[i], _x:mc._width*i, _y:mc._height*i});
            //mc.oldname = mc._name;
            //mc.oldX = mc._x;
            //mc.oldY = mc._y;
            //trace("mc.oldname = " + mc.oldname);
            //trace("mc._x = " + mc._x);
            //trace("mc._y = " + mc._y);
           
            xLoc = getProperty ("noun"+i, _x);
            yLoc = getProperty ("noun"+i, _y);
            trace(xLoc);
            var abc:Array = new Array()
            abc.push(["noun"+i, xLoc]);
            trace(abc.length);
           
            if(wordArray[i].length > 4 && wordArray[i].length <= 9){
                mc._xscale = mc._xscale * 2;
            }else if(wordArray[i].length >= 10){
                mc._xscale = mc._xscale * 2.3;
            }else{
                mc._xscale = mc._xscale;
            }
        }
    }
    myLV.load("nounsFile.txt");
    tempLabel = "Nouns";
}

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

Adding Elements Of One Array Into Another.
I know this can be done with concat, but why doesn't it work with splice or push? I'd like to be able to insert elements from one array into the middle of another array. Additionally, I'd like to have the changes affect the original array, but concat creates a new array.

ie.

Code:
var n1:Array = new Array();
n1.push(1,2,3);

var n2:Array = new Array();
n2.push(4,5,6);

n1.splice(n1.length, 0, n2)

// n1 = [1,2,3,[4,5,6]]
// n1 != [1,2,3,4,5,6]
Seems strange since all three functions use the ...args for the parameters to add.

Is there a way to use splice or push how I'm intending? Maybe with a for or for each statement to modify the array parameter?

Adding Data To An Array
I have an array populated from a parsed XML file. The XML file has a node representing an employee with attributes for "id", "tenure" , "phone" and "address". I want to be able to change the "id" attribute for a particular employee dynamically. Do I work with the array or is it better to affect the attribute in the xml doc , in which case I am clueless there as well so any help will be appreciated.





























Edited: 05/13/2007 at 02:22:17 PM by NorthB31

Adding Object To Array
This program has a green ball (var ballplayer) that the player moves around in 3D space using the numpad keys (8, 2, 6, 4) to move the green ball (up, down, right, left). And it also uses the up and down arrown keys to move the ball along the z-axis. There are also five red balls moving around the screen. As the red balls collide they turn blue. The red/blue balls are z-sorted, so that the balls closer to the viewer appear in front. The balls all move around in an invisible cube that they bounce off.

Problem: How do I get the player's green ball to be z-sorted with the other balls? I think I either need to add the green ball to the array called balls before it is sorted. Or create an array for the green ball and then add the two arrays together (if that's possible) before z-sorting. I tried to add the green ball directly to the balls array but it didn't seem to work. I'm new to AS3 and programming, so I may have made a simple mistake. Please help.

I'm attempting to modify code from "Foundation ActionScript 3.0 Animation" by Keith Peters. Here is the code so far.

Velocity3D.as

----------
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.geom.ColorTransform;

public class Velocity3D extends Sprite
{
private var ballplayer:Ball;
private var xpos:Number = 0;
private var ypos:Number = 0;
private var zpos:Number = 0;
private var vx:Number = 0;
private var vy:Number = 0;
private var vz:Number = 0;
private var friction:Number = .98;
private var fl:Number = 250;
private var vpX:Number = stage.stageWidth / 2;
private var vpY:Number = stage.stageHeight / 2;
private var top:Number = -200;
private var bottom:Number = 200;
private var left:Number = -250;
private var right:Number = 250;
private var front:Number = 300;
private var back:Number = -45;
private var balls:Array;
private var numBalls:uint = 5;

public function Velocity3D()
{
init();
}

private function init():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

ballplayer = new Ball(15, 0x1FE932);
balls = new Array();
for(var i:uint = 0; i < numBalls; i++)
{
var ball:Ball3D = new Ball3D(15);
balls.push(ball);
ball.xpos = Math.random() * 400 - 200;
ball.ypos = Math.random() * 400 - 200;
ball.zpos = Math.random() * 400 - 200;
ball.vx = Math.random() * 10 - 5;
ball.vy = Math.random() * 10 - 5;
ball.vz = Math.random() * 10 - 5;
addChild(ball);
}

addChild(ballplayer);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}

private function onEnterFrame(event:Event):void
{

xpos += vx;
ypos += vy;
zpos += vz;

vx *= friction;
vy *= friction;
vz *= friction;

var radius:Number = ballplayer.radius;
if(xpos + radius > right)
{
xpos = right - radius;
vx *= -1;
}
else if(xpos - radius < left)
{
xpos = left + radius;
vx *= -1;
}
if(ypos + radius > bottom)
{
ypos = bottom - radius;
vy *= -1;
}
else if(ypos - radius < top)
{
ypos = top + radius;
vy *= -1;
}
if(zpos + radius > front)
{
zpos = front - radius;
vz *= -1;
}
else if(zpos - radius < back)
{
zpos = back + radius;
vz *= -1;
}

if(zpos > -fl)
{
var scale:Number = fl / (fl + zpos);
ballplayer.scaleX = ballplayer.scaleY = scale;
ballplayer.x = vpX + xpos * scale;
ballplayer.y = vpY + ypos * scale;
ballplayer.visible = true;
}
else

{
ballplayer.visible = false;
}
for(var i:uint = 0; i < numBalls; i++)
{
var ball:Ball3D = balls;
move(ball);
}
for(i = 0; i < numBalls - 1; i++)
{
var ballA:Ball3D = balls;
for(var j:uint = i + 1; j < numBalls; j++)
{
var ballB:Ball3D = balls[j];
var dx:Number = ballA.xpos - ballB.xpos;
var dy:Number = ballA.ypos - ballB.ypos;
var dz:Number = ballA.zpos - ballB.zpos;
var dist:Number = Math.sqrt(dx * dx + dy * dy + dz * dz);
if(dist < ballA.radius + ballB.radius)
{
var blueTransform:ColorTransform = new ColorTransform(0, 1, 1, 1, 0, 0, 255, 0);
ballA.transform.colorTransform = blueTransform;
ballB.transform.colorTransform = blueTransform;
}
}
}
sortZ();

}

private function onKeyDown(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.NUMPAD_8:
vy -= 1;
break;

case Keyboard.NUMPAD_2:
vy += 1;
break;

case Keyboard.NUMPAD_4 :
vx -= 1;
break;

case Keyboard.NUMPAD_6:
vx += 1;
break;

case Keyboard.UP:
vz += 1;
break;

case Keyboard.DOWN :
vz -= 1;
break;

default :
break;
}
}
private function move(ball:Ball3D):void
{
var radius:Number = ball.radius;

ball.xpos += ball.vx;
ball.ypos += ball.vy;
ball.zpos += ball.vz;

if(ball.xpos + radius > right)
{
ball.xpos = right - radius;
ball.vx *= -1;
}
else if(ball.xpos - radius < left)
{
ball.xpos = left + radius;
ball.vx *= -1;
}
if(ball.ypos + radius > bottom)
{
ball.ypos = bottom - radius;
ball.vy *= -1;
}
else if(ball.ypos - radius < top)
{
ball.ypos = top + radius;
ball.vy *= -1;
}
if(ball.zpos + radius > front)
{
ball.zpos = front - radius;
ball.vz *= -1;
}
else if(ball.zpos - radius < back)
{
ball.zpos = back + radius;
ball.vz *= -1;
}

if(ball.zpos > -fl)
{
var scale:Number = fl / (fl + ball.zpos);
ball.scaleX = ball.scaleY = scale;
ball.x = vpX + ball.xpos * scale;
ball.y = vpY + ball.ypos * scale;
ball.visible = true;
}
else
{
ball.visible = false;
}
}

private function sortZ():void
{
balls.sortOn("zpos", Array.DESCENDING | Array.NUMERIC);
for(var i:uint = 0; i < numBalls; i++)
{
var ball:Ball3D = balls;
setChildIndex(ball, i);
}
}
}
}
----------

Here's the code for Ball.as.

---------

package {
import flash.display.Sprite;

public class Ball extends Sprite {
public var radius:Number;
private var color:uint;
public var vx:Number = 0;
public var vy:Number = 0;
public var mass:Number = 1;

public function Ball(radius:Number=40, color:uint=0xff0000) {
this.radius = radius;
this.color = color;
init();
}
public function init():void {
graphics.beginFill(color);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
}
}
}

------------

Here's the code for Ball3D.as.

------------------

package {
import flash.display.Sprite;

public class Ball3D extends Sprite {
public var radius:Number;
private var color:uint;
public var xpos:Number = 0;
public var ypos:Number = 0;
public var zpos:Number = 0;
public var vx:Number = 0;
public var vy:Number = 0;
public var vz:Number = 0;
public var mass:Number = 1;

public function Ball3D(radius:Number=40, color:uint=0xff0000) {
this.radius = radius;
this.color = color;
init();
}
public function init():void {
graphics.lineStyle(0);
graphics.beginFill(color);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
}
}
}.

Adding With A Number Array
I have an array, strictly numbers, how could I add...
say array[0](value=2)+array[1](value=1) to equal 3? What I come up with is an undefined error, or not a number...


Thanks


-TJ

Adding The Value Of Array Elements Together?
ok, i've been completely stuck on this for the past two hours. i just need someone to help point me in the right direction as far as what method to use here.

i have a clip on the stage that is 650px wide. i am placing dynamicaly sized clips on top of that clip. when they are created, their names are placed into an array. I am trying to take the items out of the array, find their widths, and then figure out if the width will be greater than 650 if the next clip is placed down. i'm stuck on the loop.

("track1Clips" is the array i have the clips in) here's what i have
for (i=0; i<_root.track1Clips.length; i++) {
clipName = _root.track1Clips[i];
clipName._width = clipWidth;
}

i want to add all the values of clipWidth together inside the loop to get the width of all the clips together, and then substract that value from 650 to get how big the last clip needs to be. I'm lost as to how to do this. can someone please give me a nudge. any help would be so greatly appreciated.

it's so add to look up help on this cause all i can find is how to add an element to an array, not add the values of the array together

Adding Another Dimension To An Array
I have some 2D arrays. I would like to add a 3rd dimension. How do I add this 3rd dimension? Thanks.

I don't know if I'm stating this correctly but what I would like to do is have an array that holds a bunch of [thumb.jpg, number, bigpic.jpg]. This way all the values entries are related. So if I wanted to get any of these values I could use the same key value.

I don't know if this makes sense. Plus, do I get the values of the 3rd dimension by using [i][2] in a for-loop? I know that [i][0] gets the 1st dimension and [i][1] gets the 2nd dimension.

Thanks in advance for any direction or help.

Adding An Array Value To An Instance Name
This should be an easy one cos I think I'm close already.

Basically, I want to loop through an array and call the same method for each button instance. So instead of hardcoding this:

Code:
sections_mc.section2.alphaTo(10,.5,"easeoutquad");
sections_mc.section3.alphaTo(10,.5,"easeoutquad");
sections_mc.section4.alphaTo(10,.5,"easeoutquad");
sections_mc.section5.alphaTo(10,.5,"easeoutquad");
sections_mc.section6.alphaTo(10,.5,"easeoutquad");
I can use something like this:

Code:
for (i=0; i < sectionArray.length; i++) {
sections_mc.section + sectionArray[i] + .alphaTo(10,.5,"easeoutquad");
}
I tried various things like concatenating the command and using eval:

Code:
eval("sections_mc.section" + sectionArray[i] + '.alphaTo(10,.5,"easeoutquad");';
However, none of my efforts worked.

Please could somebody help me?

Adding Values Of An Array
I have a list of values that I loop though and stuff into an array. Once they are in the array, I would like to add all of the values together (they are all numbers). There will always be a different number of values in the array so it needs to be done dynamically. Can anyone point me in the right direction?

var animalCountArr:Array = new Array();
var animalCount:XMLList = xmlData.row.(animalID == r && animalType == "DOG" && countyID == 40);
for (var v:uint = 0; v<animalCountArr.length(); v++) {
animalCountArr[v] = animalCount.calcCandidateVotes[v];
}

Thanks.

Adding With A Number Array
I have an array, strictly numbers, how could I add...
say array[0](value=2)+array[1](value=1) to equal 3? What I come up with is an undefined error, or not a number...


Thanks


-TJ

Adding Objects To A 2d Array
In my actionscript, I map parameters from an XML file to objects, and then add them to an array called tiles.

This was accomplished by using the push function at the end of each loop in the parsing routine.

However, I've reorganized the objects into a 2d array, and I'm unsure how to use the push function with it -- or if it's even possible at all.  Setting the array[i][j] equal to the object adds the object properly, but the objects don't seem to retain all of their properties when I add them in this way.   Any help would be appreciated.. code below:

Map.prototype.initialize = function(mapXML) {
        
        mapXML.ignoreWhite = true;              // Ignore Whitespace
        
        var rootTag;                            // Root XML Element
        rootTag = mapXML.firstChild;
        
        // Obtain Root Element attributes, store in map object
        this.rows = rootTag.attributes["rows"];
        this.cols = rootTag.attributes["cols"];
        this.numTiles = rootTag.attributes["numTiles"];
        
        // For each Hex node
        for (i = 0; i < (rootTag.childNodes.length); i++) {  
            // if node is valid (not null)
            if (rootTag.childNodes[i].nodeName != null) {
                // Declare Hex object this node represents
                tempHex = new Hex();                    // Temporary Hex Object
                // Get Hex Attributes from current node
                tempHex.row = rootTag.childNodes[i].attributes["row"];
                tempHex.col = rootTag.childNodes[i].attributes["col"];
                // For each Child of a Hex Node
                for (j = 0; j < (rootTag.childNodes[i].childNodes.length); j++) {
                    // if node is valid (not null)
                    if (rootTag.childNodes[i].childNodes[j].nodeName != null) {
                        // Set Hex Properties based on node values
                        if (rootTag.childNodes[i].childNodes[j].nodeName == "terrain") {
                            tempHex.terrain = rootTag.childNodes[i].childNodes[j].childNodes[0].nodeValue;
                        }
                        if (rootTag.childNodes[i].childNodes[j].nodeName == "province") {
                            tempHex.province = rootTag.childNodes[i].childNodes[j].childNodes[0].nodeValue;
                        }
                        if (rootTag.childNodes[i].childNodes[j].nodeName == "color") {
                            tempHex.colorStyle = rootTag.childNodes[i].childNodes[j].childNodes[0].nodeValue;
                        }
                        
                    }// If != null
                }// For each Hex Node Child
                
                this.tiles[tempHex.col][tempHex.row] = tempHex;// Add tempHex to the Map.tiles array
                trace(this.tiles[tempHex.col][tempHex.row].terrain);// This parameter shows undefined, even though tempHex.terrain shows the proper value.
            }// If != null
        }// For each Hex Node
};// Map.initialize()

Adding OnRelease To MC's In Array
I'm looping through an array (cardsArray) and am trying to add the onRelease functionality to each card stored in the array. For some reason, the onRelease isn't being properly assigned. Can anybody tell me where I've gone wrong?



ActionScript Code:
function programButtons ()
{
    for (var i = 0; i<cardsArray.length; i++)
    {
        trace ("..."+cardsArray[i]);
        cardsArray[i].onRelease = function ()
        {
            if (pickedCount>0)
            {
                var isMatch = checkMatch ();
                checkWin (isMatch);
            } else
            {
                //nothing
            }
        }
    }
};

Adding (sum) Array Elements
Just started working on a commerce app... price data is being successfully placed in an array within Flash (from mySQL DB), but trying to add two prices together comes out like: 13.5013.50

Seems like Flash isn't recognizing the price as a "Number". Any suggestions?

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