[Resolved] SimpleButton not displaying in HTML5 target

I have a test which works fine in a Flash target, but fails in HTML5.

var bmd = Assets.getBitmapData("assets/img/play.png");
var b = new Bitmap(bmd);
// addChild(b); // line1

//var pb = new SimpleButton (b, b, b, b); //line2
//addChild (pb); //line3

if I uncomment line1, the bitmap displays fine in both targets.

If I uncomment line2 & 3 the SimpleButton will display in Flash, but not HTML5

if I uncomment line1 & 2, the bitmap will display in Flash but Not HTML5

Any ideas where I’m going wrong??

ok I’ve found a way of making this work, but I’d be interested in learning why the above fails.

The below adds the button in HTML5:

var b1 = new Bitmap(bmd);
var b2 = new Bitmap(bmd);
var b3 = new Bitmap(bmd);
var b4 = new Bitmap(bmd);

var pb = new SimpleButton (b1, b2, b3, b4);

That would be my fault. I made improvements to make SimpleButton only appear if you pass in just one parameter on the upState. That means that if the downState or upState are null, the state won’t change, it will remain the same as the upState when you hover and click down on the mouse.

So in your first example, all you would do is:

var pb = new SimpleButton(b);

And that would work. Or should do.

I don’t think you can add the same object twice though, as you have done in your first example, if you uncomment line 1 and line 2 and 3, the second addChild call will be ignored because a Bitmap of the same instance has already been added to the stage.

1 Like

We should fix this if we can. Probably simple?

The case is one DisplayObject passed as all the states, and it doesn’t behave properly outside Flash? What does it do?

in the HTML5 target it just displays nothing, no errors.
I’ve not tried any other targets.

Yep.

Ah, this makes sense :smile:

I think we need to support sprite.hitArea (and similarly hitArea here for SimpleButton) to hit test on a totally different object, without affecting the addChild hierarchy.

As a fast workaround, perhaps if (hitTestState != overState && ... (etc) to not hide an object used for other states?

Honestly, I think the real thing here is that we need to be able to redirect hit testing logic to use a different object entirely.

hitTestState needs to be a child at all times, but the other states are removed and added regularly.

Alright guys

I have a brand-new implementation of SimpleButton (just committed to GIT). With sprite.hitArea support in now (I think it basically works?) I used the same functionality to get our hitTestState behavior right. I moved SimpleButton to use InteractiveObject as the base class instead of DisplayObjectContainer, so it matches the proper parent, and also now behaves more like Flash.

If you add objects that are on the stage, these will be unparented as the button requires them. This is Flash’s behavior. They have a null parent when they are used as a state, and a hitTestState can remain parented (and displayed) elsewhere in the project, which is actually interesting.

Interested if there are any minor issues with the new code, but I think SimpleButton is now working how it should really behave, not as a quick workaround :slight_smile:

Excellent, will update next week. Let you know if there are any further issues.

Ok - I’ve just looked at this again - I’ve noticed that if you try:

var pb = new SimpleButton(b);

then the button actually won’t work - no handcursor and events aren’t picked up.

Not sure if this is old version, or if the amend is broken (I checked, my openFL is up to date)

We’re behind the curve on releases – pretty sure the new code has not gone live in a release just yet. Stay tuned, or try a development version of Lime/OpenFL if you want to try it out right away :slight_smile: