Archive for the ‘ Flex ’ Category

FDT Flex [Frame(factoryClass increase your SWF size ?

Using the example of my previous post AS3 Only Preloaders, noticed that for strange reasons the size of the resulting swf grows as 130kb ..

For that reason it is, therefore, when you insert the Flex tag Frame it includes some SWC you do not really need.

1
[Frame(factoryClass="preloader.as")]

To fix this, from FDT remove the swc’s you are not referencing.

And with this our SWF’s will return to their original weight.

Eclipse FDT. Automatically embed a build control STRING.

On many occasions, it would have an interesting way to know if we have updated our flash projects, if are cached, etc …

A simple way of doing it is as follows:

We generate a file that contains our version number with a Ant build as follows:

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<project name="xxxx BUILDER" default="buildVersion" basedir="..">

    <!-- DEFAULT TARGET -->
    <target name="buildVersion" >

        <!-- include a valid filePath -->
        <buildnumber file="yourpath/buildVersion.txt"/>
    </target>

</project>

Perfect, as we build our file with a nice number that is updated every time you execute it.

Now test it, the resulting file likes that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#Build Number for ANT. Do not edit!
#Sat Nov 29 00:00:34 CET 2008
build.number=4
[cc lang="actionscript3"]
package
{
    import flash.utils.ByteArray;

    /**
     * @author xperiments
     */

    [Embed(source="pathToYour/buildVersion.txt",mimeType="application/octet-stream")]
    public class EmbeddedVersion extends ByteArray
    {
        private var _revision : String;

        public function EmbeddedVersion()
        {
            var txtFile:String = this.toString( );
            var lines:Array = txtFile.split("\n");

            //asignamos el valor de revision
            _revision = String( lines[ 2 ].split('=')[ 1 ] );
        }

        public function getRevision( ):String
        {
            return _revision;
        }
    }
}

Now for accessing to the actual revision value.

var embedInstance:EmbeddedVersion = new EmbeddedVersion( );
var revision:String = embedInstance.getRevision( );
trace( "Revision:" + revision );

We also have to modify the compilation settings in Ant tab Options (next to the tab Compiler Arguments) to include the previous buildVersion.xml file in the “ant prebuilt file.” parameter.

Nice coding…

Static initializers in AS3

Does ActionScript 3 have static initializers like Java?

You bet it does!

First of all, what is a static initializer? Simply put, it’s a block of executable code used to initialise a class. They’re also called “static constructors” in C#.

Here’s a class that detects and stores Flash Player version information:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class FlashPlayerVersion
{
    /* Inicializador de Bloque estático */
    {
        trace("Initialising class FlashPlayerVersion");
        var a:Array = Capabilities.version.split(" ");
        platform = a[0]; // "WIN", "MAC", "UNIX", etc.
        a = a[1].split(",");
        majorVersion = int(a[0]);
        minorVersion = int(a[1]);
        buildNumber = int(a[2]);
        internalBuildNumber = int(a[3]);
    }
    public static var platform:String;
    public static var majorVersion:int;
    public static var minorVersion:int;
    public static var buildNumber:int;
    public static var internalBuildNumber:int;
}

The version information provided by the Capabilities class is in string format, so we need to parse it once. Since the variables holding these values are static, they must be initialised in a static block.

The code in the static block is run when the class is first loaded. You can have multiple static blocks, and they’ll all be executed in the order in which they appear textually within the source.

Here’s a small bit of MXML to test out the FlashPlayerVersion class:

1
2
3
4
5
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Button label="Click Me!"
     click="trace('Build number:', FlashPlayerVersion.buildNumber)" />
</mx:Application>

When you click the button for the first time, the program will trace “Initialising class FlashPlayerVersion” followed by the Flash Player build number. The static initializer is run only once, when the class is first loaded in the virtual machine, which happens when it is first referenced in the application (in our case the click handler).

Original post:manishjethani.com