Symmetri Developer Blog

November 4, 2009

Using a Flash symbol from an SWF as the background for a UIComponent using styles

Flash/Flex - By Shourov Bhattacharya

You can use a Flash movie clip from within an SWF as the background for a component in Flex. First, you must create the symbol in Flash and then be sure to create a linkage for the symbol (Export for Actionscript etc.) and give it a unique name; then publish the Flash movie as a SWF. Within Flex, the background can be set up as part of a style in the CSS stylesheet - but the part that had me stumped was that instead of using background-skin, you must use background-image. That is, the following code is correct and will work:

.bubble
{
    background-image: Embed(source=../swf/bubble_skins.swf, symbol=bubble);
    background-alpha: 1.0;
    background-size: 100%;
}

The following code will NOT work:

.bubble
{
    background-skin: Embed(source=../swf/bubble_skins.swf, symbol=bubble);
    background-alpha: 1.0;
    background-size: 100%;
}

Dividing the perimeter of an ellipse into equal segments

Flash/Flex, Algorithms - By Shourov Bhattacharya

Suppose we want to lay out N number of objects on the perimeter of a circle, equally spaced. Finding the position of each object is trivial; we simply divide the total angle 2*PI by N and then draw out a point at the constant radius at that angle. However, doing the same thing on an ellipse is surprisingly tricky. Using the same algorithm as the circle in polar form does not yield the right results; the points end up “bunching up” on the minor axis. To find the correct algorithm, we need to think parametrically - we parametrize the elliptical curve by a variable theta and then plot points at equadistant intervals projected on the linear axis of theta:

var theta:Number = (Math.PI*2)*(i/NUMBER_OF_SEGMENTS) - Math.PI/2;
var a:Number = 100;
var b:Number = 80;
var x:Number = a* Math.sin(theta);
var y:Number = b*Math.cos(theta);
var point:Point = new Point(x, y);

Get free blog up and running in minutes with Blogsome
Theme designed by Janis Joseph