Archive for actionscript 3

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.

Andkrup Actionscript3 Game Library

Posted in Actionscript, Development, Games with tags , , , , , on April 27, 2009 by andkrup

I just started a project at googlecode.com.

Sometimes you have an idea, but you don’t act on it. At least not immediately.

I’ve been wanting to create some nice 2D, top-down shooters, but every time I sit myself down and start planning, I get lost in all sorts of RPG-like features, overloading any game-idea with features such as experience points, skill-levels, etc.

The idea with this library is to have some tools that may help you quickly create a basic 2D/top-down shooter, quickly giving you a prototype you can put as many features into as you want.

If you have any suggestions, please don’t hesitate to send them this way

http://code.google.com/p/andkrupgamelib/