-
Problems with buttons inside MC added with addChild.
I have my Stage. On this I have an empty MovieClip (MC).
To begin with I do:
MCContent = new TestMC();
MC.addChild(MCContent);
This works.
But in my TestMC, I have another MovieClip Button01, which is named Button01, where I have the code:
Button01.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
function handleMouseUp(event:MouseEvent):void {
trace('Hello World);
}
But when I click on Button01 nothing happens... What am I doing wrong?
-
Senior Member
Code:
MCContent = new TestMC();
MC.addChild(MCContent);
MCContent.Button01.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
function handleMouseUp(event:MouseEvent):void {
trace('Hello World);
}
I don't have flash handy to test right now but will help more tonight if need be. But anyway, give this a whirl and let me know what happens.
-
That didn't work, got the error:
"...: Access of undefined property MCContent."
I tried:
Object(root).MCContent.ImageButton.addEventListene r(MouseEvent.MOUSE_UP, handleImageMouseUp);
and that don't report any error, but doesn't do anything
Any other ideas?
-
Senior Member
So Button01 is in MCContent, right?
Do you have a var declaration with the MCContent clip?
-
Button01 is inside TestMC, which is a MovieClip added to MC via addChild, from the code:
MCContent = new TestMC();
MC.addChild(MCContent);
Does that make sense?
-
Senior Member
Code:
var MCContent:MovieClip = new TestMC();
MC.addChild(MCContent);
So you have that, right?
If I got you now, this should do it:
Code:
trace("Here's the line up, if one returns null, we know that it isn't getting set up somewhere");
trace(MC);
trace(MC.MCContent);
trace(MC.MCContent.Button01);
trace("End of Line up");
MC.MCContent.Button01.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
function handleMouseUp(event:MouseEvent):void {
trace("Hello World");
}
I added more traces as well to trace out values. They should all return Object MovieClip when traced I beleive.
-
I get:
Access of undefined property MC
on all 3 lines.
The code is inside TestMC and NOT my main stage, I guess that's why it cannot find MC.
-
If I just have the code:
trace("Here's the line up, if one returns null, we know that it isn't getting set up somewhere");
trace(Button01);
trace("End of Line up");
Button01.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
function handleMouseUp(event:MouseEvent):void {
trace("Hello World");
}
I get:
Here's the line up, if one returns null, we know that it isn't getting set up somewhere
[object MovieClip]
End of Line up
But clikcing on the button doesn't output "Hello World".
-
Senior Member
Oh, your button code is in TestMC?
And you want a click,
Okay, try this:
Code:
Button01.addEventListener(MouseEvent.CLICK, handleMouseClick);
function handleMouseClick(evt:MouseEvent):void {
trace("Hello World");
}
My apologies, I must have misunderstood you.
Let me know if this works for you.
-
That worked! What is the difference?
-
Senior Member
the MOUSE_UP event is really not meant for the functionality you were after. The CLICK event is what's meant to handle the event of capturing a mouse press. The MOUSE_UP event is kinda sketchy honestly. It's made to handle when the mouse is let up but it doesn't always do that.
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
|