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




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



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 03-29-2006, 07:00 AM


View Complete Forum Thread with Replies

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

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 Slice
I have this mc that i want its name to be added to an array and when that movie clip is deleted I also want that value in the array to be deleted also. How would I do this?
Thanks for the Help.







Attach Code

balive.push("bomb"+bombNum);
_root["bomb"+bombNum].onEnterFrame= function() {
this._y += this.myspeed;
wb = this;
if (this._y>=550) {
this.removeMovieClip();
for (i=0; i<=balive.length; i++) {
if ("_level0."+balive[i]==wb){
balive.splice(i, i+1);
trace(balive.splice(i,i+1));
trace(balive);
}
}
}
};

Array.slice()
Heres an array of questions if you will...(pun )

ActionScript Code:
Array = [ one, two, three, four, five, six ]slice = array.slice( start, end )

Say i wanted to cut out "three" from the array so i was left with: [one, two, four, five, six]
is this possible with just slice? or is there other methods you would need to use?

Theoretically speaking..
now that my slice.length is 1 smaller than array.length, im confused on how to get my for loop to function correctly:

ActionScript Code:
slice = [one, two, four, five, six]xb = [array[0]._x, array[1]._x, array[2]._x etc etc];yb = [array[0]._y, array[1]._y, array[2]._y etc etc];for(x=0;x<slice.length;x++){slice[x]._x=xb[x]slice[x]._y=xb[x]}


Now the for loop will run 5 times however since "three" has been removed, i need it to skip the 3 itteration. So it will make x: 1,2,4,5,6

Any suggestions?

Using Array.slice
Hi there,

I made an swf that displays 8 thumbnails at a time. The locations of the content for the thumbs comes from an external text file, that contains a string of folder names that hold the images.
I now feed this string into an array, by splitting the string up using:
ActionScript Code:
stop();
theArray = new Array();
pr_var = new LoadVars();
pr_var.onLoad = function(ok) {
if (ok) {
projArray = this.projArray.split(",");
gotoAndPlay("letsGo");
trace(projArray);
} else {
trace("can't get the txt file");
gotoAndPlay("loadLoop2");
}
};
pr_var.load("content/projects/projectsContent.txt");



Then I used the following code to load only the first 8 items:
ActionScript Code:
var startIndex:Number = 0;
var endIndex:Number = 8;
var projRange = this.projArray.slice(startIndex, endIndex);



Now, my original array contains 22 items for now, how would I add a "next" Button to load items the next 8 items (8 to 16 and after that 16 to 22)?

Thanks for any help,

Rufus

Array.slice()
Hi,

i have an fileArray consisting of 6 mc's. i have a second containerArray that consists of 3 containermcs.

i would like to obtain the following :

containerArray[0] = containerMC0;
containerArray[1] = containerMC1;
containerArray[2] = containerMC2;

containerMC0.addChild(fileArray[0]);
containerMC0.addChild(fileArray[1]);

containerMC1.addChild(fileArray[2]);
containerMC1.addChlid(fileArray[3]);

containerMC2.addChild(fileArray[4]);
containerMC2.addChild(fileArray[5]);

im not very good at writing loops. So when this is done, i could go and say :

addChild(containerArray[0])

this would give me containerMC0 consisting of the mc's fileArray[0] & [1]

any ideas on how i could do this ?

Array.slice()
Heres an array of questions if you will...(pun )

ActionScript Code:
Array = [ one, two, three, four, five, six ]slice = array.slice( start, end )

Say i wanted to cut out "three" from the array so i was left with: [one, two, four, five, six]
is this possible with just slice? or is there other methods you would need to use?

Theoretically speaking..
now that my slice.length is 1 smaller than array.length, im confused on how to get my for loop to function correctly:

ActionScript Code:
slice = [one, two, four, five, six]xb = [array[0]._x, array[1]._x, array[2]._x etc etc];yb = [array[0]._y, array[1]._y, array[2]._y etc etc];for(x=0;x<slice.length;x++){slice[x]._x=xb[x]slice[x]._y=xb[x]}


Now the for loop will run 5 times however since "three" has been removed, i need it to skip the 3 itteration. So it will make x: 1,2,4,5,6

Any suggestions?

Slice Array Into Another Array
I would like to take the current array image[i] randomly select ten items from it and load that into a seperate array. Is there a way to accomplish this?

What Am I Doing Wrong With Array.slice?
Hi there, folks. I’ve just started getting my feet wet with actionscript, and I’d sure appreciate it if someone could explain what it is I’m doing wrong in a way that I’ll be able to understand. The problem I’m having is around line forty or so. The user is supposed to receive feedback showing the other possible correct answers after they’ve submitted a, b, c, or d. (for example, if 'a' has been entered, they would read ‘Correct… Other possible correct answers include: b, c, d’). I thought creating otherCorrectArray and populating it with answerArray.slice(i) would work, with i derived from the previous for loop. But no luck.



