Im using a Bitmap for a button in OpenFL. What im seeing when I set myBitmap.visible = true
is that the bitmap does not become visible.
It seems I need to call myBitmap.__CombinedVisible = true
as well for it to be drawn. I can't find any documentation for this property on how to use it properly.
I'm also noticing the first time I switch between 2 bitmaps that the bitmap made visible does not appear right away, but the one made invisible disappears right away. Any time after that it behaves properly and the switch happens instantly.
Could this have something to do with __CombinedVisible
?
You can see the bitmap switching code below inside of my button.
private function update() : Void {
if( state == ButtonState.OVER ){
this.over.visible = this.over.__combinedVisible = true;
this.up.visible = this.down.visible = false;
}else if( state == ButtonState.UP ){
this.up.visible = this.up.__combinedVisible = true;
this.down.visible = this.over.visible = false;
} else if( state == ButtonState.DOWN ){
this.down.visible = this.down.__combinedVisible = true;
this.up.visible = this.over.visible = false;
}else if( state == ButtonState.CLICK ) {
this.up.visible = this.up.__combinedVisible = true;
this.over.visible = this.down.visible = false;
this.enabled = false;
dispatchEvent(new Event("CLICK"));
}
}
So after a bunch of testing I'v narrowed it down to this: If I set visible
to false prior to assigning the BitmapData
this __combinedVisible
member seems to need to be used. If I do it right after setting the BitmapData
it still needs this.
If I let the bitmap draw for 1 frame then set visible
to false
. visible = true
works after this happens and I can now see the bitmap.
But if it doesn't draw once then visible = true
does not show the bitmap.
Can I not create an empty bitmap this way and assign the BitmapData
later? It works on the up state as I never set visible = false
prior to it being drawn the first time.
Okay so after tons of testing and trying to get this to work it just won't.
There is a bug here where if visible
is set to false
before drawing the bitmap to the canvas it won't draw it until __combinedVisible
is set to true
. This always causes a flash when drawing the bitmap for the first time as well, so its not feasible to use.
I went and used alpha
instead of visible
. This works properly and as expected.
If someone can get this working with visible
I will accept that answer.
private function update() : Void {
if( state == ButtonState.OVER ){
this.over.alpha = 1;
this.up.alpha = this.down.alpha = 0;
}else if( state == ButtonState.UP ){
this.up.alpha = 1;
this.down.alpha = this.over.alpha = 0;
} else if( state == ButtonState.DOWN ){
this.down.alpha = 1;
this.up.alpha = this.over.alpha = 0;
}else if( state == ButtonState.CLICK ) {
this.up.alpha = 1;
this.over.alpha = this.down.alpha = 0;
this.enabled = false;
dispatchEvent(new Event("CLICK"));
}
}