Bug apparent in browser but not in Flash CS5
I am pulling my hair out. I have this extremely strange bug :
I have a custom "StagedSprite" class that extends Sprite. Its purpose is to automatically align itself to the st开发者_JAVA技巧age's border whenever the stage gets resized.
NOW, I load a PNG file "ybmp" (Bitmap) and add it as child to "loadingIcon" (StagedSprite). In Flash CS5, the PNG is shown correctly on screen (aligned too). But if I publish and run the SWF from within Firefox or IE, the PNG IS NOT SHOWN!
What is even MORE strange is what the following code produces :
//var ybmp:Bitmap = the loaded bitmap
//loadingIcon is a StagedSprite
loadingIcon.addChild(ybmp);
trace(ybmp.bitmapData.width,ybmp.bitmapData.height);
trace(ybmp.width,ybmp.height);
trace(loadingIcon.width,loadingIcon.height,loadingIcon.getChildAt(0),loadingIcon.stage);
I put the "trace" results in a TextField on screen. In CS5, the code above produces :
215 200
215 200
215 200 [object Bitmap] [object Stage]
In Firefox and IE, the code above produces :
215 200
215 200
0 0 [object Bitmap] [object Stage]
What on earth is that?!? In the browsers, the Bitmap IS added in "loadingIcon" but "loadingIcon" still has its width and height set to zero. ?!?!?
I could paste the StagedSprite code here too, but it's a little big and has no scrollRect property. After all, what could be the reason for it running in the Flash authoring tool but NOT in the browsers..?
Many many thanks in advance,
Bill
EDIT : Oh my good. For some still unbelievable reason, loadingIcon had scaleX and scaleY set to 0. But that ONLY in the browsers version. In my code, I had nothing setting its scaleX or scaleY to anything assuming that it should be set to 1 by default.
Does anyone have ANY suggestions why in the browsers my "loadingIcon" would have zero scale but not in CS5? It's exactly the same code in both cases, I have cross-checked this 1000 times...
OK, I found it and sending it here in case someone is helped some time in the future.
In the browsers, a Stage.RESIZE event was fired at start-up. It wasn't being fired in the authoring tool. Since it was happening at a very early stage, "loadingIcon" would get a zero height (since it had no gfx loaded) and that would result in zero scaleY.
So, the thing to note is : in a browser, several events maybe fired at start that usually don't in CS5.
精彩评论