-
Notifications
You must be signed in to change notification settings - Fork 23
Compile with the Flex SDK
This is a temporary solution, it will get better in the future.
This is to compile ActionScript 3.0 projects, to compile the Redtamarin sources see Compiling Redtamarin.
For now we focus mainly on ABC files that we compile with ASC (eg. asc.jar
).
The ActionScript Compiler (ASC) is a bit more complicated to use than MXMLC (the default Flex SDK compiler), it gives us more control at a lower level and allow us to better understand "what's going on", but lack some features.
First, ASC will not automatically manage the actionscript files to compile based on the imports, you will need to manage all that by hand using includes.
Second, ASC can build ABC files and SWF files and allow to compile against ABC libraries but will not support SWC libraries.
That is exactly why we provide our own building tool redbean
in the Redtamarin SDK.
Redbean simplify a lot of things:
- compile AS3 sources with or without dependencies to ABC
- generate include files
- execute AS3 / ABC / SWF with the
redshell
runtime - merge ABC files into SWF
- create projectors from ABC / SWF files
Please look at the redbean tool page and the redbean documentation.
For now, our advice is to organise your source code with includes and use redbean to compile; look at the as3lang project for an example.
Please consider this as experimental, we believe as a developer you should fully understand how your code is compiled and not just expect to "click on a button" to get the job done.
That said, here a way to use Flash Builder and the Flex SDK:
- Download a Flex SDK
for example: Adobe Flex 4.6 SDK - Install (unzip) the Flex SDK to a path
for example:/sdk/flex/4.6.0/
- Find where is the
playerglobal.swc
in our example:/sdk/flex/4.6.0/frameworks/libs/player/playerglobal.swc
- Copy the
redtamarin.swc
and replaceplayerglobal.swc
with it - Launch Flash Builder
- In the Preferences, Installed Flex SDKs
add the new SDK, eg./sdk/flex/4.6.0/
- Create a new ActionScript project
select the new SDK above
Follow the following for your "Main" class
package
{
// all the imports and syntax completion use redtamarin definitions
import C.unistd.*;
// do not extends Sprite
public class Main
{
public function Main()
{
trace( "hello world" );
trace( "hostname: " + gethostname() );
}
}
/* Note:
you need to create the entry point
eg. tell the runtime which class you want run
*/
new Main();
}
From that point, just compile as usual and the SWF produced in bin-debug/Main.swf
should run using the redshell
.
Here from the command line
$ ./redshell_dd bin-debug/Main.swf
produce the output
hello world
hostname: machine123
Also if you want to be able to launch the SWF from Flash Builder itself
- go into your project properties
- select 'Builders'
- create a new 'builder' from a 'program'
with those parameters
Location: ${project_loc}/redshell_dd
Working Directory: ${project_loc}
Arguments: bin-debug/Main.swf - be sure the this new builder is placed underneath the default 'Flex' builder
With that setting you will not need to manage includes manually but you will be only able to produce SWF files, not ABC files.
Note:
This will not take care of SWC dependencies see Support for 'normal' SWF loading/instantiating
In Redtamarin 0.4.1 here how you deal with those dependencies
package
{
// all the imports and syntax completion use redtamarin definitions
import C.unistd.*;
// do not extends Sprite
public class Main
{
public function Main()
{
trace( "hello world" );
trace( "hostname: " + gethostname() );
}
}
}
/* Note:
you need to create the entry point
eg. tell the runtime which class you want run
*/
import shell.Program;
Program.atExit( function():void {
new Main(); // the entry point
} );
In Redtamarin v0.4.2 we introduced Program.start()
.
package
{
// all the imports and syntax completion use redtamarin definitions
import C.unistd.*;
// do not extends Sprite
public class Main
{
public function Main()
{
trace( "hello world" );
trace( "hostname: " + gethostname() );
}
}
}
/* Note:
you need to create the entry point
eg. tell the runtime which class you want run
*/
import shell.Program;
Program.start( "Main" ); // entry point
Here what happen in details:
-
When you build a SWF with MXMLC and that SWF has dependencies in SWC
the resulting SWF will have manydoABC
tagsdoABC "1" doABC "2" doABC "3" doABC "4" ...
-
When you execute your main class it happens in the first
doABC
tag -
but when your main class depends on other definitions that are defined
in other doABC tags (doABC "2"
, doABC "3", etc.) following the firstdoABC
tag
those otherdoABC
tags may not be completely loaded -
so when your main class try to use one of those definitions it may not be found
What does Program.start()
do ?
-
it will execute at the very end of the stack of
doABC
tags -
this ensure that all other
doABC
tags are loaded in memory before they are needed -
even if your main class is defined in the first
doABC
tag it is only instantiated after the lastdoABC
tag has been loaded -
here the details
doABC "1" main class definition doABC "2" doABC "3" doABC "4" ... main class instantiation