Code:
var first1:Number = 0;
var correctSubmit:String;
//
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0x000000;
my_fmt.underline = false;
my_fmt.align = "center";
my_fmt.size = 20;
//
empty_mc.createTextField("my_txt", 0, 145, 165, 250, 300);
empty_mc.my_txt.multiline = true;
empty_mc.my_txt.wordWrap = true;
empty_mc.my_txt.text = "Enter a letter from a to d.";
empty_mc.my_txt.setTextFormat(my_fmt);
//
var answerArray:Array = new Array();
answerArray[0] = "a";
answerArray[1] = "b";
answerArray[2] = "c";
answerArray[3] = "d";
//
correctSubmit_btn.onRelease = function() {
correctSubmit = textInput_txt.text;
var i:Number = 0;
for (i=0; i<answerArray.length; i++) {
if (correctSubmit == answerArray[i]) {
first1++;
correct();
return;
}
}
incorrect();
return;
};
function correct() {
if (first1 == 1) {
var otherCorrectArray:Array = new Array();
// If a correct answer has been submitted, it's supposed to list the other
// possible correct answers, _without_ listing the one that was subitted.
// Slice() wants an index and it doesn't seem to work taking i from the above for loop.
otherCorrectArray = answerArray.slice(i);
trace("Correct... "+"Other correct answers: "+otherCorrectArray);
empty_mc.my_txt.text = "Correct..."+"Other correct answers: "+otherCorrectArray;
empty_mc.my_txt.setTextFormat(my_fmt);
} else if (first1>1) {
trace("Yes, but you already entered an answer. Possible correct answers include: "+answerArray);
empty_mc.my_txt.text = "Yes, but you already entered an answer. Correct answers include "+answerArray;
empty_mc.my_txt.setTextFormat(my_fmt);
}
}
function incorrect() {
empty_mc.my_txt.text = "Incorrect.";
empty_mc.my_txt.setTextFormat(my_fmt);
trace("Incorrect.");
}

Thanks.

Array.slice Is Not Working
Array.slice is not working

Code:
var a:Array = []

for (var i:int = 0; i<2; i++){
a[i] = [];
//b[i] = [];

for (var j:int = 0; j<2; j++)
{
a[i][j] = {type1:j};
}
}

var b:Array = a.slice();

trace(a[1][1].type1); // 1
trace(b[1][1].type1); // 1

b[1][1].type1 = 2;

trace(a[1][1].type1); // 2
trace(b[1][1].type1); // 2

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!

Multidimensional Array , Slice And Sort
how can I slice and sort an array like this :


Code:

var Table:Array = new Array();
Table[0]=[3];
Table[0][0]="01/01/2007 0:00";
Table[0][1]=100;
Table[0][2]=500;

Table[1]=[3];
Table[1][0]="01/01/2007 0:15";
Table[1][1]=15;
Table[1][2]=75;

Table[2]=[3];
Table[2][0]="01/01/2007 0:30";
Table[2][1]=150;
Table[2][2]=750;
I need a copy of this array sliced .... just last two elements

Split Array With MyArray.slice(start, End)
I have a text file containing:

&img0=comment img0|images/image0.jpg&
&img1=comment img1|images/image1.jpg&
&img2=comment img2|images/image2.jpg&
&img3=comment img3|images/image3.jpg&
&img4=comment img4|images/image4.jpg&
&img5=comment img5|images/image5.jpg&
&TotalImages=6&

With Flash I put the content of this text file into an array:

slides = comment img1,images/image1.jpg,comment img2,images/image2.jpg,comment img3,images/image3.jpg,comment img4,images/image4.jpg,comment img5,images/image5.jpg,


What I need is the following: I need the images/imageX.jpg in an array and the comments in ANOTHER array. I searched and found the myArray.slice option. But how do you use it in this situation? HELP, hahaha!


So the result should be Array1 = images/image1.jpg etc.., Array2= comment img1 etc..

Can't Duplicate Movieclips As An Array Within An Array
Hello.
I have an animation that loads an xml into it and traces back an array within an array. I have tried to apply this to duplicated movieclips thereby creating a structured set of links. What I am trying to do is this:

Chicken Nuggets
__Compression
__Texture
__Disgust
Mega Warhead
__Taste
__Hardness
__Pain

This traces fine but I can't seem to get the duplicated movieclips to assemble in this fashion.
The code for the XML is as follows:

var controlArray:Array;
var variable:Array;
var testTopic = new Array ();
var test = new Array ();

var controlsXML:XML = new XML();
controlsXML.ignoreWhite = true;

controlsXML.onLoad = function(success:Boolean){
if (success){
var mainnode:XMLNode = controlsXML.firstChild;
var controlNodes:Array = controlsXML.firstChild.firstChild.firstChild.firstChild.childNodes;

var list:Array = new Array();
for (var i:Number = 0; i < controlNodes.length; i++) {
var personnode:XMLNode = controlNodes.attributes.Name;
trace(personnode);
testTopic.push (new struct (personnode));
var specificNode:Array = controlNodes.childNodes;
for (var j:Number = 0; j < specificNode.length; j++){
var itemnode:XMLNode = specificNode[j].attributes.Variable;
trace(itemnode);
test.push (new struct2 (itemnode));
}


}
printer ();
printer2 ();
} else {
trace('error reading XML');
}
};
controlsXML.load ("controls3.xml");

The code for the movieclip duplication is as follows:

x = 50;

function printer ()
{
for (m = 0; m < testTopic.length; m++)
{
duplicateMovieClip ( slotTopic, "slotTopic" + m, m );
slotTopic = eval ( "slotTopic" + m );
slotTopic._y += x;
slotTopic.slotTopicContent.text = testTopic[m].personnode;
}
}

function printer2 ()
{
for (k = 0; k < test.length; k++)
{
duplicateMovieClip ( slot, "slot" + k, k );
slot = eval ( "slot" + k );
slot._y += x;
slot.slotContent.text = test[k].itemnode;
}
}

function struct (personnode)
{
this.personnode = personnode;
}

function struct2 (itemnode)
{
this.itemnode = itemnode;
}

On the stage are two movieclips, titled "slotTopic" and "slot". Within those are dynamic text boxes titled respectively "slotTopicContent" and "slotContent". When I preview this file it only displays the text within the "slot" movieclip and it lists all six of the subtopics with no break. So, there are two dilemmas:

