1 (edited by Fabur 2010-02-23 11:54:50)

Topic: [RESOLVED] Chumby won't refresh custom widget

Hey everyone,


I have been playing around with some ActionScript 2 stuff.
My biggest problem was that I was unable to refresh the screen.
Thanks to Raff and his chumbydevelop examples I was able to get it to work.

Well, at least on my PC.
The problem is that the chumby will the do refresh "circle" only once.
Here is an example code:

class Main 
{
    var time = 0;
    
    static function main(swfRoot:MovieClip) 
    {
        // entry point
        var app = new Main(swfRoot);
    }
    
    function Main(swfRoot:MovieClip)
    {
        _root.createTextField("t",0,0,0,320,240);
        _root.t.text = time;
        time += 1;
        
        setInterval(this, "onTimer", 1000);
    }
    
    function onTimer()
    {
        time += 1;
        _root.t.text = _root.t.text + "\r" + time;
    }
}

On my PC I get something like this:
0
2
3
4
5

and so on.

The chumby seems to stop after the first circle through the onTimer function and I get this:
0
2


In my shell (ssh) I get the following error message over and over again:
ClientObject::MainLoop(playCount=48) master instance 0021e230 is not playing!!!

The playCount is getting higher.
I really don't get it.
The other examples are working fine and I don't see what I am missing.
I am only using the stop_control_panel and chumbyflashplayer.x -i /mnt/usb/x.swf commands.

Am I missing something?
(I am a completely new to flash programming.)

2 (edited by gmcbay 2010-02-22 17:00:54)

Re: [RESOLVED] Chumby won't refresh custom widget

Try changing it to this:

class Main
{
    var time = 0;
    static var app:Main;
   
    static function main(swfRoot:MovieClip)
    {
        // entry point
        app = new Main(swfRoot);
    }
   
    ....
}


By declaring app as a var inside the main function, it is falling out of scope after the main function exits and thus it is fair game for the garbage collector to come and clean that object up since nothing external is holding a reference to it.   It is more surprising that this continues to work indefinitely on the PC than it is that it doesn't work on the chumby.   My guess would be the garbage collector on the desktop Flash player is less aggressive and defers collecting until it really needs the resources.

Re: [RESOLVED] Chumby won't refresh custom widget

Hey gmcbay,

thanks for your help.

I have changed my code but it isn't working either.

In the example codes, the variable is also declared inside the static main function.

Here is one of those example codes (only the main.as):

/*
 * The MIT License
 *
 * Copyright (c) 2008 Raffaele Sena <raff367@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

import util.*;

class BarChart.Main
{
    private var parent:MovieClip;
    private var current:Number = 0;
    private var delta:Number = 7;
    private var bar:BarChart;
    
    function Main(mc:MovieClip)
    {
        // save reference to main movieclip
        this.parent = mc;
        
        // set background and app title
        UI.mainScreen(mc, UI.BLUE_1, "My First Chumby Application");
        
        // create bar chart
        bar = new BarChart(mc, 10, 40, 300, 190, 8, UI.BLACK, UI.CYAN);
        
        // start timer
        setInterval(this, "onTimer", 100);    
        
        mc.app = this;
        mc.onMouseDown = function() {
            this.app.bar.clear();
        }
    }
    
    function onTimer()
    {
        current += (delta - int(Math.random() * 10));
        if (current > 100) {
            current = 100;
            delta = 3;
        } else if (current < 0) {
            current = 0;
            delta = 7;
        }
        
        trace(current);
        bar.add(current);
    }
    
    static function main(mc:MovieClip)
    {
        var app = new Main(mc);
    }
}

And here the BarChart.as:

/*
 * The MIT License
 *
 * Copyright (c) 2008 Raffaele Sena <raff367@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

import util.UI;
import flash.geom.Point;
import flash.geom.Rectangle;

/**
 * A simply bar char widget
 *
 * @author Raffaele Sena
 */

class util.BarChart 
{
    var mc:MovieClip;
    var bars:Array;
    var background:Number;
    var barColor:Number;
    var barWidth:Number;
    var barHeight:Number;
    var space:Number;
        
    function BarChart(parent:MovieClip, x:Number, y:Number, w:Number, h:Number, bw:Number, backgroundColor:Number, color:Number)
    {
        barHeight = h;
        barWidth = bw == undefined ? 2 : bw;
        space = bw > 2 ? 1 : 0;
        
        background = backgroundColor == undefined ? UI.BLACK : backgroundColor;
        barColor = color == undefined ? UI.WHITE : color;
        
        mc = parent.createEmptyMovieClip("mc", parent.getNextHighestDepth());
        mc._x = x;
        mc._y = y;

        UI.drawRect(mc, 0, 0, w, h, background);
        
        var mask:MovieClip = parent.createEmptyMovieClip("mask", parent.getNextHighestDepth());
        mask._x = x;
        mask._y = y;
        UI.drawRect(mask, 0, 0, w, h, background);
        mc.setMask(mask);

        bars = new Array();
        
        for (var i = 0; i < w / barWidth; i++) {
            var bar:MovieClip = mc.createEmptyMovieClip("bar_" + i, mc.getNextHighestDepth());
            bar._x = barWidth * i;
            bar._y = barHeight;
            UI.drawRect(bar, 0, 0, barWidth - space, h, barColor);
            bars.push(bar);
        }
    }
    
    function add(n:Number)
    {
        var bar:MovieClip = MovieClip(bars.shift());
        bars.push(bar);
        
        bar._y = barHeight - int(barHeight * n / 100);

        for (var i = 0; i < bars.length; i++)
        {
            bar = bars[i];
            bar._x = barWidth * i;
        }
    }
    
    function clear()
    {
        for (var i = 0; i < bars.length; i++)
            bars[i]._y = barHeight;
    }
}

This one is working without any problems, but I don't get why.

4 (edited by gmcbay 2010-02-23 11:29:32)

Re: [RESOLVED] Chumby won't refresh custom widget

Is the code you're using still what was in the original post?  Because when I changed that code you posted as suggested in my post and compiled it in the version of mtasc that comes with the latest version of FlashDevelop (what IDE are you using btw?), it works fine.   However, your original version (before I make the change) has the same issue you mentioned.

The example you posted doesn't have the garbage collection issue because it is creating a reference to the main object externally to itself when it sets mc.app = this; in the Main object's constructor.    After that there's a reference to the main object named 'app' on the swf's root, so it won't get garbage collected unless that reference is removed.

Re: [RESOLVED] Chumby won't refresh custom widget

Wow ok, sorry.

I don't know what I did wrong, but I just tested it again and it worked.
Don't know what I had forgotten the last time (but it was not the code, I changed that; must have been something else. compiling? scp went wrong?).


Thanks for your help and your useful explanation!



And yeah, I am also using the latest version of FlashDevelop.
Better than using vi on the chumby. big_smile