FORUMS: list search recent posts

arrays and indexing movie clips

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
matt watts
arrays and indexing movie clips
on Nov 9, 2009 at 10:14:48 pm

In the following code, the on1,on2,on3,on4,on5 are instance names given to 5 buttons. all five of the buttons ARE SUCCESFULLY responding to the Press1 function below.

var ONarray:Array=new Array("on1","on2","on3","on4","on5");
for (var i:uint; i < ONarray.length; i++) {
var ON:MovieClip=getChildByName(ONarray[i]) as MovieClip;
stop();
ON.buttonMode = true;
ON.addEventListener(MouseEvent.MOUSE_DOWN, Press1);
}

function Press1(e:MouseEvent):void{
"FUNCTION HERE"
}



The problem: when each button is clicked it needs to send out its number (i'm using binary sockets for that).
the problem is i dont' want to copy the code for each button (cause there's eventually gonna be nearly 200 buttons), so in my function, when the button is clicked, it needs to write two things: it's instance name, and the fact that it was pressed:

binarySocket.writeUTFBytes("ONarray[i]"+"Pressed");

when i try this i traced it and it says "undefined Pressed" when it should say something like "on3 Pressed" (otherwise I won't know WHICH buttons is being pressed!
when i trace just [i] by itself, it always comes out as the number 5....no matter which button is clicked.
any ideas? i think im really close. thanks for any advice W


Return to posts index

Clint Milner
Re: arrays and indexing movie clips
on Nov 10, 2009 at 1:17:49 pm

I'm no pro, but have you tried:

trace(ONarray[i].name + " Pressed");

I don't know if .name is the right method of the Array class to access the instance name of each element, but it's worth a shot looking that up.

Hope that is a little helpful.

Clint


Adobe CS4 Master Suite
Vista Ultimate 64 SP1
Intel Core i7 920 @ 3.60GHz
12 GB DDR3 RAM
NVidia Quadro FX 3700
Matrox RT.X2 LE Capture Card
4 TB RAID 5


Return to posts index

matt watts
Re: arrays and indexing movie clips
on Nov 10, 2009 at 8:30:54 pm

your solution almost worked, heres the solution

(DisplayObject(e.currentTarget).name + "pressed");

thanks

i have another question, I built one of those click-and-drag rotating images. basically you click on it and drag left to right and it will scroll through a series of images in the timeline to make it appear like the object in the images is rotating

the problem is I want to be able to click-and-drag the mouse up-and-down, AND left-and-right. Right now I can program it to do one or the other, but not both. if i put left,right,up,AND down in the code it ignores one or the other.

any ideas?
heres the code
photos.stop();

var startX:Number;
var startY:Number;
var startFrame:int;
var changeDistance:int;
var travelDistance:int;


photos.buttonMode = true;
photos.addEventListener(MouseEvent.MOUSE_DOWN,
pressHandler);

function pressHandler(evt:MouseEvent):void {
startX = photos.mouseX;
startY = photos.mouseY;
startFrame = photos.currentFrame;
stage.addEventListener(MouseEvent.MOUSE_MOVE,
moveHandler);
stage.addEventListener(MouseEvent.MOUSE_UP,
releaseHandler);
}

function releaseHandler(evt:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE,
moveHandler);
stage.removeEventListener(MouseEvent.MOUSE_UP,
releaseHandler);
}

function moveHandler(evt:MouseEvent):void {

changeDistance = Math.round((photos.mouseX
- startX)/30);
travelDistance = startFrame + changeDistance;
if (travelDistance > photos.totalFrames) {
photos.gotoAndStop(travelDistance %
photos.totalFrames);
} else if (travelDistance < 0) {
photos.gotoAndStop(photos.totalFrames +
(travelDistance % photos.totalFrames));
} else {
photos.gotoAndStop(travelDistance);
}
}


right now (with this code) it will click and drag left to right only...


Return to posts index


Clint Milner
Re: arrays and indexing movie clips
on Nov 11, 2009 at 9:13:29 am

It's a bit over my head now and not seeing the swf now makes it a little harder, but I'm wondering if it's because it's a timeline animation and you're using gotoAnd... commands to navigate.

It's almost like you need AS3 to do the scrolling dynamically.

http://www.gotoandlearn.com/play?id=103 is a good tutorial that shows how to respond to x and y coords.


If that doesn't help, try starting a new post to see if anyone else can help.

Clint

Adobe CS4 Master Suite
Vista Ultimate 64 SP1
Intel Core i7 920 @ 3.60GHz
12 GB DDR3 RAM
NVidia Quadro FX 3700
Matrox RT.X2 LE Capture Card
4 TB RAID 5


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]