* Site Has Moved to www.bbishop.org *

February 9, 2011

I have ported my wordpress blog over to my own webpage www.bbishop.org

I can now upload runnable demos of my swf’s.

All further updates will be on that site (as well as all archived content from here).

as3term – Handy app for compiling AS3 snippets

January 21, 2011

I found a cool little Air app on riaspace.com for compiling and executing simple snippets of AS3 code.

Very handy for testing out things like Math functions.

as3term

Flash Builder 4, Flex 3 SDK: Export Release Build Error

January 19, 2011

Had to import some Flex 3 projects to Flash Builder 4 (using it in work now), and everything seemed to go ok. Had copied the Flex 3 SDK from FB3 folder, set it as the default in FB4. Cleaned and ran the project (including RSL library projects) all ok. Then went to Export Release Build and got:

Error – One or more errors were found while trying to build the release version. Unable to export.

The Log file (thanks to doc_180 on Stackoverflow) showed the cause as:

java.lang.NoClassDefFoundError: flex2/tool/oem/OEMException$CircularLibraryDependencyException

Log file can be found at the equivalent of C:\Documents and Settings\bbishop\Adobe Flash Builder 4\.metadata

Turns out that 3 files are required by Flex 3 SDK to export a release build in Flash Builder 4 where RSL’s (Library projects) are used, and these are missing. Luckily you can copy these from the Flex 4 SDK.

Let me shout out a thanks to eggsWurzel for his Adobe Forum Post with the solution. Bug is on the Adobe Jira Bug Database

How to implement the solution

  1. Get a copy of flex-compiler-oem.jar from C:\Program Files\Adobe\Adobe Flash Builder 4\sdks\4.1.0\lib
  2. Extract flex-compiler-oem.jar (using Winzip/7 Zip/Winrar), and go to the flex2\tools\oem folder in the extracted files
  3. Look for the following 3 files:
    1. OEMException$CircularLibraryDependencyException.class
    2. OEMException.class
    3. OEMException_en.properties.
  4. Open Winrar (doesnt work for me with Winzip or 7 Zip), and in the AddressBar browse to the flex-compiler-oem.jar file in the Flex 3 SDK – should beequivalent to C:\Program Files\Adobe\Adobe Flash Builder 4\sdks\3.2.0\lib (make a copy first just in case), and open \flex2\tools\oem
  5. Drag the 3 OEM files over to the \flex2\tools\oem folder in Winrar

That’s it! Close Winrar, and restart Flash Builder 4, should Export a release build ok now:) Nice one.

Note: if using RSL’s you may also need to untick Use local debug runtime shared libraries when debugging from Flex Build Path>Library Path

App Size: Flex vs Actionscript Project (Flex Framework Caching)

January 14, 2011

Following on from discussions at the ‘after’ part of last nights MMUG-Dublin meeting, I created a pure Actionscript 3 project and a similar Flex application project, both in Flex Builder 3. The aim was to compare final swf size. Both apps draw 3 circles on the screen.

Three circles, well done

Size Wise:

Flex 3 Application SWF (Release Build of Project): 169KB (but only 65KB with framework caching – see Optimization section below)

Pure Actionscript 3 Project SWF: 1KB

Optimization – Framework Caching

By default, the flex framework gets merged into your main swf file, adding around 100KB+. This can be avoided by going to Properties/Flex Build Path/Library Path/Framework Linkage/ and selecting Runtime Shared Library (RSL) from the dropdown. When you do a Build Release Project, your framework will be exported as a signed swz and an unsigned swf . These files should be placed in the same directory as your main swf file on the web server. In Flex 4, the framework RSL will automatically point to a public section of the Adobe site, where the swz’s will be available. Saves you having to host them.

The framework will only need to be downloaded by a particular client once, and will be cached by Flash Player, meaning every subsequent use of your app will not require downloading of the framework.swz (in the release will be named something like framework_3.2.0.3958.swz).

Read more about framework caching here: http://ted.onflash.org/2008/01/flex-3-framework-caching.php

Conclusion

If Actionscript will suffice e.g. for drawing three circles on the screen, go with a pure AS3 Project. If your developing data driven applications and user interfaces, use the Flex SDK (saves a tonne of time and effort, and whats 60kb these days – less than most peoples profile pics). Have a look at this Stackoverflow question for more opinions on each approaches pros and cons.

Code

Flex

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
	initialize="onInitialize()">
	<mx:Script>
		<![CDATA[
			import mx.core.UIComponent;

			private function onInitialize():void{
				drawCircle( 0x336699 );
	            drawCircle( 0x993333 );
	            drawCircle( 0x339933 );
			}

			private function drawCircle( color:uint ):void
	        {
	            var circle:Shape = new Shape();
	            var displayObject:UIComponent = new UIComponent();

	            circle.graphics.beginFill( color );
	            circle.graphics.lineStyle( 2, 0xCCCCCC );
	            circle.graphics.drawCircle( 30, 40, 30);
	            circle.graphics.endFill();
	            circle.x = (this.numChildren * 65) + 10;
	            circle.y = 0;

	            displayObject.addChild(circle);
	            this.addChild(displayObject);
	        }
		]]>
	</mx:Script>
</mx:Application>

Actionscript Project

package {
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;

	public class ActionScriptProject extends Sprite
	{
		public function ActionScriptProject()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            doDrawCircle( 0x336699 );
            doDrawCircle( 0x993333 );
            doDrawCircle( 0x339933 );
		}

		private function doDrawCircle( color:uint ):void
        {
            var child:Shape = new Shape();
            child.graphics.beginFill( color );
            child.graphics.lineStyle( 2, 0xCCCCCC );
            child.graphics.drawCircle( 30, 40, 30);
            child.graphics.endFill();
            child.x = (this.numChildren * 65) + 10;
            child.y = 0;
            addChild(child);
        }

	}
}

