1 (edited by gingerbeardman 2008-03-02 19:09:43)

Topic: Updating Flash controls based on root params?

I have a widget configuration movie that stores the value of a checkbox and radio button group through the standard method shown in the sample banner widget. This works fine, storing the states as true/false when "Done" is pressed. And when I reload the widget configuration the correct states are read back from _root.params. All good so far!

Next, using an onEnterFrame function, I set the value (for the checkbox) and selected (for the radio buttons) properties as required. This is where my problem lies - it works in the Flash IDE (as far as I can tell as I can't read the root params but go with default values) but not when it's on Chumby.com - leaving me stumped.

Any ideas?

Here's my code as it stands:

this.onEnterFrame = function() {
    pagelistInput.text = _root.params['pagelist'];
    
    slideshowPref = _root.params['slideshow'];
    if (slideshowPref == undefined) {
        slideshowCheckbox.value = true;    //default value for checkbox
    } else {
        slideshowCheckbox.value = slideshowPref;
    }
    
    if (_root.params['random'] == undefined) randomFeature = true;    //default value for radio button

    if (randomFeature == true) {
        randomRadio.selected = true;
        disableInput();
    } else {
        userRadio.selected = true;
        enableInput();
    }

    delete this.onEnterFrame;
}

Re: Updating Flash controls based on root params?

In the widget, the parameters are not stored in the "params" array - they're simply declared on the _root, ie. _root.pagelist, _root.slideshow, _root.random

I'd change the name of "random", since it might conflict with the built-in function of the same name.

Re: Updating Flash controls based on root params?

Thanks Dave,

Not sure where I got that crazy syntax. Oops!

4 (edited by gingerbeardman 2008-03-03 03:29:59)

Re: Updating Flash controls based on root params?

Ah, I knew I'd got the code from somewhere: it's in the sample banner widget

I'm now even more confused, because that code works when uploaded as a private widget!

Whereas your proposed code of _root.banner or just banner does not work.

//
// load the current value of the "banner" variable into the edittext field
//
this.onEnterFrame = function() {
    bannerInput.text = _root.params['banner'];
    this.onEnterFrame = undefined;
}

5 (edited by gingerbeardman 2008-03-03 03:31:12)

Re: Updating Flash controls based on root params?

This seems to have been reported before: http://forum.chumby.com/viewtopic.php?id=1850

So, just to repeat - I have code that reads in the params but when I attempt to set the values of a checkbox and radio button group it doesn't behave as expected.

Any help appreciated.

matt

6 (edited by gingerbeardman 2008-03-03 05:15:27)

Re: Updating Flash controls based on root params?

Here's my config.fla, feel free to upload it (with any widget ) just to give it a try.

http://www.divshare.com/download/3936606-4c6

Debug values in an overlay: checkbox state, radio button state, text box contents

Any help appreciated.

matt

Re: Updating Flash controls based on root params?

You should not populate the values of the controls from an onEnterFrame handler, because the configuration widget has to collect those values from the server before you can use them - that can take several frames.

Instead, provide a function to _chumby_get_widget_parameters that will automatically be called, and use that to populate the controls.

Re: Updating Flash controls based on root params?

That'll be, it, then.

Please update the Sample Banner widget with the correct code and I will hack away at mine to do the same. Thanks.

Re: Updating Flash controls based on root params?

Well, it's not quite that cut-and-dry.  When Flash enters a new frame, it cannot call functions in submovies in the new frame until at least one frame time has passed.  The technique that the banner code uses is a common trick to get around that, although in the this specific case, it's not necessary since it's not calling a function.  This code is derived from a widget where it *was* calling functions.

It's done in this code because the controls exist on the *second* frame of the movie.  If you have a single-frame movie, then the logic should be as I described in my last post.

Re: Updating Flash controls based on root params?

As you can see from my config.fla I am using the banner sample as a basis.

I'm getting awfully confused here. smile

Re: Updating Flash controls based on root params?

OK, I'll take a closer look at your FLA when I have a chance.

Re: Updating Flash controls based on root params?

I *think* I need to figure out whether the form controls have loaded before I try to give them their values.

Flash  is trying it's damndest to stop me enjoying the chumby wink

Re: Updating Flash controls based on root params?

Eureka! I rebuilt my config widget starting (again) from the sample banner, and using some advice from misterhee to sanity check the boolean data to make sure it is really so, and it works.

matt