Topic: this.onLoad

whilst working on a flash drawing tool discovered that this.onLoad at the top level on a frame did not work, in fact, the Chumby just hung completely and required a restart with the switch on the back.  Anyone got any ideas why this might be?  Turned out it wasn't necessary for the script to function but would be useful to know if that is a known bug or what.

Cheers,
-Joe

* *  **   ***     ***** Joseph Gray Grauwald Creative *****     ***   **  * *

Re: this.onLoad

Keep in mind that your widget is actually being loaded into another movie (the Control Panel).  If by "top level", you're referring to _root or _level0, it's not what you think it is.  You *can* use _root if you set _lockroot to  true on your main timeline and your movie is Flash 7/FlashLite 2.x.

If this isn't the issue please post the bits of Actionscript that are causing the problem so we can diagnose it.

3 (edited by grauwald 2007-04-03 10:23:10)

Re: this.onLoad

was avoiding "_root" as per instructions on the wiki, however, onLoad was crashing this script, pulling the stuff out of onLoad and just putting it "loose" at the beginning of the script fixed the problem:


/*
** Mouse Stuff
*/

this.touched = false;

this.onMouseDown = function () {
    touched = true;
}

/*
** Drawing Stuff
*/

this.onLoad = function () { // this is the offending line
    i = 0;
    totalPoints = 12;
    pointsX = new Array();
    pointsY = new Array();
    pointsX[i] = 160;
    pointsY[i] = 120;
    this.createEmptyMovieClip("canvas", 1);
}

this.onEnterFrame = drawItAll;

function drawItAll () {
    
    //light.text = ASnative(5,15); // get the ambient light sensor reading
    
    //
    if (touched) {
        touched = false;
        //
        ++i;
        if (i>=totalPoints) {
            i = 0;
        }
        //
        xm = this._xmouse;
        ym = this._ymouse;
        //
        pointsX[i] = xm;
        pointsY[i] = ym;

    }
    //
    if (pointsX.length >= 2) {
        canvas.clear();
        trace("start draw");
        canvas.beginFill(0xFFFFFF, 100);
        canvas.lineStyle(1, 0x333333, 100);
        //
        
        canvas.moveTo(pointsX[0], pointsY[0]);
        for(j=1; j<=pointsX.length-1; ++j) {
            
            offset = 4;
            curX = pointsX[j]+((Math.random()*offset)-(offset/2));
            curY = pointsY[j]+((Math.random()*offset)-(offset/2));
            //
            canvas.lineTo(curX, curY);
        }
        canvas.endFill();
    }

    
}
* *  **   ***     ***** Joseph Gray Grauwald Creative *****     ***   **  * *

Re: this.onLoad

OK, I'll look into it.

Re: this.onLoad

I tried this on my prototype Chumby, and the issue is not that onLoad causes the a crash, but that the onLoad() never gets called, and therefore the application crashes.  You will notice the same behavior on your desktop if you comment out the onLoad function above.

The reason the onLoad doesn't get called is that the swf is loaded into the control panel swf.  In such cases Flash doesn't call the onLoad function on the loaded timeline.  You can try this even without the Chumby, as I did:

1. publish the above code as is, with the onLoad, and save as points.swf
2. Create a swf called loader.swf, with only 2 lines of code:
   mc = this.createEmptyMovieClip("mc",1);
   mc.loadMovie('points.swf');

You will see that even though points.swf runs fine, when loader.swf loads it, it will hang because the onLoad function isn't called.

According to other posts, the production Chubys will create a new instance of the flash player for each swf, so it will not be loaded into another, and therefore the onLoad will be called, and your program will work fine.  (BTW, I like the effect you created.)

Re: this.onLoad

instead of requiring developers to avoid _root, I suggest you use _lockroot = true... assuming you can do this in Flashlite.

Re: this.onLoad

thanks bucini, nice work on your part as well. 

Interesting to realize that the chumby "OS" is an illusion and that the interface is simply a flash file loading other swfs. 

Which begs the question is the .fla file used to create the UI available?  And can the UI swf be replaced?

* *  **   ***     ***** Joseph Gray Grauwald Creative *****     ***   **  * *

Re: this.onLoad

grauwald wrote:

Interesting to realize that the chumby "OS" is an illusion and that the interface is simply a flash file loading other swfs.

I don't think we made any claim otherwise - but in any case, that's how the current prototypes work. However, the production units don't work that way - the widgets are loaded into their own instance of the Flash player, not into the Control Panel.

Which begs the question is the .fla file used to create the UI available?  And can the UI swf be replaced?

We don't provide the FLA for the Control Panel, however, on a prototype unit it can simple be replaced on the file system with your own SWF.  In production units, the file system is read-only, however you can override the launch of the Control Panel by placing an alternative on a USB dongle and using the user hooks built into the boot code.  That's how we test new Control Panels.

9 (edited by zachninme 2007-05-31 06:18:20)

Re: this.onLoad

Its not hard, however, to get all the XML that contains user's channels and their widgets. So you could re-make the control panel. I worked on doing this awhile ago, I might try again wink

(By the by, here's a nice place to get started with the XML, it will lead you to everything else: http://www.chumby.com/xml/users/YOUR-US … L-GO-HERE)
Profile is a channel.

Re: this.onLoad

This should probably continue on the Chumby OS thread now.

* *  **   ***     ***** Joseph Gray Grauwald Creative *****     ***   **  * *