views:

164

answers:

2

UPDATE: This is not an actual issue. It transpires that there was another Sprite being create and set to alpha=0 which just happend to be at the same Y position as the height of the SimpleButton. This was preventing interaction with the button. Thanks to the guys for your thoughts. I'm closing the question.


I have a SimpleButton which I am positioning on the stage. I'm doing a variety of things with it buy when I set it's Y position it breaks/alters the hitArea.

var playUp:Bitmap = getBitmap('play_up');
var playDown:Bitmap = getBitmap('play_down');

var Y:Number = 100;

_playButton = new SimpleButton(playDown, playUp, playDown, playDown);
_playButton.addEventListener(MouseEvent.CLICK, playClick);
_playButton.x = (640 / 2) - (_playButton.width / 2);
_playButton.y = Y;
_playButton.name = "playButton";
var shadow:DropShadowFilter = new DropShadowFilter();
shadow.distance = 5;
shadow.angle = 25;
shadow.alpha = 0.5;
shadow.blurX = 8;
shadow.blurY = 8;
_playButton.filters = [shadow];
addChild(_playButton);

If I remove the line _playButton.y = Y; the button works perfectly, it's hit area covers the entire button.
If I set var Y:Number = playDown.height; then I cannot rollover or click the button at all.
If I set var Y:Number = playDown.height - 10; then only the top 10px of the button is active, I can click and rollover the top 10px.

I've tried wrapping the button in another Sprite and moving the containing sprite but it results in exactly the same behavior.

var playUp:Bitmap = getBitmap('play_up');
var playDown:Bitmap = getBitmap('play_down');

var Y:Number = 100;

_playButton = new SimpleButton(playDown, playUp, playDown, playDown);
_playButton.addEventListener(MouseEvent.CLICK, playClick);
_playButton.x = (640 / 2) - (_playButton.width / 2);
_playButton.y = Y;
_playButton.name = "playButton";
var shadow:DropShadowFilter = new DropShadowFilter();
shadow.distance = 5;
shadow.angle = 25;
shadow.alpha = 0.5;
shadow.blurX = 8;
shadow.blurY = 8;
_playButton.filters = [shadow];

var holder:Sprite = new Sprite();
holder.addChild(_playButton);
addChild(holder);
+1  A: 

With two images, exported for Actionscript in the library, this works fine:

var playUpBMPD:BitmapData = new PlayUp(200, 40);
var playDownBMPD:BitmapData = new PlayDown(200, 40);
var playUp:Bitmap = new Bitmap(playUpBMPD);
var playDown:Bitmap = new Bitmap(playDownBMPD);

var Y:Number = 100;

var _playButton:SimpleButton = new SimpleButton(playDown, playUp, playDown, playDown);
_playButton.x = (640 / 2) - (_playButton.width / 2);
_playButton.y = Y;
_playButton.name = "playButton";
var shadow:DropShadowFilter = new DropShadowFilter();
shadow.distance = 5;
shadow.angle = 25;
shadow.alpha = 0.5;
shadow.blurX = 8;
shadow.blurY = 8;
_playButton.filters = [shadow];

addChild(_playButton);

What does getBitmap do? Also, is Y being used anywhere else in your code.

sberry2A
+1  A: 

I haven't used a SimpleButton before, but here's what I gather from about a 10 minute Google-search: You may need to manually change the location of the hitState, upState, downState, etc. of the button every time you move it. In the following example it looks like their hitState, etc for the button are drawn at a specific place on the stage.

http://weblog.cahlan.com/2006/07/simplebutton-class-in-actionscript-30.html

And even in the example from the SimpleButton reference page, it looks like they're actually setting the location of the hitState:

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/SimpleButton.html

(W/apologies if I'm completely wrong.)

Mark