开发者

Changing SimpleButton.y does not appear to move the hitArea of the button [closed]

开发者 https://www.devze.com 2022-12-20 03:21 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 12 years ago.

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, pla开发者_开发知识库yDown, 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);


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.


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消