1) The movieclips won't duplicate into the structured set of links that I want.
2) "slotTopic" is not displaying text at all.

If anyone has any advice, I'd really appreciate it. Thx!

Duplicate Movieclips: Array Within An Array
Hello.
Having a problem with duplicating movieclips within an array within another array.
I'm trying to setup a horizontal categorical menu drawn from an xml file.

I want this:

0
mainMenuSmall0.jpg
1
mainMenuSmall1.jpg
2
mainMenuSmall2.jpg

...etc.


The following is the code:

var array = new Array ();
var xml = new XML ();
xml.onLoad = function ()
{
var header, link, image;
for (var i = 0; i < this.firstChild.childNodes.length; i++)
{
if (this.firstChild.childNodes[i].nodeName != null)
{
header = this.firstChild.childNodes[i].attributes.header;
}
for (var j = 0; j < this.firstChild.childNodes[i].childNodes.length; j++)
{
if (this.firstChild.childNodes[i].childNodes[j].nodeName == "link")
{

link = this.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
}
}
for (var k = 0; k < this.firstChild.childNodes[i].childNodes.length; k++)
{
if (this.firstChild.childNodes[i].childNodes[k].nodeName == "image")
{

image = this.firstChild.childNodes[i].childNodes[k].firstChild.nodeValue;
}
}
array.push (new struct (header, link, image));
}
printer ();
};
xml.load ("dbase.xml");

function printer ()
{
for (i = 1; i < array.length; i=i+2)
{
slot.duplicateMovieClip ( 'slot'+i,i,{_y:100});
slot.header = array[i].header;
slot.link = array[i].link;
slot.image = array[i].image;
slot = eval ( "slot" + i );
slot2.duplicateMovieClip ( 'slot2'+(i+100),i+100,{_y:50});
slot2.header = array[i].header;
slot2.link = array[i].link;
slot2.image = array[i].image;
slot2 = eval ("slot2" + (i+100));


}
}
function struct (header, link, image)
{
this.header = header;
this.image = image;
this.link = link;
}


'Slot' and 'Slot2' are what the movieclips (blue and green) that should contain the menu item text. I've attached the .xml file and the result of what I get when I publish. Essentially the movieclips are not positioning correctly and the only one of each menu item is displaying.

Any advice would be much appreciated.
Thanks!

Array, Duplicate MC
Hello !
I am trying to make a little game and I have problems with some AS.
I have four MC that I random duplicate. They are duplicated if they hit some object or after 60 frames (var ie5).
Duplication is goning OK, but the objects dont move properly. I think there could be something wrong with the array or sth.
Please help me cause I am stucked with it.

Here is all the code of the frame.

Thanx in advance

MF-Digital

RandomThrash = new Array("thrash0", "thrash1", "thrash2", "thrash3");
ThrashGenerator = random(4);
DoThrashRandom = RandomThrash[ThrashGenerator];
NumberOfItems+=1;
is5=NumberOfItems%60;

thrashcopy = new Array();

if (Number((go) == 0) || (is5==0)) {
nn = Number(nn)+1;
duplicateMovieClip (DoThrashRandom,"thrashcopy" + nn, 120+Number(nn));
thrashcopy[nn] = eval("thrashcopy" + nn);
thrashcopy[nn]._x=0;
thrashcopy[nn]._y=196;
thrashcopy[nn].isAlive = true;
xmov = random(3)+6;
ymov = 0;
go = 1;
}

for (var i=1; i<= thrashcopy.length; i++) {
if (_root.thrashcopy[i].buttonDown ne true){
xmov = xmov;
thrashcopy[i]._x=thrashcopy[i]._x+xmov;
thrashcopy[i]._y=196;
}

if (thrashcopy[i].hitTest(_root.rollbandEnd)){
thrashcopy[i].gotoAndPlay(2);
_root.score=_root.score-1;
go = 0;
}

if (thrashcopy[i].hitTest(_root.glass) and thrashcopy[i].isAlive){ //BOTTLE
thrashcopy[i].gotoAndPlay(2);

if (thrashcopy[i].food==0){
_root.score=_root.score+1;
go = 0;
}

if (thrashcopy[i].food==1){
_root.score=_root.score-1;
go = 0;
}

if (thrashcopy[i].food==2){
_root.score=_root.score-1;
go = 0;
}
}

if (thrashcopy[i].hitTest(_root.mat) and thrashcopy[i].isAlive){ //ORANGE CHICKEN
thrashcopy[i].gotoAndPlay(2);
if (thrashcopy[i].food==0){
_root.score=_root.score-1;
go = 0;
}

if (thrashcopy[i].food==1){
_root.score=_root.score+1;
go = 0;
}

if (thrashcopy[i].food==2){
_root.score=_root.score-1;
go = 0;
}
}

if (thrashcopy[i].hitTest(_root.papir) and thrashcopy[i].isAlive){ //LETTER
thrashcopy[i].gotoAndPlay(2);
if (thrashcopy[i].food==0){
_root.score=_root.score-1;
go = 0;
}

if (thrashcopy[i].food==1){
_root.score=_root.score-1;
go = 0;
}

if (thrashcopy[i].food==2){
_root.score=_root.score+1;
go = 0;
}
}
}//for

Duplicate AND Array
I'm trying to assign my duplicated movieclips to an array and then place them on random parts of the screen. This is only working for one movieclip.


