-
Calling indices in Multiple Array
Hi,
I'm a newbie and I am trying to set up a multiple array where I can call on the mc object and then add an EventListtener and getting into all kinds of strife.
My version of Action-script is 3 and I'm running Flash CS6 Here is my code;
import flash.events.Event;
Code:
{
var myPieces:Array = new Array(6); // there are six rows
myPieces[0] = [pc1_mc,targpc1_mc,160.30,162.90];
myPieces[1] = [pc2_mc,targpc2_mc,291.50,162.90];
myPieces[2] = [pc3_mc,targpc3_mc,425.50,162.90];
myPieces[3] = [pc4_mc,targpc4_mc,147.65,304.50];
myPieces[4] = [pc5_mc,targpc5_mc,291.00,305.15];
myPieces[5] = [pc6_mc,targpc6_mc,435.40,303.85];
for (var row:int=0; row <=5; row++)
{
for (var column:int=0; column <=3;column++)
{
forEach (object in(var i[0] in myPieces));
{
i.buttonMode = true;
i.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
i.addEventListener(MouseEvent.MOUSE_UP, dropObject);
}
function pickupObject(event:MouseEvent):void
{
event.target.startDrag(true);
}
function dropObject(event:MouseEvent):void
{
event.target.stopDrag();
}
}
}
}
I'm getting several errors on row 16
Error 1084: Syntax error: expecting rightparen before each.
Error 1084: expecting identifier before rightparen.
Error 1084: exptecting identifier before var.
Would appreciate any support.
Thanks in advance.
Regards
Tanya
-
.
Hi,
Attach your *.fla so we dont need to have to try and mimick your file, graphics and clips etc.
Please then explain what you require help with.
-
you write
for (var column:int=0; column <=3;column++)
{
forEach (object in(var i[0] in myPieces));
{
i.buttonMode = true;
not good
@+gustave02
-
Prid - Outing
Hi,
I may not be an AS3 expert, but that code looks a bit erroneous to me. I believe you're trying to access the first column of all the rows, which contains the MovieClips. If you think it this way, that you want to go through each row and simply fetch the first column-value of that row, then you'd have the code simplified to something like this:
Code:
var myPieces:Array = new Array(6); // there are six rows
myPieces[0] = [pc1_mc,targpc1_mc,160.30,162.90];
myPieces[1] = [pc2_mc,targpc2_mc,291.50,162.90];
myPieces[2] = [pc3_mc,targpc3_mc,425.50,162.90];
myPieces[3] = [pc4_mc,targpc4_mc,147.65,304.50];
myPieces[4] = [pc5_mc,targpc5_mc,291.00,305.15];
myPieces[5] = [pc6_mc,targpc6_mc,435.40,303.85];
for (var row:int=0; row < myPieces.length; row++)
{
var i:MovieClip = myPieces[row][0];
i.buttonMode = true;
i.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
i.addEventListener(MouseEvent.MOUSE_UP, dropObject);
function pickupObject(event:MouseEvent):void
{
event.target.startDrag(true);
}
function dropObject(event:MouseEvent):void
{
event.target.stopDrag();
}
}
myPieces.length simply returns the number of rows, which is 6, but your condition >= 5 also works just fine. We make a variable i and store the first cell/column-value for the current row in the for loop, making it contain your variables one at a time. Then we can simply add event listeners to those movieclips and voilÃ*, it works
Your code didn't really make any logical sense as you were traversing (going through) all the rows and all the columns, yet while doing so it seemed like you were trying access all the objects in first column and adding those listeners to them -- but that code syntax looked wrong, in my opinion. But salute to you for trying given that you're a newbie as you stated yourself
Unless there are movieclips inside pc_mc movieclips to which you're trying add those listeners. In that case, to my surprise, the code above still works, and that's because you're not dragging those movieclips (pc_mc's), rather in your dragging functions it says: event.target.startDrag(true); -- and event.target will return the movieclip you clicked on/pressed down, which is why the above code should be sufficient for you regardless of how one might interpret your problem
Hope this helps
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Response - Including Flash File
Originally Posted by Nig 13
Hi,
I may not be an AS3 expert, but that code looks a bit erroneous to me. I believe you're trying to access the first column of all the rows, which contains the MovieClips. If you think it this way, that you want to go through each row and simply fetch the first column-value of that row, then you'd have the code simplified to something like this:
Code:
var myPieces:Array = new Array(6); // there are six rows
myPieces[0] = [pc1_mc,targpc1_mc,160.30,162.90];
myPieces[1] = [pc2_mc,targpc2_mc,291.50,162.90];
myPieces[2] = [pc3_mc,targpc3_mc,425.50,162.90];
myPieces[3] = [pc4_mc,targpc4_mc,147.65,304.50];
myPieces[4] = [pc5_mc,targpc5_mc,291.00,305.15];
myPieces[5] = [pc6_mc,targpc6_mc,435.40,303.85];
for (var row:int=0; row < myPieces.length; row++)
{
var i:MovieClip = myPieces[row][0];
i.buttonMode = true;
i.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
i.addEventListener(MouseEvent.MOUSE_UP, dropObject);
function pickupObject(event:MouseEvent):void
{
event.target.startDrag(true);
}
function dropObject(event:MouseEvent):void
{
event.target.stopDrag();
}
}
myPieces.length simply returns the number of rows, which is 6, but your condition >= 5 also works just fine. We make a variable i and store the first cell/column-value for the current row in the for loop, making it contain your variables one at a time. Then we can simply add event listeners to those movieclips and voilÃ*, it works
Your code didn't really make any logical sense as you were traversing (going through) all the rows and all the columns, yet while doing so it seemed like you were trying access all the objects in first column and adding those listeners to them -- but that code syntax looked wrong, in my opinion. But salute to you for trying given that you're a newbie as you stated yourself
Unless there are movieclips inside pc_mc movieclips to which you're trying add those listeners. In that case, to my surprise, the code above still works, and that's because you're not dragging those movieclips (pc_mc's), rather in your dragging functions it says: event.target.startDrag(true); -- and event.target will return the movieclip you clicked on/pressed down, which is why the above code should be sufficient for you regardless of how one might interpret your problem
Hope this helps
I copied your code over and it is still not working.. The file itself is too large (image size) so here is a link to my cloud storage:
-
Last edited by gustave02; 03-02-2015 at 11:27 AM.
-
Prid - Outing
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
i modified the fla with currentTarget
@+ gustave02
-
This Newby is so confused.
Thank you to both gustar02 and Nig13, for hanging in there and in particular for Nig13, your patience in trying to explain to me what is happening with the code, but when I run each it isn't happening.
I have since gone back to basics (I have some limited Pascal and Python experience) and want to keep the code as simple as possible.
What I really want to do is test to see if the current target is in proximity to targ and then drop it. Hence the convoluted multiple array I tried to use.
I've gone back to a single array to allow pickup and drop, but keep coming up with errors about the brackets. This is driving me crazy.
Here is my new code which allows me to pick up and drop object successfully:
Code:
import flash.events.Event;
{
var pieces = [pc1_mc,pc2_mc,pc3_mc,pc4_mc,pc5_mc,pc6_mc]
for each (var i in pieces)
{
i.buttonMode = true;
i.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
i.addEventListener(MouseEvent.MOUSE_UP, dropObject);
}
function pickupObject(event:MouseEvent):void
{
event.currentTarget.startDrag(true);
}
function dropObject(event:MouseEvent):void
{
event.currentTarget.stopDrag();
}
}
Now when I add these lines of code to see if the piece is in proximity, I start getting syntax error 1087
Code:
if (i.hitTestObject(targpc1_mc))
{
pc1_mc.x=117.50; // x coordinate for pc1
pc1_mc.y=143.00; // y coordinate for pc1
pc1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
}
I could of course then write these extra lines of code (if this was working) for each piece and matching target. But I don't believe this is the most efficient method.
You ongoing support and instruction is appreciated.
Here is my latest version.
https://app.box.com/s/yqmdnpvtd8qize03224pj5ugjg5dmgn8
-
Senior Member
I just stuff refrences to the movie clip in an array using a for loop ant the Array.push(mc) during the loops iteration you could attach a eventlistner that changes to whatever function u want that listener to listen on .......heck I'd probably use a second array for the xy coordiantes if I wanted to dynamically assign the mc movie clips positions. probabably wouldn't have a huge impact on hardware of VM performance.
--calmchess
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|