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




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



KirupaForum > Flash > ActionScript 3.0
Posted on: 10-20-2007, 12:24 AM


View Complete Forum Thread with Replies

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

Duplicate Movieclip, Drag Duplicate, Leave Original Behind
Hello all,

I have been searching frantically for an answer to this. I know it has to be easy....

I want to duplicate a movieclip on press and also drag the duplicate, leaving the original behind. I've attached a sample of what I'm doing. Does anyone have any ideas? Is there a way to target the duplicated movieclip to drag that? And leave the original in it's original location?

Any help, guidance, nudging would be greatly appreciated. I've been trying to figure this out for hours.

Thanks,
jessicuh

Offset Duplicate MC From Original
hi is there a simple way i can make a duplicate MC offset the original so it doesn't appear exactly on top? thanks!

Removing Duplicate And Original Movie Clips
Hi,

I have duplicated a movie clip which the user can move using the cursor keys, however the script used to do this is attached to the origianl movie clip and when run the main movie and move my duplicated clip around both MCs appear on the screen. Is there any way I can remove the origianl clip?

Thanks
Andy

Array Copy Points To Original Array Instead Of Duplicating
Hey all.
Spent a long time trying to figure out what was wrong with my code. Then I remembered about arrays being objects instead of primitive variables. My question is, how can I make a duplicate copy of an Array?

Details:

So this code

PHP Code:




package{
    import flash.display.*
    public class tester extends MovieClip{
        var a:Array = [1,2]
        public function tester () {
            var b = a
            trace (a)
            b.splice(1,1)
            trace (a)
        }
    }
}







results in this output:

PHP Code:




1,2
1







How can i make b an actual duplicate of a, instead of a pointer?

PHP Code:




b = new Array
b = a






doesn't work either.
Thanks!
DHP

Flash 8 - Re-order An Array, Simple Binding Of Xml
I am prototyping a data table display. I need to show a data table inside a grid, using a simple xml file such as the one in the "DinnerMenu" tutorial whereby a button loads the xml file into the data grid component.

I want to know how to set the order of the fields to display from left to right in the table (which I haven't figured out how to do) either in the component settings or in the xml file, wherever it works.

Then, I also would like to know how to get the data load immediately when user reaches the scene, or just have it already pre-loaded. Right now, al I know is the tutorial method where the actionscript defines the button and onclick the data is loaded. I want to show it already there.

Thank you!

Random Array Shuffle That Never Chooses Original Value
Hi.
I'm trying to produce a random array that shuffles numbers. The problem is I don't want any array position to be what it was before (or repeated) EG:

Original Array:
[0] = 0
[1] = 1
[2] = 2

After shuffling - not what I want:
[0] = 2
[1] = 1
[2] = 0

Even though this has been randomly shuffled, this is not what I want.

This is what I'm looking for:

[0] = 1
[1] = 2
[2] = 0

Here none of the original values are what they previously where.

Can anyone please help?

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!

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

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

[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 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();

Xml Binding And Use
Here is what I have.
I have a frame that uses the xml connector to get data from and xml doc. I have that working fine. What I want to do is
1) put a frame before that that stops until a button is clicked then goes to the frame with the data.

2) I would like to have a screen before that to have the user log in with a username and password that is in the xml that is being used by the connecter.

How can I do this? I know enough about this process to get the data in but if I create a frame before the data frame and put a stop in there after the trigger then I get no data when the button is clicked and it goes to the data frame.

HELP ME,
Pyromaster

Binding Problem
Hi everybody,
I'm new to FlashMX 2004 and I'm trying to figure this out:

I'm reading data from an XML sheet using an XMLConnector. I bind the content of a particular node to a label by specifying an Xpath like this:

/node1/node2[@id=5]

Now, I have to modify this xPath during runtime, dynamically changing the expression id=5 so I could show a node at a time.
How do I do that?

Should this be done in some other way? Maybe using a dataset?
Many thanks in advance