ActionScript Code:
var myArray:Array = Array();
for (i=0; i<9; i++) {
    var myPosX:Number = Math.floor(Math.random()*500)
    var myPosY:Number = Math.floor(Math.random()*350)
    trace(myPosX);
    duplicateMovieClip(d, "mc"+i, this.getNextHighestDepth);
    this["mc"+i]._x = myPosX;
    this["mc"+i]._y = myPosY;
}
stop();

Array Duplicate/attach MC
5 navigator in the main window and when any of the menu clicked the non clicked menu has to come and merge to the clicked one.
5 navigator has done thru Duplicate/attach MC working fine
while clicking the menu its not merging.


------------------------------------------------------------
Frame 1 consists of the following code: which work fine

menuArray = new Array("About","Q","Third","S","Menu 5");
_root.about.menu = menuArray[0];

for (i=0; i<menuArray.length; i++){
attachMovie(_root.menuArray[0],_root.menuArray[i],i);
var display = this[menuArray[i]];
_root.display.menu = menuArray[i];
eval(menuArray[i])._x = eval(menuArray[i-1])._x + 130;
eval(menuArray[i])._y = + 300;
}
------------------------------------------------------------
Inside the MC the Button Code not working:
on(press){
myX = this._x;

for(i=0 ;i<_root.menuArray.length;i++){
_root.menuArray[i]._x = myX;
}
}
------------------------------------------------------------

Duplicate MC From Array Length
can anyone lend a hand please. In AS2 i would use the length of an array or xml to duplicate navigation buttons and add functions to those buttons such as:

ActionScript Code:
var buttons:Array = new Array("JOHN", "FRANK", "JANE", "STUART");
for (var i:Number = 0; i<buttons.length; i++)
{

    mNav.mTextMc.duplicateMovieClip("mTextMc"+i,mNav.getNextHighestDepth());

    mNav["mTextMc"+i]._y = mNav.mTextMc._y+i*24;
    mNav["mTextMc"+i].txt = buttons[i];
    mNav.mTextMc._visible = false;
    mNav["mTextMc"+i].Text.autoSize = true;


    bt = mNav["mTextMc"+i];
    bt.num = i;
    bt.onRelease = function()
    {
        this._alpha = 20;
    };
}

but i cant seem to get this in as3.
any help will be appreciated, thank you

Array Duplicate Error
Hey all,

I am making tetris and found an incredibly annoying bug (in Flash 5 AS).


Code:
array1 = new Array('0','1','2','3');
array2 = array1;
array2[0] = 'blah';
trace(array1[0]);
Now, this traces out 'blah'. It's supposed to trace '0'. I copied array2 from array1, but if I change array2, array 1 will change also. How is this possible? This is not so with variables (strings, integers), but with arrays. Is this an error or something? How can I avoid this?

Array Duplicate Error
Hey all,

I am making tetris and found an incredibly annoying bug (in Flash 5 AS).


Code:
array1 = new Array('0','1','2','3');
array2 = array1;
array2[0] = 'blah';
trace(array1[0]);
Now, this traces out 'blah'. It's supposed to trace '0'. I copied array2 from array1, but if I change array2, array 1 will change also. How is this possible? This is not so with variables (strings, integers), but with arrays. Is this an error or something? How can I avoid this?

Duplicate MCs And Array Prob.
There are 5 buttons, and each button has a random number. If I choose to click on for an example 3 of them, then a main button, there's suppose to popup 3 duplicated mcs that each contain same image. But they don't work. I get the random numbers to work but not the duplicated mcs.
Please help


Code:
bildArray = new Array(5);
One of the five buttons:


