1 (edited by tboling1 2010-06-06 16:02:45)

Topic: Chumby LoadVars

I have seen a few posts that have mentioned something similar to what I'm trying to accomplish but none of those suggestions seemed to fix my problem so I'm hoping I just missed something.  I have created a very simple project (based off of Raffaele Sena's Chumby template) that makes a menu of 8 choices.  When the user clicks one of the choices, it sends a post request to a local server.  I have used FlashDevelop to create an swf file.  This file performs perfectly on my desktop.  Clicking one of the menu choices sends the corresponding post request to the server.  However, I put it onto my chumby and it no longer works correctly.  It looks like it works, but the server never sees the post requests from the chumby. Here is my relevant code:

function onMenuSelect(i:Number) {
        var sendInfo:LoadVars = new LoadVars();
        var recieve:LoadVars = new LoadVars();
        recieve.onLoad = function(success:Boolean) {
            if ( success) {
                trace(recieve);
            }
        }
        //Load up all the variables you want to POST
        sendInfo.myVar = i;

        sendInfo.sendAndLoad("http://192.168.1.9:7650/test.php", recieve, "POST");
    }

Is there a known problem using LoadVar.sendAndLoad on flash lite or am I doing something wrong?

Thanks for any help you can provide.

Re: Chumby LoadVars

Do you have a crossdomain.xml file on your server?  This is required for your server to grant permission to the Flash movie to access it - this is a normal Flash requirement, not limited to the chumby.

Note also that this widget would *only* work if your device and the server were on the same LAN, since you're using a 192.168.*.* IP.  Nobody else would be able to use this widget. Also, if your access point has its own address allocation (such as a NAT that *also* allocates addressed in the same range) then your server might not be visible at all from the chumby.

3 (edited by tboling1 2010-06-06 14:29:51)

Re: Chumby LoadVars

Thank you for your reply duane.

Yes, I realize the 192.168 domain will only work on the same LAN.  I will be changing this to an actual server once the testing is done on my local network.

I do not recall ever setting up a crossdomain.xml file on my server.  However, the flash application works just fine on my desktop.  So if the crossdomain.xml was the problem, then the flash application shouldn't work on ANY computer/device, right?  I should also note that my desktop is not the same computer as this server, just to clear up any confusion that may arise from that.

Thanks again.

Re: Chumby LoadVars

I'd recommend trying a crossdomain.xml as well.  A lot of items will run fine from the desktop whether a crossdomain is available or not.

Also, are you running the widget locally via USB, or uploading to chumby.com as a private widget?

And just a tip:  You can combine your LoadVars into one object:

function onMenuSelect(i:Number) {

        var lv:LoadVars = new LoadVars();
  
        lv.onLoad = function(success:Boolean) {
            if (success) {
                trace(lv);
            }
        }

        //Load up all the variables you want to POST
        lv.myVar = i;

        lv.sendAndLoad("http://192.168.1.9:7650/test.php", lv, "POST");
}

If you don't have one, just copy and paste.  Save as crossdomain.xml -- needs to be placed in the root of your server.

<?xml version="1.0"?>

   <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">

   <cross-domain-policy>

    <allow-access-from domain="*" />

   </cross-domain-policy>

Cheers.

Come join thousands of chumby owners in Chumbyland!

Re: Chumby LoadVars

Well silly me for assuming I didn't need a crossdomain.xml file.  I gave it a try today and now the chumby is working.  Thank to both of you for suggesting that.  I have a few small questions remaining, perhaps you can answer them.

How exactly does this crossdomain.xml file work?  Is it something that my webserver handles, or something that the flash client handles?  I ask because I have a very specific purpose for sending this request and its going to involve a webserver that is very minimal.  So if this crossdomain.xml requires any work by the server, it might not work with my specific webserver.

Thanks.

Re: Chumby LoadVars

tboling1 wrote:

Well silly me for assuming I didn't need a crossdomain.xml file.  I gave it a try today and now the chumby is working.  Thank to both of you for suggesting that.  I have a few small questions remaining, perhaps you can answer them.

How exactly does this crossdomain.xml file work?  Is it something that my webserver handles, or something that the flash client handles?  I ask because I have a very specific purpose for sending this request and its going to involve a webserver that is very minimal.  So if this crossdomain.xml requires any work by the server, it might not work with my specific webserver.

Thanks.

It's only used by the swf.  It just needs to be publicly accessible on the server.

Hope that helps.  Good luck!

Cheers.

Come join thousands of chumby owners in Chumbyland!

Re: Chumby LoadVars

Great!  Thanks for all your help guys.  I've been most impressed with Chumby community so far.  You guys are doing a great job.  I still have a small problem that appears to be related to caching.  I saw a similiar post about that.  I'll go find it again and it should fix my problem (I'll just add a timestamp or something to the request).

Thanks again for all your help.

Re: Chumby LoadVars

tboling1 wrote:

Great!  Thanks for all your help guys.  I've been most impressed with Chumby community so far.  You guys are doing a great job.  I still have a small problem that appears to be related to caching.  I saw a similiar post about that.  I'll go find it again and it should fix my problem (I'll just add a timestamp or something to the request).

Thanks again for all your help.

Yeah it's a common issue.  I use:

var d:Date = new Date();
var ms:Number = d.getTime();
var url:String = "http://www.givemesomenewdata.com?ran="+ms;

Cheers.

Come join thousands of chumby owners in Chumbyland!

Re: Chumby LoadVars

Worked like a charm.  Thanks cbreeze smile

Re: Chumby LoadVars

tboling1 wrote:

Worked like a charm.  Thanks cbreeze smile

Anytime. smile

Cheers.

Re: Chumby LoadVars

The other (and better) way to solve the caching issue if you have control over the server is to have the response set the HTTP "cache-control" header to not cache the response.

The "random number" cache-buster trick still caches the response, and eventually it will fill up with data you're never going to use again, at the expense of data that you would.

Re: Chumby LoadVars

I see your point Duane.  I will see how easy it is to change that in the server configuration.  It would be a better approach.

Thanks for your input and thanks for your original suggestion on crossdomain.xml.

Re: Chumby LoadVars

Typically this is done in the CGI you're creating, not necessarily in the server configuration (you'd do it there mainly for simple files, not scripts).  For instance, in PHP, you'd do something like:

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>

Re: Chumby LoadVars

Perfect.  Appears to be working great. smile

Thanks Duane