Posts Tagged mxmlc

actionscript SoundMixer fun

Ever since I grabbed ye olde flex builder for linux, I’ve been get jiggy with some ActionScript.

I did a few things with papervision, but nothing ready to show.

Here are some observations on…

AS3 weird stuff

I’m pretty used to Java these days, so the AS3 class layout was a little weird to me:

package {
     import flash.stuff.and.or.junk;
     public class Funzone extends Zone {
          private var x:int;
          public function Funzone() {
          public function fu( n:Number ) : int {
              return 1;
          public function gu() : void {

Fer starters, the whole thing is inside a package xyz { } wrapper. If you put something there, the .as file (and it has to have the .as extension of mxmlc will ignore freak), it has to be inside some sorta java-ishy directory nesting and you have to figure out the args to mxmlc >.<

Or you can leave it blank… and keep it in pwd… and compile it directly with mxmlc… yeah… I know…

Look at the weird way the imports go inside the package stanza… ok, maybe not that weird…

The class definition (and if it extends another class) is nice and familiar.

Variable definitions are in the form of: (private|protected|public)? var name:type

Which is why the functions (cleverly marked as such in case you might confuse them for hamburgers) have that quirky colon return type look… Except for the constructor…

It’s a little different, but it looks pretty reasonable… not like ruby/perl/python…

Anyhooo… nuff said? Oh, you can compile it like so: mxmlc , as usual, the filename needs to match the classname and have the “.as” extension…

So, lez…

SoundMixer it up!

One thing people seem to find neat is sound visualization, so I thought it might be something fun to cut my teeth on.
I found a couple of pretty cool posts about using SoundMixer.computeSpectrum and thought… neat!

Those guys go into mechanics of it and there’s really not a whole lot to it. The only real improvement I made was to drive it all of the “Event.ENTER_FRAME” event handler.

inherit the drawSpectrum method

The original class I made to visualize it up was Souvouzou, the method which ultimately does the per fram drawing looks like this:

        public function drawSpectrum( graphics:Graphics, byteArray:ByteArray ) : void {
            graphics.lineStyle( 0, 0x0000FF );
            graphics.beginFill( 0x0000FF );

            var w:int = 2;
            for ( var i:int = 0; i < 512 ; i += w ) {
                var n:Number = ( byteArray.readFloat() * 256 ) + 1;
                graphics.drawRect( i, 256, w, -n );

Which is pretty much copied from the example, but by breaking it out into a separate method, it was pretty easy to override it in Magnozou where I got a little more jiggy with it:

        public class Magnozou extends Souvouzou {
            // ....

        public override function drawSpectrum( graphics:Graphics, byteArray:ByteArray ) : void {
            this.magnitudes( byteArray );
            this.drawHits( graphics );
            this.drawHats( graphics );
            this.drawMags( graphics );

It’s a little more in the flavor of the olde fadey, jumping hat thing of yesteryear with some nutty laser light show…

Notice the sly override, if you forget it, don’t worry! mxmlc will remind you… 😀

Error: Overriding a function that is not marked for override.

Thanks! I almost left off the handy “override” keyword! What a mess that would have been!!!


weird AS3 variable scoping

Another really weird thing about AS3 is that it appears that variable scoping is per function rather than per code block.

Which is weird! It means stuff like this:

        public function noworkie() : void {
            for ( var i:int = 0; i < 512 ; i++ ) {
            for ( var i:int = 0; i < 512 ; i++ ) {

will get a saddy face like:

Warning: Duplicate variable definition.

and you can do weird stuff like this:

        public function noworkie() : void {
            for ( var i:int = 0; i < 512 ; i++ ) {
                var n:int = 12;

which is REALLY weird!!! X-D

AS3 is weird

It is weird! But despite it’s few quirks, it’s a pretty usable language. The mxmlc compiler seems really slow…

It also seems really quirky.

Once I get the real directory structure / package / mxmlc straightened out I’ll post it.

BTW, don’t ferget, you can still write in Haxe, have it generate the AS3 and compile that with mxmlc… the big advantage of that is Haxe’s cool dynamic type inferencing, and it can also translate yer code to Javascript too…

I’m just saying… there are alway alternatives


Comments (1)

gen-hx-classes papervision3d

After reading [haXe] Fisix + haXe = FisaXe? hehe, I started to wonder if I couldn’t use a similar trick to make papervision3d.

Though I was not able to get a pure haxe solution, I did get a happy ending

Updating papervision3d

ActionScript3 pointed out that the version of papervision3d he ported was old and that it would probably be worthwhile to grab a newer version

I thought about checking out a copy from SVN, but I know the sort of stuff you tend to get from checking out from the head… 😛

So I decided to go with what looked to the the last official release, version 1.5 from

% mkdir /home/brian/tmp/pv3d
% cd /home/brian/tmp/pv3d
% unzip
% ls PV3D_1_5/src
com  fl  livePreview  org


flex builder for linux

Word on the street is that the A3 compiler from flash is still faster than haxe.

So… I went to and grabbed a copy of the flex builder alpha for linux.

The install wanted an eclipse directory with a “configuration” subdirectory and barked at me… I’m not really an eclipse guy, so whatever. Maybe I will hook it up later…

Here is what it looked like:

% chmod 755 flexbuilder_linux_install_a3_033108.bin
% ./flexbuilder_linux_install_a3_033108.bin
% export PATH=${PATH}:${HOME}/data/Adobe_Flex_Builder_Linux/sdks/3.0.0/bin/
% which mxmlc

Sweet… now I can get that AS3 fanciness I keep hearing about!


This actually had me scratching my noggin… The original post had said:

mxmlc -include-libraries /AS3_src/Fisix/Bin/FisixEngine.swc -file-specs -output ./FisixLib.swf  -benchmark=true

Obvious is something I don’t have and I also don’t have a swc and I won’t bore you with how I came up with this bit of madness:

% cd /home/brian/tmp/pv3d
% mkdir tmp
% cd tmp
% find /home/brian/tmp/pv3d/PV3D_1_5/src -type f -name "*.as" >
% echo "package {" >
% cat | cut -f1 -d. | sed 's,.*src/,import ,;s,/,.,g;s,$,;,'  >>
% echo "public class Test {" >>
% cat  | cut -f1 -d. | sed 's,.*/,,;s,.*,public var tmp_& : &;,' >>
% echo "} }" >>

Of course that’s not exactly how I did it, but it was just as painful and used the same methodology.

So by now you are probably shaking your head and laffing, going “ok, bright-boy! now echo me up an swc file!”

Not nice…

Happily, I got some command line help from a guy I don’t know in Japan, so that I was able to hookup:

%  mxmlc -source-path ${HOME}/tmp/pv3d/PV3D_1_5/src -file-specs -output Papervision3d.swf

Kabloom! It dumped out a bunch gobble-de-gook.

Luckily, yours-truly is an old hand at ignoring compiler errors… A little of ye olde clickety-clack… and I had version of that would compile.

I did it like this:

% grep PV3D_1_5/src mxmlc.errors.compiling.PV3D_1_5.txt | cut -f1 -d\( | sed 's,.*/,,;s,.as$,,' | sort -u | sed 's,^,tmp_,'
tmp_InteractiveWireframeMaterial Error: A file found in a source-path must have the same package structure 'livePreview', as the definition's package, 'fl.livepreview'.

Look, maw! I’m UNIX hackin’! I’m UNIX hackin’! Got that one odd-man-out…

Comment those lines out:

//public var tmp_CompositeTriangleCuller : CompositeTriangleCuller;
//public var tmp_DepthTriangleCuller : DepthTriangleCuller;
//public var tmp_InteractiveWireframeMaterial : InteractiveWireframeMaterial;
//public var tmp_PV3DColladaScene : PV3DColladaScene;
//public var tmp_Stars : Stars;
//public var tmp_LivePreviewParent : LivePreviewParent;

Next thing you know:

%  mxmlc -source-path ${HOME}/tmp/pv3d/PV3D_1_5/src -file-specs -output Papervision3d.swf
Loading configuration file /home/brian/data/Adobe_Flex_Builder_Linux/sdks/3.0.0/frameworks/flex-config.xml
Papervision3d.swf (168851 bytes)

And now we know!

And knowing is half the battle…

Let’s fight on…


The next piece of good advice is that we can use

% haxe --gen-hx-classes Papervision3d.swf

Yeah… sure it spewed a bunch of madness, but let it!

It also generated a lot of good stuff!

% find hxclasses -name "*.hx" | wc -l

Kind of a lot of stuff.. the original library only had 85 .as files… hummm… thanks?

trying it on

% cp Papervision3d.swf /tmp
% cp -r hxclasses /tmp
%  cat TestHaxePv3d.hxml
-main TestHaxePv3d
-swf TestHaxePv3d.swf
-swf-version 9
-swf-lib /tmp/Papervision3d.swf
-cp /tmp/hxclasses
% haxe TestHaxePv3d.hxml
TestHaxePv3d.hx:19: characters 0-47 : Class not found : org.papervision3d.core.utils.FPSCounter

Which is actually ok… I reused my demo from before… clickety-clack…

% haxe TestHaxePv3d.hxml

Yup… it gacked up more “Unknown opcode 0x59” hairballs! but… lookit!

% ls *swf

Or better yet! Don’t bother!

Cuz it’s just a blank blue-ish screen!

Haha! It doesn’t really make me feel any better that Asger Ottar Alstrup got stuck at pretty much the same point…

When I asked him about it, he said he did get it to work:


Yes, I got it to work just fine. Just make a .as file referencing the classes you need, compile that to a papervision.swf file, then

haxe --gen-hx-classes papervision.swf

generates the classes, and everything works fine. Remember to add a "-cp" switch to point to the generated files, and link in the papervision.swf file using "-swf-lib". (I use swfmill to bundle a bunch of .swf's together to one .swf and then link that into the final .swf, but it also works if you just directly link in the papervision.swf file.)


So… I dunno

Bummer… I tried everything all over again trying to use the 2.0.1 version of mxmlc, but with the same result.

Silver Lining

Though I was originally hoping to be able to papervision3d via haxe, I finally did end up with a solution that works

% wget
% mxmlc -source-path ${HOME}/tmp/pv3d/PV3D_1_5/src -file-specs -output exampleSpherePrimtive.swf

Sure… it’s actionscript, but yeah the compiler is proprietary, but … eh.. at least there is some way forward.

It just wasn’t the way I wanted… boo+hoo=moving on

Time to get my AS3-fancy on!

Comments (1)