Copy link to clipboard
Copied
Recently, I have got a very strange bug with the radial gradient. Unfortunately, I could not find a solution. I built a project to demonstrate the problem (you can download it below). The code is from another large project that used to work correctly in Flash Professional CS6 in August 2013. I now use Flash Professional CC. The version does not matter. I tried with both versions and I still have the same problem. Meanwhile, I updated the AIR and I was wondering if updating it could have been a problem. The demo project is only in ActionScript 3.0. The target Flash Player version does not seem to have an influence on the results. I decided to build a demo project in the simplest form to demonstrate the problem and also make sure that I isolate the precise variables that influence the result.
The bug and symptoms:
Although it seems to have been working correctly in last August, drawing radial gradient circles with transparency now creates patterns mathematically defined. The radial gradient is created on a movie clip circle with alpha 100% at the center and alpha 0% on the edge.
The results are variable. They generally make patterns of rectangle areas with the dots visible and inversed circles' areas with visible dots. See picture below for a preview. Sometimes, there are only rectangles of visible dots.
Sometimes, the dots are drawn only on the left part of the screen (about 75% of the screen width). In addition, there are dots randomly drawn on the remaining 25% of the screen at the right). It looks like, the size of the dot influences whether or not they will appear). The bigger the dot, the more chances it could be drawn. As if there were a threshold. However, what I find very weird is the fact that dots with the same size are drawn in some areas and not in others. And the areas seem mathematically defined as you can see on the picture below.
On the edge of the visible and invisible areas, the dots with many pixels (if you increase the scale of the movie clip) could be cut in the middle. They are partly displayed.
Another issue I noted about the display problem does not seem related to the drawing method. Whatever the method, the problem is the same. Formerly, I used addChild() to add the movie clips (the dot clip) to a parent clip. Then, I converted the parent clip to a bitmap. Because I thought this method could cause a problem with the children, I decided to use the BitmapData.draw() function to draw each movie clip. In both cases, the result is exactly the same. That made me think the problem could be closer to the bitmap memory surface.
Picture a typical result with the radial gradients.
The solution:
At the moment, I cannot see any solutions. After several attempts and variations of the code, I came to the conclusion that the source of the problem is not related to my code, but might be related to the Adobe software.
Below, you will find the demo project to download as a ".fla" file and a preview of the code on the forum for your convenience. At the moment, I believe the source of the problem is out of my control. Try the code and let me know what kind of results you get and if you see a problem with the code and please share your results.
Specs:
Windows 7, 64 bits
Flash Professional CC et CS6
ActionScript 3.0
Target Flash Version 11.4, but any version caused the problem
Flash Player Version: 11.7.700.169
Hardware accelleration (Publish Settings): The three options gives the same result.
To download the demo project (contains the dot movie clips)
https://www.dropbox.com/s/glf81vvr8i2lowe/RadialGradientBug_v1_00.fla
Here is the project's code embedded in the .fla
/*
Test application to debug a problem with the display of radial gradients Flash, ActionScript 3.0.
This application displays a series of dots on the screen and produces two different results.
The dots are MovieClip objects.
1. If we use the clip with the solid fill, the dots are displayed correctly.
2. If we use the clip with the radial gradient fill, some dots are not displayed. the
dots displayed make a mathematic pattern on the screen. Different patterns have
been produced depending of the parameters.
Originally, the Dot movie clips were added with addChild() to a parent movie clip. The parent
movie clip was then converted to bitmap after. This new method below for drawing each Dot
individually produced the same results as originally.
In another test, it has been noted that dots scaled to many pixels in diameter could be cut in the
middle. They were partially drawn on the edge of the pattern (visible / not visible). The problem
could be more related to the bitmap then the movie clip itself.
Other shapes with radial gradient were tested and they also caused the same problem.
*/
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Matrix;
var screen_width:int = stage.stageWidth;
var screen_height:int = stage.stageHeight;
var ClipBitmapData:BitmapData = new BitmapData(screen_width, screen_height, true, 0x000000);
/*
DEBUGGING NOTE:
"ClipDot_Gradient" is the clip that causes the bug. It has a radial gradient.
"ClipDot_Solid" works correctly and has no gradient. Just a solid color.
To test, comment and uncomment the line below.
*/
var clipdot:MovieClip = new ClipDot_Gradient(); // Buggy. 1 pixel gradient circle (alpha 1.0 at center and alpha 0.0 outside).
// var clipdot:MovieClip = new ClipDot_Solid(); // Correct. 1 pixel solid color circle.
var dot_distance:int = 6;
for ( var pos_y:int = 0; pos_y < screen_height; pos_y += dot_distance )
{
for ( var pos_x:int = 0; pos_x < screen_width; pos_x += dot_distance )
{
clipdot.x = pos_x;
clipdot.y = pos_y;
// Scenario 1.
// Produces a circle alike pattern.
clipdot.scaleX = clipdot.scaleY = 1.0;
// Scenario 2.
// Produces other patterns depending of the parameters.
//const alpha_scale:Number = pos_y; // Buggy. Alway return 1 for clipdot.scaleX. Don't know why. Use "var" instead of "const".
var alpha_scale:Number = pos_y;
var scale_factor:Number = 1.0;
// clipdot.scaleX = clipdot.scaleY = (1.0 + alpha_scale / 100.0) * scale_factor;
var draw_matrix:Matrix = new Matrix();
// Position the clip on the bitmap.
draw_matrix.translate(clipdot.x, clipdot.y);
// Scale the clip. The scale influences how the clip is shown.
draw_matrix.scale(clipdot.scaleX, clipdot.scaleY);
// Draw the clip to the bitmap. So far, no errors have been displayed in the console. We assume
// the "draw" function works correctly, but the image does not display at some positions
// based on a pattern that seems to be created by the Flash software.
try
{
ClipBitmapData.draw(clipdot, draw_matrix, null, null, null, true);
}
catch(e:Error)
{
trace("ERROR: draw bitmap: " + e.toString());
}
}
}
// Create the bitmap and add it to the stage to show the result.
var FinalBitmap:Bitmap = new Bitmap(ClipBitmapData, "auto", false);
addChild(FinalBitmap);
Regards,
Sebastien
Copy link to clipboard
Copied
Hi Sebastien,
You can try to create a 256x256 bitmap data instance and render your movie clip inside it, with the desired dot_distance as you are doing in the main movie. You will get better results with an integer factor of 256 (for eg, 4px). You may also have to take care of the offsetting though. Start the pos_x and pos_y with the value 0.5. Later, you can repeat this bitmap with the x, y offset equal to 256 inside a bigger bitmap data instance of desired size (in this case, 1600x600). Finally create a Bitmap with this bitmap data instance and add it as a child. That should do the trick. Let me know if it works the way you expected.
Regards,
Dharmendra.
Copy link to clipboard
Copied
Hi Dharmendra,
Thank you for the solution. It is not what I expected, but it might look like a solution that "could" be applied.
There is still one problem with this approach. If I still use a movie with radial gradient within the bitmap, the same exact problem could occur again.
I was trying to understand if I did something wrong in my code, or it was a bug in the Flash software. I still find weird that I get different results by drawing a movie clip at different positions on a bitmap object. How can the drawing position change if the movie clip is drawn or not drawn? Why does it make mathematical patterns? I guess it has something to do with the precision numbers.
Meanwhile, I did a few extra tests. I tried a new approach with Blur and Glow effects. That is not exactly what I want, but it seems to create a transparent gradient. I might consider this approach if the basic radial gradient does not work. I also created a gradient transparency circle bitmap in Photoshop that I imported into my movie clip. It worked. So, at the moment I have two solutions that seem to be working.
I would appreciate if you could investigate the original problem. It looks like there is a problem in the rendering of Flash. Workarounds are fine sometimes, but I do not expect to developer programs on workarounds.
Copy link to clipboard
Copied
Hi Sebastian,
I was trying to observe the behavior with various parameters to understand what might be going on and try to simulate the same somehow inside of Flash Pro, but I wasn't able to do that. My feeling was that the exact bits are not being copied from the movie clip immediately, rather a fill is being created and fill.matrix is being updated based on your tranform (translation in this case) and the final rendering happening in the end when we create the Bitmap object. I was guessing something wrong with the final uv because of the repeat mode, and/or pixel alignment but wasn't successfully able to re-create any content in flash based on the various theories.
While I still try to do that, it may be a good idea to post this in the Flash Player forum too. Meanwhile, I can also see if we can reach out to any of them directly from our side.
Regards,
Dharmendra.
Copy link to clipboard
Copied
Hi Dharmendra,
Sorry for the delay. I understand that you tried my project, but you did not get the bug. I am wondering if it might be a subtle change in my system's configuration. For example, the graphic drivers.
As a workaround, I made a small change. I replaced the transparent radial gradient dot with a bitmap exported from the original movie clip. The result is nearly 100% of what it was with the gradient. At the moment, I am considering the problem as solved, but it is still annoying to think that there is something that did not work and used to work until recently.
Thank you for your time.
Regards,
Sebastien
Find more inspiration, events, and resources on the new Adobe Community
Explore Now