On 2006-11-16, at 15:26 EST, Max Carlson wrote:

So, I've been banging my head against two different issues that turned out to have the same root cause: problems setting the volume of a loaded movieclip, and problems getting a custom class to initialize. After a few days of frustration, I stripped the LFC down to only include the files I'm working with and decompiled them. Here's what I found:

This source:

    var s = new Sound(t);

Compiles to this:

    var v1 = Sound.make(t);

Since Sound is a built-in object, it doesn't have a make() method.

So, in LzRuntime.lzs, you will see that I define .make for all the Javascript native objects. You probably should do the same thing in the swf kernel for all the Flash native objects. Or, if you just need to get at one of them, you can say:

  #pragma "passThrough=true"

right before your new.

Here's another one:

    HelloWorld = function (){
        alert('say hello!')
    }

    HelloWorld.sayHello = function(msg){
        return "FLASH: Message received from JavaScript was: " + msg;
    }

    helloWorld = new HelloWorld();


Compiles to:

    with (_root) {
    }
    HelloWorld = function () {
        alert('say hello!')
    };

    with (_root) {
    }
    HelloWorld.sayHello = function (msg) {
        return 'FLASH: Message received from JavaScript was: ' + msg;
    };

    helloWorld = HelloWorld.make();


Notice that there's one of these before each function declaration:

    with (_root) {
    }

I'm using the flare tool to decompile the swfs: http:// www.nowrap.de/flare.html

It seems like the compiler is going overboard assuming every 'new foo()' means make a new Laszlo class called 'foo'. Let me know what you find!

It's true. The compiler makes no effort to distinguish our classes from runtime classes. So the runtime classes must be bent to our way.

Your decompiler is mistaken about the extent of the `with`, however. The `with` block extends around the entire expression. This is intentional, and is to make up for a player bug, where top-level functions get defined with no context, rather than in their correct lexical context. It costs nearly nothing to do this and it makes it so any function can be invoked from an idle task without the programmer having to make explicit all their global references. This is not new to Legal's -- it's how we've been doing it for a while...

Reply via email to