Skip to main content
July 19, 2007
Question

Can't load data from PHP into dataGrid

  • July 19, 2007
  • 9 replies
  • 405 views
the php script outputs a urlencoded string, with the first variable named records, which has an integer value.
The AS code looks like this:

var zDP=new Array();
var getFeed:LoadVars=new LoadVars();
getFeed.load(" http://localhost/php/sendrecords.php?ck="+new Date().getTime());
getFeed.onLoad = function(success) {
if (!success) {
trace("Can not load");
} else {
loading_mc.removeMovieClip();
trace("Loaded");
var records:Number=this["records"];
trace(records);
if (numsigs==0)
trace("No msgs yet");
else {
for (var i=0;i<records;i++) {
trace(this["s1"+i]+" "+this["s2"+i]+" "+this["s3"+i]+" "+this["s4"+i]+" "+this["s5"+i]+" "+this["s6"+i]+" "+this["s7"+i]);
zDP.addItem({c1:this["s1"+i], c2:this["s2"+i], c3:this["s3"+i], c4:this["s4l"+i], c5:this["s5"+i],c6:this["s6"+i],c7:this["s7"+i]});
}
}
}
}
zDg.dataProvider=zDP;
stop();

--And it goes to trace(records), and outputs "undefined". Anyone has any idea on what I am doing wrong here?

TIA.

gm.
This topic has been closed for replies.

9 replies

July 23, 2007
Hi Patrick - I am reading your first reply in which you suggested to populate the cells directly instead of using a dataprovider.

Would you give me a hint on how to do that?

Thanks...
July 23, 2007
Hi Patrick -
I am happy to report that the data parsing hurdle has been overcome - in AS trace as shown below, I am seeing all the right elements loaded from PHP. But zDP.push(...) is not adding anything to the zDP array. When I trace it, it just outputs [object Object] ... [object Object]:

for (var i=0;i<records;i++) {
trace(theTarget["s1"+i]+" "+theTarget["s2"+i]+" "+theTarget["s3"+i]+" "+theTarget["s4"+i]+" "+theTarget["s5"+i]+" "+theTarget["s6"+i]+" "+theTarget["s7"+i]);
zDP.push({c1:theTarget["s1"+i], c2:theTarget["s2"+i], c3:theTarget["s3"+i], c4:theTarget["s4l"+i], c5:theTarget["s5"+i],c6:theTarget["s6"+i],c7:theTarget["s7"+i]});
}

I am just trying to populate the dataProvider array zDP for a data grid display.

Thanks for taking a look...
Inspiring
July 23, 2007
Try adding an extra ampersand to the front of the string:

&records=9&...

If that doesn't work, you can try it with a question mark:

?records=0&...

What makes me raise an eyebrow is that your onLoad methid was being
triggered and it went into trying to parse it. What this means is that
Flash was receiving the data and successfully. This doesn't mean that
the data was valid or properly formatted, just that it was received.

Anyhow, let me know how that works out.

Patrick

gm01 wrote:
> Hi Patrick, this is what it output:
>

> Items received from server:
> http://localhost/php/sendtoflash.php?ck = 1185045545578
>