Module Optimization: Link report and load externs

January 12, 2011

When modules are released or built (using Clean or Project>Export Release Build..), the exported module swf’s will include any Flash/Flex framework classes and external swc/swf classes that are used by the modules.

This is not always optimal, as some of the files included in the Module’s swf’s may already be in used by the Main app, and included in the MainApp.swf. You can remove the overlapping classes from the module swf’s by doing the following:

  1. In your main app i.e. the one that will use the module, go to Project>Properties>Flex Compiler and add an Additional compiler arguments:

-link-report=link_report.xml

  1. Clean or Export Release Build the project.
  2. Copy the link_report.xml file from the bin-debug or bin-release folder and paste it to the root of the module project folder i.e. the same folder as the Module.mxml file(s).
  3. Repeat step 1 for the Modules project, and add the compiler arguments:

-load-externs=link_report.xml

  1. Clean or Export Release Build the project.

The released module swf’s will not include any external files that it shares with the main app. Reduced the size of the module I was optimizing in work by 15%!

Additional Compiler Arguments

More details on the compiler arguments and module optimization from:

http://livedocs.adobe.com/flex/3/html/help.html?content=modular_4.html

Caution: any time you change your main app, and remove or change dependencies or SDK versions, you will need to repeat the above process. The modules will not work with apps that they have not been optimized for.

If you receive an error message -load-externs “could not open …..”, make sure that the xml file is at the root of the module project.

Firefox & Debugging in Flex – same browser tab and no swf caching

December 14, 2010

Handy tips I picked up recently. In Firefox, type about:config in the address bar.

To make Flex debug window use the current tab, instead of repeatedly opening new tabs (very annoying), then do step 1.

If you’re debugging modules, the browser may have cached them, so you have to repeatedly delete the History and chache. Step 2 solves this.

  1. browser.link.open_newwindow = 1 (default is 3)
  2. browser.cache.disk.enable = false

 

 

Installing Flash Player 9: Firefox, Chrome, Internet Explorer (for testing)

December 9, 2010

Trying to test your Flash/Flex apps on older versions of Flash Player? I was, and did the following.

Check currently running Flash Player version in each of the browsers at Adobe Player Check.

Downlaod Flash 9 archive from here, in my case the first one under Windows sufficed, unzip and install flashplayer9r280_win.exe.

Chrome:

Go to Tools (Wrench), Options, Under the Hood, Plugins, Disable Individual Plugins.

Expand the details for the Flash install, and edit as shown below (disable ver 10 basically):

Disable Flash 10

Set your browser to Chrome in Flex Builder:

Flex Builder browser selection

Firefox:

Firefox is simpler, after installing Flash 9 exe, just check in Firefox, Tools, Add-ons, Plug-ins, it should have automatically switched version. If not, disable version 10 first, then reinstall ver 9.

Internet Explorer:

You will firstly need to uninstall Flash Player 10, following these instructions. Make sure that all flash using programs are closed (incl Flash/Flex Builder). After the uninstall is complete, install flashplayer9r280_winax.exe from the zip you downloaded. Check IE Flash Player version in Tools/Options/Programs/Manage Add-ons

FINALLY

Great, after doing the uninstall for IE, and your testing is complete,  now you will need to reinstall Flash 10 Debugger Player from Adobe. This is a good reason to start using Sun Virtual Box!!!!

Show In Navigator – Flex Builder – when your getting lost in the file structure!

December 3, 2010

In the code editor of any file, Right Click and go to Show in Navigator to see the files location relative to the other packages/classes/projects. Very handy when using GoTo Definition (F3) or Crtl+Left Click to jump between files.

“Where am I?”, now you know!

Flash Builder 4 – ASDoc hints in the IDE, commenting for yourself!

November 24, 2010

A really nice feature in Flash Builder 4 is the displaying of ASDoc hints by default on hover over delay. Now it makes sense to comment the code with ASDoc tags, not just for API dev, but also because the hints will pop up for other developers on your team and yourself.

ASDoc FB4 IDE Hinting

This gives an added incentive for developers to comment their code with function/variable/class descriptions along with relevant @param, author, returns tags.

If you still want to generate and publish the actual ASDoc html files from within the FB4 IDE, heres a very good tutorial from Arjan on Flex-blog.com to get you sorted. I made one change to Arjan’s setting up the ASDoc.exe tool to run as an External tool rather than a command prompt. I set the ‘Working Directory’ to ${folder_prompt}, so that each time you run it, you get to choose which project folder you want to target (usually in you Flash/Flex Builder Workspace somewhere). Also, as we may need to target different versions of the Flex SDK, I’ve named the External Tool Configuration ASDoc SDK 3.4, to mimic the location of the ASDoc.exe.

External Tools Configuration - ASDoc Generation from within Flash Builder 4

API (SWC) “Code Navigation Error” when Ctrl+Left Click in Flex Builder

November 22, 2010

You’ve added your SWC to the build path, and it works fine. But, when you want to view a source file (ctrl+left click on the function name for example), you get an error. This use to bug me.

You need to edit the Source Attachment directory location in the Build Path (right click on the project name, and click properties/build path). Click the edit button for the Source Attachment, and point to the ‘src ‘ folder of the api zip file you downloaded. It may be the case that your import statement looks like “import com.mc.components.MyComponent;” but the file structure is src/main/flex/com/mc/.. : in this case set the source attachment folder to point to ..src/main/flex, i.e. the last folder before the imported package.

Flex Builder - src build path


Follow

Get every new post delivered to your Inbox.