dna
07-02-2007, 12:33 AM
I'm really missing something here. I've created this code (adapted from the AS3 Cookbook) so that I could work on learning how to do FocusManager stuff. However, I've encountered a problem I cannot figure out. The code creates 3 Simple buttons, each identical, with functions to create the (identical) upstate, overstate and downstate for each. The hit test state is assigned for each to be the same as the overstate. A simple mouse event traces "Mouse clicked the button" when each button is clicked.
For some reason that I totally cannot figure out, there is an instance of the downState drawn up in the top left corner. I've tried commenting out all references to the downstate and this instance remains, but is changed to an instance of the upstate.
Odder still, if I click all three buttons in any order (but must be all three) the random floating button state disappears. I have been sitting and staring at this for quite a while. The code is so simple, and is throwing no errors. Where is this ghost button coming from?
I've attached the .fla.
Thanks in advance, if it's a stunningly simple flaw somewhere I'll be more relieved than embarassed...;) dina
var leftbutton:SimpleButton = new SimpleButton();
leftbutton.x = 50;
leftbutton.y = 300;
leftbutton.upState = createUpState();
leftbutton.overState = createOverState();
leftbutton.downState = createDownState();
leftbutton.hitTestState = leftbutton.upState;
leftbutton.addEventListener(MouseEvent.CLICK, handleClick);
var middlebutton:SimpleButton = new SimpleButton();
middlebutton.x = 200;
middlebutton.y = 300;
middlebutton.upState = createUpState();
middlebutton.overState = createOverState();
middlebutton.downState = createDownState();
middlebutton.hitTestState = middlebutton.upState;
middlebutton.addEventListener(MouseEvent.CLICK, handleClick);
var rightbutton:SimpleButton = new SimpleButton();
rightbutton.x = 350;
rightbutton.y = 300;
rightbutton.upState = createUpState();
rightbutton.overState = createOverState();
rightbutton.downState = createDownState();
rightbutton.hitTestState = rightbutton.upState;
rightbutton.addEventListener(MouseEvent.CLICK, handleClick);
function createUpState():Sprite {
var sprite:Sprite = new Sprite;
sprite.graphics.lineStyle(8, 0xFF0000);
sprite.graphics.beginFill(0x990000);
sprite.graphics.drawRoundRect(0,0,130,86,20);
sprite.graphics.endFill();
addChild(sprite);
return sprite;
}
function createOverState():Sprite {
var sprite:Sprite = new Sprite;
sprite.graphics.lineStyle(8, 0x66FF33);
sprite.graphics.beginFill(0x990000);
sprite.graphics.drawRoundRect(0,0,130,86,20);
sprite.graphics.endFill();
addChild(sprite);
return sprite;
}
function createDownState():Sprite {
var sprite:Sprite = new Sprite;
sprite.graphics.lineStyle(8, 0xFF0000);
sprite.graphics.beginFill(0x999999);
sprite.graphics.drawRoundRect(0,0,130,86,20);
sprite.graphics.endFill();
addChild(sprite);
return sprite;
}
addChild(leftbutton);
addChild(middlebutton);
addChild(rightbutton);
function handleClick(event:MouseEvent):void
{
trace("Mouse clicked the button");
}
For some reason that I totally cannot figure out, there is an instance of the downState drawn up in the top left corner. I've tried commenting out all references to the downstate and this instance remains, but is changed to an instance of the upstate.
Odder still, if I click all three buttons in any order (but must be all three) the random floating button state disappears. I have been sitting and staring at this for quite a while. The code is so simple, and is throwing no errors. Where is this ghost button coming from?
I've attached the .fla.
Thanks in advance, if it's a stunningly simple flaw somewhere I'll be more relieved than embarassed...;) dina
var leftbutton:SimpleButton = new SimpleButton();
leftbutton.x = 50;
leftbutton.y = 300;
leftbutton.upState = createUpState();
leftbutton.overState = createOverState();
leftbutton.downState = createDownState();
leftbutton.hitTestState = leftbutton.upState;
leftbutton.addEventListener(MouseEvent.CLICK, handleClick);
var middlebutton:SimpleButton = new SimpleButton();
middlebutton.x = 200;
middlebutton.y = 300;
middlebutton.upState = createUpState();
middlebutton.overState = createOverState();
middlebutton.downState = createDownState();
middlebutton.hitTestState = middlebutton.upState;
middlebutton.addEventListener(MouseEvent.CLICK, handleClick);
var rightbutton:SimpleButton = new SimpleButton();
rightbutton.x = 350;
rightbutton.y = 300;
rightbutton.upState = createUpState();
rightbutton.overState = createOverState();
rightbutton.downState = createDownState();
rightbutton.hitTestState = rightbutton.upState;
rightbutton.addEventListener(MouseEvent.CLICK, handleClick);
function createUpState():Sprite {
var sprite:Sprite = new Sprite;
sprite.graphics.lineStyle(8, 0xFF0000);
sprite.graphics.beginFill(0x990000);
sprite.graphics.drawRoundRect(0,0,130,86,20);
sprite.graphics.endFill();
addChild(sprite);
return sprite;
}
function createOverState():Sprite {
var sprite:Sprite = new Sprite;
sprite.graphics.lineStyle(8, 0x66FF33);
sprite.graphics.beginFill(0x990000);
sprite.graphics.drawRoundRect(0,0,130,86,20);
sprite.graphics.endFill();
addChild(sprite);
return sprite;
}
function createDownState():Sprite {
var sprite:Sprite = new Sprite;
sprite.graphics.lineStyle(8, 0xFF0000);
sprite.graphics.beginFill(0x999999);
sprite.graphics.drawRoundRect(0,0,130,86,20);
sprite.graphics.endFill();
addChild(sprite);
return sprite;
}
addChild(leftbutton);
addChild(middlebutton);
addChild(rightbutton);
function handleClick(event:MouseEvent):void
{
trace("Mouse clicked the button");
}