mankis
asked on
AS3 can custom Event class extend MouseEvent?
I need to pass variables in to a function with MouseEvent.CLICK.
How can I do that, is there a way to make custom Event class that extends MouseEvent?
Do you know some tutorial?
How can I do that, is there a way to make custom Event class that extends MouseEvent?
Do you know some tutorial?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
actually once I have clicked very quickly and I get penultimate number (array.length-1), but when I click again (on any button on the stage) I get the last number (array.length)
ASKER
no, sorry I'm telling it wrong, I'm getting the last (a + br) number, but it is important that is not working
ASKER
I have changed my function a little bit so now I have objects in array that contains movieclip and other vars
so now I have object id like this:
kvadrati[a + br].id
and movieclip like this:
kvadrati[a + br].kvadarmc
but I still don't know how to pass kvadrati[a + br].id into function when i click on kvadrati[a + br].kvadarmc?
so now I have object id like this:
kvadrati[a + br].id
and movieclip like this:
kvadrati[a + br].kvadarmc
but I still don't know how to pass kvadrati[a + br].id into function when i click on kvadrati[a + br].kvadarmc?
ASKER
do I need a class that extends MovieClip instead of this Object that I used?
ASKER
I have created new Class that extends MovieClip and now I can access id property from function. So I wasn't able to pass the variable to the function, I just found another solution. If you have a solution for my question (how to pass variable to a function with MouseEvent.CLICK) I would still like to hear it.
the code snippet you showed above, which of the solutions are you supposed to be using there from the link halfbloodprince posted?
ASKER
hi, sorry, no, I now have something like this
function createPage(e:MouseEvent) {
trace("mc id = "+e.target.id);
}
function addButtons() {
for (a=0; a<numbr; a++) {
br = br+n[a];
try {
kvadrati[a + br].addChild(forattach[a]);
kvadrati[a+br].getChildAt(1).getChildByName("insidebtn").alpha = 0;
TweenLite.to(kvadrati[a+br].getChildAt(1).getChildByName("insidebtn"), 0.5, {alpha:1});
kvadrati[a + br].addEventListener(MouseEvent.CLICK, createPage);
} catch (e:ArgumentError) {
trace(e);
}
}
}
ASKER
this is my extended MovieClip class that I use for creating this movie clip
package {
import flash.display.*;
import flash.events.*;
public class Kvadarmc extends MovieClip {
public var pozicijax:Number;
public var pozicijay:Number;
public var id:int;
public function Kvadarmc() {
this.pozicijax=0;
this.pozicijay=0;
this.id=0;
}
}
}
ASKER
so when I create my array of moviclips I do it like this
for (j=0; j<=numlength; j++) {
kvadrati[j]=new Kvadarmc();
addChild(kvadrati[j]);
kvadrati[j].id=j;
}
ok it might be easier if you zip everything up and upload it then all the bits and pieces.
ASKER
i can't do that, it's the whole project that I'm working on, it's too big and I don't wont to share everything
ASKER
I just find out that the problem is not in my or halfbloodprince solution, both work.
The problem is that I have MovieClip that is child of another MovieClip and that MovieClip is a child of another MovieClip, and although I have put listener only for parent MovieClip like this
kvadrati[a + br].addEventListener(Mouse Event.CLIC K, createPage);
function createPage traces every time a different MovieClip, somethimes it's the parent, somethimes it's the child MovieClip, or the second child. I don't understand why is this happening. I will accept halfbloodprince solution because I get variables passed, but the problem is in target, and that is for some other question.
The problem is that I have MovieClip that is child of another MovieClip and that MovieClip is a child of another MovieClip, and although I have put listener only for parent MovieClip like this
kvadrati[a + br].addEventListener(Mouse
function createPage traces every time a different MovieClip, somethimes it's the parent, somethimes it's the child MovieClip, or the second child. I don't understand why is this happening. I will accept halfbloodprince solution because I get variables passed, but the problem is in target, and that is for some other question.
ASKER
Open in new window