01-18-2013 07:58 PM - edited 01-18-2013 08:12 PM
In a Dev Alpha targeted AIR app, using the Gold SDK, I am seeing some weird and maddening Sprite behavior.
I have a scrim sprite with an event listener attached listening for MouseEvent.CLICK. The event handler
is supposed to toggle the scrim's alpha between 1 and 0. If I change one little line of code, the behavior
on the Dev Alpha goes from irrational to rational. I have a line of code that says:
e.target.alpha = 0.0;
In the particular execution branch this code lives in, the sprite refuses to change its alpha. I know the
line is getting executed because: 1) I have trace comments inline right before and after it, and 2) When I
change it to read:
e.target.alpha = 0.01;
it suddenly feels like cooperating, and turning the scrim's alpha down to 0.01.
What. The. Foo.
Anyone ever seen anything like this? (And more importantly what is the "fix"?)
I want to set the alpha to exactly zero because I test its value along with the alpha values of several other
scrims elsewhere in the code.
Also, when I repeately tap one of the scrims with the code in its apparenly broken state (i.e. trying to set the alpha to identically zero), other code that is checking the scrim's alpha is indicating that the attempt to assign a value of zero
failed succeeds according to the value read back from e.target.alpha, yet the scrim remains black (the scrim color value is 0x000000).
01-18-2013 09:48 PM
Not sure what is causing the problem, but you could try setting the alpha first to 0.01 then to 0.0 in two consecutive lines of code.
Are you 100% sure e.target is always a Sprite?
Are you 100% sure it is referring to the correct sprite?
What do you get if you trace out the alpha directly after setting it?
What do you see if you set a breakpoint on that line and inspect e.target?
Though the AS3 compiler & runtime do have occasional bugs, I've found this type of error is almost always caused by some faulty logic in the app, i.e. programmer error.
01-18-2013 10:04 PM - edited 01-18-2013 10:06 PM
I'm assuming it is my error, however the things I have done as I describe to isolate it have left me at a dead end for now and I am going to have to shelve this app for a few days if not longer. I did trace out the alpha immediately in a line of code after the line where I set it and it reads back as the value I set it to, however the Sprite itself on the device display refuses to go transparent. Same behavior on the simulator. I also tried using the Sprite "visible" property and got the same behavior. I have traced out the e.target and it is indeed a Sprite. The only lead I can think of is I am storing my sprites in an array and maybe somehow a dereferencing is getting dropped.
I use fdb for debugging and unfortunately it appears that you can't set breakpoints in fdb if you have ANE's packaged. Google for it; apparently a bug in fdb that remains unfixed for two years. If you know different though please let me know; I'd love to be able to set breakpoints.