Archive for the Flash Category

Converting fla files to xfl and vice versa to simplify copying publish settings

Posted in Ant, Flash with tags , , , on August 23, 2011 by andkrup

A really nice feature of the xfl flash file format is that (mostly) everything is text-based.

Today I was working on a small landing page project with 1 fla file that is supposed to display small variations each week for the next 6 weeks. Some of the variations are changes in graphics, and the easiest solution was to create 7 different publish settings each with different compiler constants.

Copying a publish setting will copy all the current settings, bit for some reason, the library settings pointing to the swc files used, was not copied into the new publish setting.

Instead of tediously selecting and copying every compiler constants back and forth in 7 publish settings, it was much easier and faster to convert the fla file to xfl, and edit the PublishSettings.xml with a simple search and replace.

This way you can replace a text like this:

<AS3ConfigConst>CONFIG::FLASH_AUTHORING=&quot;true&quot;;CONFIG::debug=&quot;false&quot;;CONFIG::production=&quot;true&quot;;</AS3ConfigConst>

with a text like this.

<AS3ConfigConst>CONFIG::FLASH_AUTHORING=&quot;true&quot;;CONFIG::debug=&quot;false&quot;;CONFIG::production=&quot;true&quot;;CONFIG::week34=&quot;false&quot;;CONFIG::week35=&quot;false&quot;;CONFIG::week36=&quot;false&quot;;CONFIG::week37=&quot;false&quot;;CONFIG::week38=&quot;false&quot;;CONFIG::week39=&quot;true&quot;;</AS3ConfigConst>

in the PublishSettings.xml instead of risking carpal tunnel syndrome by copying each constant and clicking a lot of gui components in the gui.

Converting a fla file into a xfl file is as easy as unzipping the fla file – it’s a zip file with the *.fla extension. Converting back is rather obvious.

I use some ant tasks to streamline the process:

<target name="Convert Xfl to Fla">
<zip destfile="${dir.flash}/${_flash.name}.fla" basedir="${dir.flash}/${_flash.name}" />
<delete dir="${dir.flash}/${_flash.name}" />
</target>

<target name="Convert Fla to Xfl">
<mkdir dir="${dir.flash}/${_flash.name}" />
<unzip src="${dir.flash}/${_flash.name}.fla" dest="${dir.flash}/${_flash.name}" />
<delete file="${dir.flash}/${_flash.name}.fla" />
</target>


 

Advertisements

Compiling external javascript files into flash for javascript injection

Posted in Actionscript, design, Development, Flash, javascript, oop with tags , , , , on July 2, 2011 by andkrup

This page contains detailed information about how you inject javascript into the web page that embeds your flash:

http://frontenddeveloper.net/wiki/index.php?title=JavaScript_and_VBScript_Injection_in_ActionScript_3

One of the drawbacks of adding javascript code directly into your as3 class files, is that it becomes less transparent where to look for the javascript code. But the solution is simply to add the javascript as an embedded resource, like you would a jpeg or png, using the Embed tag.

See this page for an example of how to embed text files:

http://techrays.wordpress.com/2007/09/19/embedding-text-files-in-a-flex-application/

Once you begin to think about that, you can create a JavaScript class that may help your workflow:

package dk.andkrup.resource {
import flash.external.ExternalInterface;
import flash.utils.ByteArray;

public class JavaScript extends ByteArray {
private var rValue : *;

public function get returnValue():*{
return rValue;
}

public static function inject(javascript:JavaScript):Boolean{
if(ExternalInterface.available){
javascript.rValue = ExternalInterface.call(javascript.toXML());
return true;
}
return false;
}

private function toXML():XML{
return new XML("<script><![CDATA["+this.toString()+"]]></script>");
}
}
}

Extend this class and add an Embed tag, in order to externalize your javascript in a separate *.js file.

Example embed tag:

[Embed(source="../js/javascript.js", mimeType="application/octet-stream")]
public class MyJavascript extends JavaScript{
...

(above example implies that you have a javascript called “javascript.js” in the relative location “../js”)

Then it becomes a small one-liner to inject your external javascript subclass with the static inject method like this:

JavaScript.inject(new MyJavascript());

Or, in order to retrieve any javascript return value:

var js:JavaScript = new MyJavascript();
if(JavaScript.inject(js)){
trace("return from javascript: "+js.returnValue);
}

This way you can keep your javascript separate from your actionscript, possibly making it easier to maintain your project.

Disabling the Warning: 1090: Migration issue

Posted in Actionscript, Bugs & Solutions, Development, Flash with tags , , on May 31, 2011 by andkrup

In actionscript 2, eventhandlers was already defined in the MovieClip class, so whenever you needed to run some code in an eventhandler, say in the onLoad function, you could ‘override’ the default (empty) onLoad function and all was good.

In actionscript 3 Flash CS assumes that you’re struggling with migration issues if the compiler encounters a function that is named similar to the actionscript 2 eventhandlers.

If I decide to listen for the Event.ADDED_TO_STAGE, and create  an eventlistener with the name onLoad, I will get the titular warning.

I don’t really need that warning; I like to give the eventhandler a meaningful name and that’s what I think ‘onLoad’ is.

To disable this warning, you can browse to this file on your Mac:

/Applications/Adobe Flash CS5/en_US/Configuration/ActionScript 3.0/EnabledWarnings.xml

(I would assume that the ‘EnabledWarnings.xml’ file is in a similar location on Windows)

and change the enabled-attribute value from true…

<warning id="1090" enabled="true"  label="kWarning_DepricatedEventHandlerError">EventHandler was not added as a listener.</warning>

to false.

<warning id="1090" enabled="false"  label="kWarning_DepricatedEventHandlerError">EventHandler was not added as a listener.</warning>

Swf 2 Png

Posted in Development, Flash with tags on May 3, 2011 by andkrup

Just saw this tool – could be real nifty for cross-platform games development

http://marshgames.com/swftopng/