Binding Flash With Xml
hi.. i'm a newbie in Flash. i've tried to make bouncing menu similar to http://www.faithornstudios.com/bounc...emo/index.html using flash and xml.
my question are [ based on the flash ]:
1. how to make the links opened on the same place in Flash ? [contents]
2. how to edit the xml to make the button to open things like movie, text or picture [ getUrl or whatever, can't understand xml ]
and optional questions
3. how to put a streaming video from the internet into the flash
4. can we make a message box in Flash, so anyone can put their msg in it ??

you can viewmy try and eror result - flash and also my xml

thats all..

Binding Properties
I am trying to bind the selectedItem property of the tree component to something else but it is not working.... the comboBox component works....

what am I missing?

XML Binding And Levels
I am working on a site that has an XML-driven photo gallery. The actual URL for the photo gallery works by itself (http://www.coachcallahan.com/photoalbum.swf) but when it loads on level one in the main movie it no longer brings up the photo although it still brings up the caption(http://www.coachcallahan.com/ GO TO THE NEWS AND PHOTOS). Does anyone have any ideas why this would be happening?

XML Binding And Levels
I am working on a site that has an XML-driven photo gallery. The actual URL for the photo gallery works by itself (http://www.coachcallahan.com/photoalbum.swf) but when it loads on level one in the main movie in level 1 it no longer brings up the photo although it still brings up the caption(http://www.coachcallahan.com/ GO TO THE NEWS AND PHOTOS). Does anyone have any ideas why this would be happening?

Binding Object
Is there anyway to binded 1 object to another. Like binding the hand to the arme. This so i can make a person wave his hand + arm.

Binding Objects
....ok I have a mass problem...
I have a two scenes in a single .fla. One of them is a catalog of some furniture (visualy drawed, designed), and in it there are txt fields that need to be changed (updated). So I did another scene with the same table (but not visualy designed) with input txt fields. Now, I want, when I put some txt in one field (with variable a), I want it to show up in the first scene (designed catalog) on the selected place...

I hope you understand...
tnx

Binding In As3: Questions
Hello everyone

I have trouble trying to emulate binding: I explain:

I have a degrafa surface into a canvas container. I want to link both width and height. When i use binding with Binding utils like in the following code it works as expected:



Code:
public class RectangleShape extends BaseShape
{
public function RectangleShape(fillColor:int) {
super.name = shapeName;
solidFill.color = fillColor;


// shape
solidFill.alpha = 0.3;
rect.fill = solidFill;
rect.stroke = solidStroke;
geoGroup.geometryCollection.addItem(rect);
geoGroup.target = surface;

surface.graphicsCollection.addItem(geoGroup);
this.addChild(surface);

// binding
// BindingUtils.bindProperty(rect,"height",this,"height");
// BindingUtils.bindProperty(rect,"width",this,"width");
}




override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

trace(unscaledWidth, unscaledHeight);
this.width = unscaledWidth;
rect.width =unscaledWidth;
this.height = unscaledHeight;
rect.height = unscaledHeight;

}
Now, someone told me that i should better do it on validateSize() or updateDisplayList(), with my current knowledge of flex i dont realy know why but i tried as you can see in updateDisplayList


The degrafa rectangle get resized well but not the canvas container which stays at zero, even tho its width and height are set. When i fall back to binding its all fine again.

Any ideas on how could i achieve the same as binding using updateDisplayList ? i would like to do a little bit of processing there as well.

Thanks a lot for any hints.

===========================

My second question is related to xml:

As you can see here i use the same calculations inthe binding several times:

Code:


<degrafa:GeometryGroup>
<repeaters:GeometryRepeater count="{( width /20) + 1}">
<geometry:HorizontalLine stroke="{white}" x = "0" x1= "{width}" y="{Math.round(height / 2 / 20 )*20}"/>
<geometry:RasterText id="ordTxt" text="1" size="12" fontFamily="Arial" x="0" y="{Math.round(height / 2 / 20 )*20}" color="0xFFFFFF" />

<geometry:Line x="0" x1="0" y="{height / 2 + 3} " y1="{height / 2 - 2}" stroke="{white}" id="ord"/> ...


When the code is compiled by flash will the calculation be repeated everytime ? if so i would like to optimise it by converting the xml in as3 and using a variable to hold the rounding calc. Width and Height get resized in real time quite often and right now its kind of slow (maybe it comes from the repeaters tho).

Should i convert it to as3 ?

Flash Binding Xml And Xsl
I'm looking to bind an XML document in a Movie clip but I want it to use the xsl that is attached to that xml. is that possible?

Binding In First Frame?
I'm trying to make a simple application with buttons to jump between frames and in each frame there are components such as comboboxes and checkboxes which values should come from .xml via xml connector.

Now, when I try to bind for example a combobox to the xml connector, it says in the component inspector: "A Component instance must exist in the first frame to edit its bindings". ???

How is it possible to make even a simplest application with navigation if all the components must be in the first frame??? Is there a solution for this?

I tried to put the components and xml connector in a movieclip of their own so that the components would be in the first frame of THAT timeline, but then it don't even find the xml connector in the component inspector when I'm trying to bind it???

Am I doing something wrong or are the components just so "infantile" that you can't create anything a bit more complex application with them?

Please help :(

XML / Data Binding
Hello,

I am having trouble figuring out data binding. I have 1 XML doc and multiple swf files. What I want to do is have each swf seach through the XML doc for a particular name and then show the data relating to that name. Here is an example of the xml...


<IMAGE NAME="Item 1">
<DESCRIPTION>Copy for item 1 goes here...</DESCRIPTION>
<IMAGE>images/1.jpg</IMAGE>
</IMAGE>
<IMAGE NAME="Item 2">
<DESCRIPTION>Copy for item 2 goes here...</DESCRIPTION>
<IMAGE>images/2.jpg</IMAGE>
</IMAGE>

So, one swf would look for the NAME "Item 1" and then display "Copy for item 1 goes here..." and the image loacted at "images/1.jpg"

Thanks!

Custom Binding
Working on some calculating tool for a client, i needed to bind my controller components to various properties calculated by the program. It is a single stated program, so i don't have to worry about removing the bindings at the moment. Ease of use and performance is crucial as there is a lot of variables to bind.

It's made in Flash CS4, but i wondered if I should use the solution in other AS3 projects as well, but I am not sure how good the solution is.

Is it something to work on?
Is there better solutions (easier to use, or better in performance)?

Examples:

BindString.as

PHP Code:



package bindings {            /* Class */        public class BindString {                        /* Private properties */                private var _string:String = new String();        private var _binds:Array = new Array();                        /* Getters and setters */                public function set string(s:String):void {            _string = s;            for (var i:int = 0; i < _binds.length; i++) {                _binds[i]();            }        }                public function get string():String {            return _string;        }                        /* Methods */                public function bindTo(f:Function):void {            _binds.push(f);        }                    }    } 




Use:

PHP Code:



var myString:BindString = new BindString();myString.bindTo(onMyStringChange);function onMyStringChange():void {    trace("string changed to", myString.string);}myString.string = "Yo"; 




Same principle goes for int, Number, Boolean, etc.

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