> ...and when I loaded sendtoflash.php with an echo statement to see urlencoded
> string it is about to send to flash, this is what's shown in the browser:
> [
]
>
> records=9&sID0=9&tsp0=02%3A35%3A18pm&action0=act1&item0=s5&regularPx0=5555.0&sal
> ePx0=0.0&wholePx0=0.0%0A&sID1=8&tsp1=02%3A35%3A14pm&action1=act1g&item1=s4&regul
> arPx1=4444.80&salePx1=0.00&wholePx1=0.00%0A&sID2=7&tsp2=02%3A35%3A05pm&action2=a
> ct1&item2=s1&regularPx2=1111.75&salePx2=0.00&wholePx2=0.00%0A&sID3=6&tsp3=02%3A3
> 4%3A15pm&action3=act1&item3=s2&regularPx3=2222.25&salePx3=0.00&wholePx3=0.00%0A&
> sID4=5&tsp4=01%3A55%3A48pm&action4=act1&item4=s3&regularPx4=3333.2112&salePx4=0.
> 0000&wholePx4=0.0000%0A&sID5=4&tsp5=01%3A25%3A12pm&action5=act2&item5=s1&regular
> Px5=1111.00&salePx5=0.00&wholePx5=0.00%0A&sID6=3&tsp6=12%3A39%3A42pm&action6=act
> 2&item6=s2&regularPx6=2222.25&salePx6=0.00&wholePx6=0.00%0A&sID7=2&tsp7=12%3A35%
> 3A45pm&action7=act1&item7=s2&regularPx7=2222.00&salePx7=0.00&wholePx7=0.00%0A&sI
> D8=1&tsp8=12%3A35%3A36pm&action8=act1&item8=s1&regularPx8=1111.00&salePx8=0.00&w
> holePx8=0.00%0A
> [/

>
> wonder what is causing it not getting into Flash.
>
> TIA
>
> gm
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
July 21, 2007
hello everynewday:

I tried your code ... nothing got output (the output screen is blank...)

Don't know what's up with that...

gm
July 21, 2007
Hi Patrick, this is what it output:

Items received from server:
http://localhost/php/sendtoflash.php?ck = 1185045545578

...and when I loaded sendtoflash.php with an echo statement to see urlencoded string it is about to send to flash, this is what's shown in the browser:
[
]
records=9&sID0=9&tsp0=02%3A35%3A18pm&action0=act1&item0=s5&regularPx0=5555.0&salePx0=0.0&wholePx0=0.0%0A&sID1=8&tsp1=02%3A35%3A14pm&action1=act1g&item1=s4&regularPx1=4444.80&salePx1=0.00&wholePx1=0.00%0A&sID2=7&tsp2=02%3A35%3A05pm&action2=act1&item2=s1&regularPx2=1111.75&salePx2=0.00&wholePx2=0.00%0A&sID3=6&tsp3=02%3A34%3A15pm&action3=act1&item3=s2&regularPx3=2222.25&salePx3=0.00&wholePx3=0.00%0A&sID4=5&tsp4=01%3A55%3A48pm&action4=act1&item4=s3&regularPx4=3333.2112&salePx4=0.0000&wholePx4=0.0000%0A&sID5=4&tsp5=01%3A25%3A12pm&action5=act2&item5=s1&regularPx5=1111.00&salePx5=0.00&wholePx5=0.00%0A&sID6=3&tsp6=12%3A39%3A42pm&action6=act2&item6=s2&regularPx6=2222.25&salePx6=0.00&wholePx6=0.00%0A&sID7=2&tsp7=12%3A35%3A45pm&action7=act1&item7=s2&regularPx7=2222.00&salePx7=0.00&wholePx7=0.00%0A&sID8=1&tsp8=12%3A35%3A36pm&action8=act1&item8=s1&regularPx8=1111.00&salePx8=0.00&wholePx8=0.00%0A
[/


wonder what is causing it not getting into Flash.

TIA

gm
Inspiring
July 20, 2007
Hi gm01,

That should be simple. LoadVars should be decoding it directly (unless
there's a flaw in the encoding format), but try this anyhow:

var decoded:LoadVars=new LoadVars();
decoded.decode(serverString); //This is the URL encoded data you get
from the server
trace ('Items received from server:');
for (var item in decoded) {
trace (' '+item+' = '+decoded[item]);
}

What do you get here?

Patrick

gm01 wrote:
> ok good idea - populating the cells directly ...
> Unfortunately, I can't even get pass the step of getting the raw data from
> loadVars call - PHP is returning an url encoded string.... any ideas on fixing
> that first?
>
> Thanks,
>
> gm
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
Known Participant
July 20, 2007
I would try modifying your code to something more like the following. I'm no flash expert, but I got a DataGrid populated with code like this:

var zDP:Array = new Array();
var getFeed:LoadVars = new LoadVars();
var loaded:LoadVars = new LoadVars();
var theTarget:LoadVars = new LoadVars();

getFeed.load(" http://localhost/php/sendrecords.php?ck="+new Date().getTime(), loaded);
loaded.onLoad = getFeed

function getFeed(success:Boolean):void {
if (!success) {
trace("Can not load");
} else {
continueOn(loaded)
}
}

function continueOn(theTarget:LoadVars):Void {
loading_mc.removeMovieClip();
trace("Loaded");
var records:Number = theTarget.records;
trace(records);
if (numsigs==0) {
trace("No msgs yet");
} else {
for (var i=0;i<records;i++) {
trace(theTarget["s1"+i]+" "+theTarget["s2"+i]+" "+theTarget["s3"+i]+" "+theTarget["s4"+i]+" "+theTarget["s5"+i]+" "+theTarget["s6"+i]+" "+theTarget["s7"+i]);
zDP.push({c1:theTarget["s1"+i], c2:theTarget["s2"+i], c3:theTarget["s3"+i], c4:theTarget["s4l"+i], c5:theTarget["s5"+i],c6:theTarget["s6"+i],c7:theTarget["s7"+i]});
}
zDg.dataProvider=zDP;
}
}
stop();
July 20, 2007
ok good idea - populating the cells directly ...
Unfortunately, I can't even get pass the step of getting the raw data from loadVars call - PHP is returning an url encoded string.... any ideas on fixing that first?

Thanks,

gm
Inspiring
July 19, 2007
Hi gm01,

Have you ever tried anything like this before? Data providers need to
be very specifically structured objects. If you look at Flash Remoting
calls you'll see how objects need to be structured so that they can be
used as data providers. Rather than setting the data provider for the
grid, you would be better off simply populating the cells directly.

Regards,
Patrick
BNM

gm01 wrote:
> the php script outputs a urlencoded string, with the first variable named
> records, which has an integer value.
> The AS code looks like this:
>
> var zDP=new Array();
> var getFeed:LoadVars=new LoadVars();
> getFeed.load(" http://localhost/php/sendrecords.php?ck="+new Date().getTime());
> getFeed.onLoad = function(success) {
> if (!success) {
> trace("Can not load");
> } else {
> loading_mc.removeMovieClip();
> trace("Loaded");
> var records:Number=this["records"];
> trace(records);
> if (numsigs==0)
> trace("No msgs yet");
> else {
> for (var i=0;i<records;i++) {
> trace(this["s1"+i]+" "+this["s2"+i]+" "+this["s3"+i]+" "+this["s4"+i]+"
> "+this["s5"+i]+" "+this["s6"+i]+" "+this["s7"+i]);
> zDP.addItem({c1:this["s1"+i], c2:this["s2"+i], c3:this["s3"+i],
> c4:this["s4l"+i], c5:this["s5"+i],c6:this["s6"+i],c7:this["s7"+i]});
> }
> }
> }
> }
> zDg.dataProvider=zDP;
> stop();
>
> --And it goes to trace(records), and outputs "undefined". Anyone has any idea
> on what I am doing wrong here?
>
> TIA.
>
> gm.
>