Code:
_root.btnLott1a.onPress = function() {
bildArray[0] = _root.dupMC.duplicateMovieClip("newDup" + bildArray[0], bildArray[0]);

Code:
function bildLott() {
_root.dupMC._visible = true;
for(i = 0; i < 5; i++){
if(bildArray[i] != null && bildArray[i] != ""){
newMC = _root.dupMC.duplicateMovieClip("newDup" + bildArray[i], bildArray[i]);
setProperty ("newDup" + bildArray[i], _y, _root.dupMC._y + 100);
trace(newMC);
}
}
}
and the button to view the result:

Code:
_root.btnDone.onPress = function() {
bildLott();
}

Please Help - Looping Through An Array, Duplicate
Hey all -
would anyone be so kind as to have a look at this code? Probably something simple I'm just not seeing.

/*mbNav is a var declared on previous frame, loading variables from a txt file called MindblazerVars.txt.
Two lines below load the nav variable and navURL variable into arrays.
*/
var mbNavItem = mbNav.nav.split(",");
var mbNavURL = mbNav.navURL.split(",");

/*
Loop through the mbNavURL array; duplicate a movie clip on the stage called "google," containing
a dynamic text field named "nav_txt" and a movie clip named "boing" for each iteration. "Boing"
is the movie clip that acts as the button to go to the mbNavURL value
*/

for(i=0;i<mbNavURL.length;i++) {
//trace(mbNavURL[i]);
_root.google.duplicateMovieClip("nav"+i,i);
_root["nav"+i]._x = _root["nav"+i]._x + (i*100);
_root["nav"+i].nav_txt.text = mbNavItem[i];
//trace(mbNavURL[i]);
_root["nav"+i].boing.onRelease = function(){
this.getURL(mbNavURL[i]);
}
}
When I preview, the links do not work. If I change the value of i in the line
this.getURL(mbNavURL[i]);
to a hard value, such as 0, 1 or 2, the link works! What am I doing wrong??

You can see the SWF at http://www.eemajin.com/Flash/Mindbla...003_7.3.03.swf

Please Help - Looping Through An Array, Duplicate
Hey all -
would anyone be so kind as to have a look at this code? Probably something simple I'm just not seeing.

/*mbNav is a var declared on previous frame, loading variables from a txt file called MindblazerVars.txt.
Two lines below load the nav variable and navURL variable into arrays.
*/
var mbNavItem = mbNav.nav.split(",");
var mbNavURL = mbNav.navURL.split(",");

/*
Loop through the mbNavURL array; duplicate a movie clip on the stage called "google," containing
a dynamic text field named "nav_txt" and a movie clip named "boing" for each iteration. "Boing"
is the movie clip that acts as the button to go to the mbNavURL value
*/

for(i=0;i<mbNavURL.length;i++) {
//trace(mbNavURL[i]);
_root.google.duplicateMovieClip("nav"+i,i);
_root["nav"+i]._x = _root["nav"+i]._x + (i*100);
_root["nav"+i].nav_txt.text = mbNavItem[i];
//trace(mbNavURL[i]);
_root["nav"+i].boing.onRelease = function(){
this.getURL(mbNavURL[i]);
}
}
When I preview, the links do not work. If I change the value of i in the line
this.getURL(mbNavURL[i]);
to a hard value, such as 0, 1 or 2, the link works! What am I doing wrong??

You can see the SWF at http://www.eemajin.com/Flash/Mindbla...003_7.3.03.swf

Removing Duplicate Values From An Array...
I am trying to remove duplicate values from an array and I am not sure how to go about doing it...

Here's what I have:

myArray =[1022.75,12.2,12.2,12.2,12.2,12.2,14.4,14.4,15.2,16 .2,32.2,32.2,32.2]

*I need to filter out the duplicate values.

Can anyone lend a hand?

thanks for taking a look.

Dropping Duplicate Values In Array?
is there a FAST way (fast meaning easy on proc) to drop duplicate values in an array?

lets say I have an array like...

[0, 0, 0, 0, 1, 1, 2, 6, 6, 6, 6, 8, 8 ]

and i want to simply return

[0, 1, 2, 6, 8]

is there a method for this already? i am having to do this with an array that is LARGE, like a few hundred values.. this is to help me with this problem here...

http://www.actionscript.org/forums/s....php3?t=122694

When I try this with LARGE arrays it is starting to take almost half a second each time... this is a problem since its for a game that has to be fast...

thanks for your help

Multi-dimensional Array Duplicate Mc
I am trying to create a mc dynamically that I will duplicate and populate with xml data. Issue is I am able to create the container clip with script but when I try to duplicate it in a for statement nothing appears on the stage not even the first rectangle named container.


Here is the code:

Code:

/////////////////////////////
// -- Rectangle Function
/////////////////////////////
function drawRectangle(mcClip:MovieClip, nWidth:Number, nHeight:Number):Void {
mcClip.lineTo(nWidth, 0);
mcClip.lineTo(nWidth, nHeight);
mcClip.lineTo(0, nHeight);
mcClip.lineTo(0, 0);
}
/////////////////////////////
// -- Draw Rectangle
/////////////////////////////
var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
_root.container.lineStyle(1, 0x000000, 0);
_root.container.beginFill(0x332211, 50);
drawRectangle(container, 60, 60);
_root.container.endFill();
/////////////////////////////
// -- Variables
/////////////////////////////
var xPos = 60;
var yPos = 60;
/////////////////////////////
// -- Create Thumb
/////////////////////////////
for (i=0; i<10; i++) {
_root.container.duplicateMovieClip("new"+i, i, {_x:xPos, _y:yPos});
xPos += _root["new"+i]._width+5;
if (xPos>400) {
xPos = 60;
yPos += 60;
}
}

Not Allowing Duplicate Numbers In An Array
I have an array where the user enters 6 numbers and then presses a button. Is it possible for an error message to come up if there is a number repreated?

Merging Duplicate Data In An Array
I am parsing data from an xml file into an array within my flash file. The nodes within the xml file have common data between them. What I am attempting to do is dynamically push the data in the array without duplicating data already contained in the array. For example I may have an xml file that looks like this:


Quote:




<videos>
<video>
<title>video1</title>
<thumb>file1.jpg</thumb>
<group>group1</group>
</video>
<video>
<title>video2</title>
<thumb>file2.jpg</thumb>
<group>group2</group>
</video>
<video>
<title>video3</title>
<thumb>file3.jpg</thumb>
<group>group1</group>
</video>
</videos>




Say I want to push the "group" data into an array. When it gets to the third "video" node I want the array to see that "group1" already exists so instead of pushing a second reference of it into the array to actually push the secondary data ("title" and "thumb"> into a new array for "group1". I will later use that array to pull up a list of "group1" videos. Any thoughts or ideas? Anything would be huge - I have been banging my head against the wall with google searches.

Array And Duplicate Random Pictures
hi there all, hope someone can help,

i am displaying random pictures in a movie. each time the
user clicks a square on the screen an image/movieclip appears.
my problem is that at the moment 2 or more of the same image/movieclip
can appear on the screen at the same time and i do not want
that.
i have tried adding each number representing the random
movie to an array and then doing a check to see if that number exists in the array. if it does exists this means the image/movieclip
is already displayed on the screen so do not show it and generate
a new number and so forth. i am receiving all the necessary
values perfectly.
my code to do the check is as follows :

i = 0;
_root.myArrayPhoto.push(randMov);
outerArraylength = _root.myArrayPhoto.length;

for(i=0; i <= outerArraylength; i++) {
if ((_root.myArrayPhoto[i] == randMov)) { //check if movie exists
gotoAndPlay(1);//goto first frame and to random func again
}
}

//else loop finished so
//movieclip does not on screen so show it :
loadMovie "swf/photo"+randMov+".swf", "_root."+_root.thisWhich);
gotoAndPlay(1); //goto first frame and start again


thanks!

Checking Array For Duplicate Numbers
Hi, I have an array of random generated numbers between 0-31 and I want to check for duplicate entries before I populate my tex fields with those numbers:
Tha code I have looks like:


var numbers = new Array();
for(var i=0;i<8;i++)
{
a = random(32);
b = parseInt(a);
numbers.push(b);

_root["tagText" + i].text = numbers[i];
}

My text fields are tagText0, tagText1 and so on till tagText7.
This works well, but I get duplicate numbers, and I want unique numbers.
I tried loops like:

for (var j = 0; j<8; j++)
{
for (var k = 0; k<8; k++)
{
if (numbers[j] == numbers[k])
{
numbers[j] = random(32);
}
}
}


before populating my text fields but it didn't work
Any ideas anyone?

Thanks a lot

Duplicate Mc`s And Remove According To Dynamic Array
Hi there guys,

First off i`m new to this forum and i hope someone can help me / get me on the right way with my (relative simple) problem...

couple of weeks ago i started my own website, http://www.ernst-marten.nl (dutch). It has a feature for visitors to enter their name, once they did it a dude will fall out of the sky and will run to the place where the user clicks in the menu. The nice thing is, that it`s sorta "multiplayer based", when you are running on my site, and another visitor enters my page, he will see you running to the place where you clicked. I also built in a chat-like system in it... users can enter a little string which will be outputted to everyone whos on my site at that moment. There are still a few bugs in it, but here comes my major problem:

the site works with a mysql database when it comes to the "running dudes",
i`m checking every 5 seconds howmany users are logged in. Im calling a php page which outputs all names separated by a comma. I put this in an array and duplicate movieclips from a temporary dudeMC according to the amount of users. When the current amount of users is lower then the updated amount of users (when someone joines) i know what to do, just duplicate movieclips. But what to do if a user leaves... ?
To make it a bit more understandable I have this simple script which represents my problem, the movie had just one frame in it, a input box called "names", a dudeMC, and a process_button.

dude._visible = false;

process_button.onRelease = function() {

temp = name;
current_count = int(name.length);
name = names.split(",");
count = name.length;

//duplicate dudes *count* times
if (current_count<count) {
for (i=0; i<count; i++) {
dude.duplicateMovieClip("dude"+i, "1"+i);
_root["dude"+i].name = name[i];
_root["dude"+i]._x = (i*100);
_root["dude"+i].id = i;
}
} else {
**check which user has left and approach the right duplicated "dudeMC" to set a variable "dead"***
}
};

the problem is, that when a user leaves, i don`t exactly know WHICH user have left... offcourse the names-array will be changed, but i need to approach the duplicatedMC of the user who has left....

well... i know it`s a bit confusing maybe to understand me... i hope someone can help / advise me a bit on this... thanks in advance!!!

[MX]Duplicate Array Item Checker
hello

I'm wondering if someone could check my code below and let me know if they see any probs. I've basically made up a function that checks to see if any 2 or more items in an array are the same. If there are duplicate items the funtion is supposed to add 1 to a variable and push that variable into another array. That other array then shifts the numbers inside of it into another array on the tailend of the duplicate array items so they are unique. Heres what it looks like:


Heres my function:


Code:
Array.prototype.dupCount = function(countElement) {
tempCount = 0;
for (i=0; i<this.length; i++) {
trace(this[i]);
if (countElement == this[i]) {
tempCount++;
catCountAry.push(tempCount);
}
}
};
Heres the loop that calls the function:


Code:
for (var elem in subCatsAry) {
subCatsAry.dupCount(subCatsAry[elem]);
if (catCountAry.length == 0) {
subCatsAry[elem] += 1;
catCountAry.shift()
} else {
for (i=0; i<=catCountAry.length; i++) {
subCatsAry[elem] += catCountAry.shift();
}
}
}
Any ideas?

Thanks

How To Duplicate An Array With Out Binding It To The Original?
PHP Code:



var array1:Array;var array2:Array;testArray(new Array(1,2,3));function testArray(e:Array):void{    array1 = e;    array2 = e;        array1[0] = 4;    trace(array2[0]); // outputs 4 but should be 1} 




this is a binding problem that I can't figure out.
I have tried to make a new array before "array1 = e" but it just overrides the old array with the new one and not copying it but binding it to the original array.


help me please I have a job to finish tonight

[MX]Duplicate Array Item Checker
hello

I'm wondering if someone could check my code below and let me know if they see any probs. I've basically made up a function that checks to see if any 2 or more items in an array are the same. If there are duplicate items the funtion is supposed to add 1 to a variable and push that variable into another array. That other array then shifts the numbers inside of it into another array on the tailend of the duplicate array items so they are unique. Heres what it looks like:


Heres my function:


Code:
Array.prototype.dupCount = function(countElement) {
tempCount = 0;
for (i=0; i<this.length; i++) {
trace(this[i]);
if (countElement == this[i]) {
tempCount++;
catCountAry.push(tempCount);
}
}
};
Heres the loop that calls the function:


Code:
for (var elem in subCatsAry) {
subCatsAry.dupCount(subCatsAry[elem]);
if (catCountAry.length == 0) {
subCatsAry[elem] += 1;
catCountAry.shift()
} else {
for (i=0; i<=catCountAry.length; i++) {
subCatsAry[elem] += catCountAry.shift();
}
}
}
Any ideas?

Thanks

Removing Duplicate Items In Array
hi guys

i'm looking for a way of removing duplicate items in an array

i've done this so far


Actionscript Code:
//sort array so all items of the same content are grouped together
myArray.sort();
 
//loop through items, removing any sitting next to a duplicate
for (var i:Number = 0; i < myArray.length; i++) {
    if (myArray[i] == myArray[i+1]) {
        myArray.splice (i, 1);
    }
}

however, i always seems to end up with the first 2 items in the array being the same (although it works well after that)

i can't figure out why - hope you can help

obie

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&

Array In Object Doesn't Duplicate Upon Instantiating
I guess I'm victim of my own misunderstanding of OOP but can somebody tell me why if I create two instances of an object which itself creates another array object, I end up referencing the same array ?

I've attached some oversimplified code to make things clearer. Why are both arrays containing the same data ? Aren't they different objects ?










Attach Code

class test
{
public var index:Array = new Array();


public function add(someValue:String):Void
{
this.index.push(someValue);
}

}


And then, here is the code in my .fla file

myTest1 = new test();
myTest1.add('abc');

myTest2 = new test();
myTest2.add('def');


trace(myTest1.index);
trace(myTest2.index);

The result I get is:

abc,def
abc,def


I was expecting:

abc
def

HitTest Array And Duplicate Moive Clip Help
Help, I can't manipulate this array.

Ok,

I've got an array of draggable icons (with their absolute paths) on my _root timeline. They're duplicate movie clips. From within the icon movie clip I have a button with AS to drag and drop it any where on the stage. I want these icons to have collision detection such that if you drop one icon on top of another icon it returns it to the initial drag position.

The problem is that when I use a loop to go through and check if my icon has hit another one, I can't manipulate it to exclude the icon that I'm calling from. Here is where I'm at ... I've highlighted where I've gone wrong.



ActionScript Code:
on (release) {
    for (i=0; i<_root.duplicatediconspaths.length; i++) {
        [u]if (this.hitTest(_root.duplicatediconpaths[i]) && !this.hitTest(!this))[/u] {
            this._x = this.old_x;
            this._y = this.old_y;
        }
    }
    stopDrag();
}


Thanks in advance and happy new year!

Flash 4 Creating An Array On Screen With Duplicate Movieclip
Hi,

i want to create a virtual array (like a grid) in a flash 4 file. I've made up this script. The problem is that i do not see an entire grid, only the first horizontal line and the last vertical line. I think there's a problem in the depth of the created movieclip but I don't have a single clue what the problem is. Do you have an idea?

This is my script:

ActionScript Code:
while(i<10) {
    i++
    while(j<10) {
        j++
        depthOfMc++
        pos_x = i * 20
        pos_y = j * 20
        duplicateMovieClip("gridPoint_mc" , "gridPoint_x"+i+"_y"+j, depthOfMc);
        eval("gridPoint_x"+i+"_y"+j)._x = pos_x;
        eval("gridPoint_x"+i+"_y"+j)._y = pos_y;
    }
    j = 0
}

Problem With Duplicate Movie Clip Which Is Tracked In An Array
I have a problem with my inventory code using Shared Objects. What i did was to track the collected items in an array. Each time the user collects an item, the original iconMC is duplicated and loads a picture of the item (function loadImage). However, my problem is that this retains the original array so even if I already added new items into the inventory, the newest item doesn't show. original array length = 2, new array length = 3; the last item doesn't show. If I reload my flash, its the only time that this shows. Now if I get an item and lessen the inventory, it still retains the original length and doubles (or triples, depending on how many items i lessened) the last item.

var so:SharedObject = SharedObject.getLocal("lakbayUser", "/");
var i:Number = so.data.currentUserIndex;
var ctr = 0;
var iconCtr;
var iconArray: Array; //temporary storage of items placed inside icon

function selectIcon(num){
eval("iconMC"+num)._alpha = 0;
so.data.users[15][0] = true;
so.data.users[15][1] = iconArray;
}

//loads the next icon
function setNextIconMC(itemCtr, iconCtr){
if(iconCtr > 0) {
newName = "iconMC" + iconCtr;
newPos = 130 * iconCtr;
_root.itemaHolderMC.iconHolderMC.iconMC0.duplicateMovieClip(newName,iconCtr+1);//does not duplcate if unloadMovie is called
this[newName]._x = newPos;
this["iconMC"+iconCtr].enabled = true;
this["iconMC"+iconCtr]._alpha = 100;
loadMovie("gamit/icon"+itemCtr+".jpg",_root.itemaHolderMC.iconHolderMC[newName]);
trace(_root.itemaHolderMC.iconHolderMC[newName]);
}
else {
iconMC0.enabled = true;
iconMC0._alpha = 100;
loadMovie("gamit/icon"+itemCtr+".jpg",_root.itemaHolderMC.iconHolderMC.iconMC0);
}
}

//loads all the icons into the container
function loadImage(){
iconCtr=0;
iconArray = new Array();
for(itemCtr = 0; itemCtr < so.data.users[14].length; itemCtr++){
if(so.data.users[14][itemCtr] == true){
iconArray[iconCtr] = itemCtr;
setNextIconMC(itemCtr,iconCtr);
iconCtr++;
}
}
if(iconCtr==0){
iconMC0._visible = false;
}
else iconMC0._visible = true;
}

loadImage();
so.flush();
stop();

Search And Remove Duplicate And Consecutive Values In An Array
Hi. I have an array which I am populating as I navigate through the site. Sometimes due to cicumstances apparently out of my control, I end up with two (never more) duplicate values consecutively placed in my array, here is an example:

groceries = ["bananas", "apples", "apples", "oranges"];

I need to run a script at all times that checks to see if this happens, and removes the second duplicate value, as well as it's corresponding key.

How can I do this?

Thank you in advance!

[CS3] Problem With Duplicate Movie Clip Which Is Tracked In An Array
I have a problem with my inventory code using Shared Objects. What i did was to track the collected items in an array. Each time the user collects an item, the original iconMC is duplicated and loads a picture of the item (function loadImage). However, my problem is that this retains the original array so even if I already added new items into the inventory, the newest item doesn't show. original array length = 2, new array length = 3; the last item doesn't show. If I reload my flash, its the only time that this shows. Now if I get an item and lessen the inventory, it still retains the original length and doubles (or triples, depending on how many items i lessened) the last item.

It works perfectly fine during the first call. But if I call loadImage again, it doesn't duplicate the last clip.

Here's the code

Code:
//loads the next icon
function setNextIconMC(itemCtr, iconCtr){
if(iconCtr > 0) {
newName = "iconMC" + iconCtr;
newPos = 130 * iconCtr;
_root.itemaHolderMC.iconHolderMC.iconMC0.duplicateMovieClip(newName,iconCtr+1);//does not duplcate if unloadMovie is called
this[newName]._x = newPos;
this["iconMC"+iconCtr].enabled = true;
this["iconMC"+iconCtr]._alpha = 100;
loadMovie("gamit/icon"+itemCtr+".jpg",_root.itemaHolderMC.iconHolderMC[newName]);
}
else {
iconMC0.enabled = true;
iconMC0._alpha = 100;
loadMovie("gamit/icon"+itemCtr+".jpg",_root.itemaHolderMC.iconHolderMC.iconMC0);
}
}

//loads all the icons into the container
function loadImage(){
iconCtr=0;
iconArray = null;
iconArray = new Array();
for(itemCtr = 0; itemCtr < so.data.users[i][14].length; itemCtr++){
if(so.data.users[i][14][itemCtr] == true){
iconArray[iconCtr] = itemCtr;
setNextIconMC(itemCtr,iconCtr);
iconCtr++;
}
}
if(iconCtr==0){
iconMC0._visible = false;
}
else iconMC0._visible = true;
so.flush();
}

loadImage();

Can't Get String.slice To Work Right
I'm just doing this simple test to try and get an array made of individual letters from what once used to be a whole word, i.e:


Code:
onClipEvent(load){

test = new String("work")
var chopped = test.split("");
trace(chopped[])
}
according to Flash help if you have an empty string as the delimiter it puts each character into its own element, but this wont work for me. Whenever it's traced all I get is 'work' rather than the expected 'o'.

Anyonw know why I am FAILING

Slice And Dice Can't Get It To Work
ok lets say I have a variable
myvar = 24c (by the way I want to allow for more than double digits so this may end up being from 2c to 2345c)

and I want to just read the last letter ie "c"

well I have used the following without much luck

scs = new String(myvar);
scd=scs.substring(-1,0);
trace(scd);

should give me my c shouldn't it?

what am I doing wrong??

Thanx in advance

More Array Work -- Help
Hey guys

I am working on a History function in Flash that will show where the user is throughout the flash movie.

I would like to use arrays for this and just add and take away elements.

for example:

You start at HOME
so a variable has a value of HOME
at HOME there is a portfolio button

when you click on the portfolio button
the variable is now HOME:PORTFOLIO

If you go back to HOME, the variable becomes just HOME again.

and so on.

This is just to show where you are at all times while you go through a flash movie.

I have made it work, but if you keep clicking on PORTFOLIO button it keeps adding PORTFOLIO to the variable, and I only want to add it once even if I click on porfolio 100 times.

got it?

dduck1934

Array's Won't Work...
I'm using the following script to try to display one entry in an array:

Code:
myArray[0] = "January";
myArray[1] = "February";
myArray[2] = "March";
myArray[3] = "April";
_root.myDynamicText = _root.myArray[3];
For some reason that won't display "April" in the textfield. If I change the line to
Code:
_root.myDynamicText = "Just testing";
The above successfully changes the text... so I'm just having troubles using the array. What is wrong?

[CS3] Array - Why Does This Not Work?
I am passing this variable into flash:

customer_arry = "{name:""John"", age:33}, {name:""Jose"", age:41}"



In flash I have this code:

var my_dg:mx.controls.DataGrid;

var myDP_array:Array = new Array(customer_arry);
my_dg.dataProvider = myDP_array;


I have tested and know the the array is loading into the flash movie... but it is not loading the data in to the datagrid...

Please help??? thanks

Array Join Does Not Work
this is what works:
a = new Array(1,2,3,4,5,6);
ab_txt.text = a.join("
");

while, this does not:
n = file_name;
myArray = new Array(n);
for(i=0; i< myArray.length; i++){
file_txt.text = "filename = " + myArray.join("
");
}
the file names get displayed separated by commas, even though i have used the same .join("
") thing. the filenames get displayed so the loop is ok ( as far as i think).

Why Won't My Two-dimentional Array Work?
I've been used to C++ for a while now, and I'm trying to make my 1-d array into a 2-d array. (Becuase of the EXTREME amounts of confusion 1-d arrays make happen with tilemaps)

I have asked this question before. It was NOT ANSWERED. I really want this ANSWERED. Sorry to be rude, but I'm starting to hate this problem.

More specifically, I am trying to turn my 1 dimentional tilemap into a 2 dimentional array. (For many reasons, the most important being collision detection.) I have no clue how to do this. Just run my .fla and see what happens, I'm too pissed off to explain it again.

My FLA: My Problem File

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