Welcome, Guest. Please login or register.
Did you miss your activation email?
05/21/12, 04:50
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash MX 2004 (Moderators: Flash-db, Musicman, vesa kortelainen, Ronald Wernecke, Andresss, papachan)
| | |-+  loadVars looping issue
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 3 Print
Author Topic: loadVars looping issue  (Read 9149 times)
davef
Server what's that
*
Posts: 3


View Profile Email
« on: 05/30/07, 17:59 »

Alright, I’m dying here and I need some serious help.  I’ve been working on this all day and I’ve gotten utterly nowhere.  I’m trying to do a loop within a loadVars function and it’s not going so well.  What the loop is supposed to do is duplicate movie clips that have variables within them to display values to the user. 

I can’t for, for some reason get the loop to dynamically create the movie clips, name them, and position them down.  Here’s what I’ve got so far:

Code:
leadVars.onLoad = function(succes) {
if (this["status"] === "success") {
leadCount = this["leadCount"];
trace("Count = "+leadCount);
bar0.one = this["bar0.column1"];
bar0.two = this["bar0.column2"];
bar0.three = this["bar0.column3"];
bar0.four = this["bar0.column4"];
leadBase = Number(0);
leadNext = Number(1);
if (leadCount>=1) {
for (i=2; i<leadCount; i++) {
duplicateMovieClip("bar"+leadBase, "bar"+leadNext, leadNext);
var oldLead = this["bar"+leadBase];
var newLead = this["bar"+leadNext];
newLead._y = oldLead._y + 25;
trace(newLead._y);
}
trace("Stick a fork in me.");
}
}

The code is the action the loadVars would take if successful.  You’ll notice it populates the first movie clip with values sent over so there isn’t a empty clip sitting there and then what I was trying to make it do is duplicate that, name it bar1, and add in the information.  What’s coming over on php is:

status=success&leadCount=4&bar0.column0=John&bar0.column1=Chicago&
bar0.column2=IL&bar0.column3=3&bar0.column4=&bar1.column0=Phil&
bar1.column1=Hollywood&bar1.column2=CA&bar1.column3=4&bar1.column4=&
bar2.column0=Lead 2&bar2.column1=New York&bar2.column2=NY&bar2.column3=2&bar2.column4=&bar3.column0=Lead1&
bar3.column1=Houston&bar3.column2=TX&bar3.column3=1&bar3.column4=

As you can see its formatted to fill bar# and then a column variable.  I can’t even get the loop to create the extra movie clips 25 pixels down from each other.  I can get them to create, but they’re all right on top of each other and they weren’t grabbing the information.  I took a step back to just see if I could get the loop to generated X amount of movie clips without overlapping.  leadCount is how many movieclips need to be made.  It populates bar0 so I know its communicating.  This code is located in the root of the movie, the movie itself will be embedded in a much larger application so I can’t use _root or it will call things all the way from the other swf file.

Anyone have any ideas what I’m doing wrong?
« Last Edit: 07/22/07, 16:35 by Jorge Solis » Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #1 on: 05/31/07, 01:19 »

this inside the onLoad handler refers to the LoadVars object, so var oldLead = this["bar"+leadBase] points to nowhere. If you want to use this, you need a pointer to the timeline, like this:

leadVars.ref = this

Then inside the onLoad handler

var oldLead = this.ref["bar"+leadBase];

And so on

Jorge
Logged

davef
Server what's that
*
Posts: 3


View Profile Email
« Reply #2 on: 05/31/07, 09:04 »

Oh man your a lifesaver, worked like a charm.
Logged
pt01
Server what's that
*
Posts: 18


View Profile
« Reply #3 on: 07/20/07, 00:11 »

Hi Jorge,

sorry, but where should the line "leadVars.ref = this" be placed? immediately after leadVars.Load(...) is called? outside of leadVars.onLoad = function(succes) {...} ?

Thanks,

pt
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #4 on: 07/20/07, 01:21 »

After the LoadVars declaration

loadVars = new LoadVars()
loadVars.ref = ....

Jorge
Logged

pt01
Server what's that
*
Posts: 18


View Profile
« Reply #5 on: 07/22/07, 12:53 »

Hi Jorge, this is my AS code, but the variable from PHP is undefined (from trace)...
Code:
var zSignal:Array=new Array();
var getFeed:LoadVars=new LoadVars();
getFeed.ref=this;
getFeed.load("http://localhost/php/sendtoflash.php?ck="+new Date().getTime());
getFeed.onLoad = function(success) {
     if (!success) {
          trace("Can not load");
     } else {
          loading_mc.removeMovieClip();
trace(this.toString());

  trace("Loaded");
          var records:Number=this.ref["records"];
          trace(records);
          if (records==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=zSignal;
stop();


...and the trace statements return these results:
wholePx8=0%2E00%0A%20%0D%0A&salePx8=0%2E00&oldPx8=1111%2E00&item8=s1&action8=act1&
tsp8=12%3A35%3A36pm&sID8=1&wholePx7=0%2E00%0A&salePx7=0%2E00&oldPx7=2222%2E00&item7=s2&
action7=act1&tsp7=12%3A35%3A45pm&sID7=2&wholePx6=0%2E00%0A&salePx6=0%2E00&oldPx6=2222%2E25&
item6=s2&action6=act2&tsp6=12%3A39%3A42pm&sID6=3&wholePx5=0%2E00%0A&salePx5=0%2E00&
oldPx5=1111%2E00&item5=s1&action5=act2&tsp5=01%3A25%3A12pm&sID5=4&wholePx4=0%2E0000%0A&
salePx4=0%2E0000&oldPx4=3333%2E2112&item4=s3&action4=act1&tsp4=01%3A55%3A48pm&sID4=5&
wholePx3=0%2E00%0A&salePx3=0%2E00&oldPx3=2222%2E25&item3=s2&action3=act1&tsp3=02%3A34%3A15pm&
sID3=6&wholePx2=0%2E00%0A&salePx2=0%2E00&oldPx2=1111%2E75&item2=s1&action2=act1&
tsp2=02%3A35%3A05pm&sID2=7&wholePx1=0%2E00%0A&salePx1=0%2E00&oldPx1=4444%2E80&item1=s4&
action1=act1g&tsp1=02%3A35%3A14pm&sID1=8&wholePx0=0%2E0%0A&salePx0=0%2E0&oldPx0=5555%2E0&
item0=s5&action0=act1&tsp0=02%3A35%3A18pm&sID0=9&%3Cbr%20%2F%3E%0A%3Cb%3ENotice%3C%2Fb%
3E%3A%20%20Undefined%20offset%3A%20%206%20in%20%3Cb%3EC%3A%5Chtdocs%5Cphp%
5Csendtoflash%2Ephp%3C%2Fb%3E%20on%20line%20%3Cb%3E15%3C%2Fb%3E%3Cbr%20%2F%3E%0A
%3Cbr%20%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E%3A%20%20Undefined%20offset%3A%20%205%
20in%20%3Cb%3EC%3A%5Chtdocs%5Cphp%5Csendtoflash%2Ephp%3C%2Fb%3E%20on%20line%20%3Cb
%3E15%3C%2Fb%3E%3Cbr%20%2F%3E%0A%3Cbr%20%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E%3A%20%20
Undefined%20offset%3A%20%204%20in%20%3Cb%3EC%3A%5Chtdocs%5Cphp%5Csendtoflash%2Ephp%3C%2Fb
%3E%20on%20line%20%3Cb%3E15%3C%2Fb%3E%3Cbr%20%2F%3E%0A%3Cbr%20%2F%3E%0A%3Cb%
3ENotice%3C%2Fb%3E%3A%20%20Undefined%20offset%3A%20%203%20in%20%3Cb%3EC%3A%
5Chtdocs%5Cphp%5Csendtoflash%2Ephp%3C%2Fb%3E%20on%20line%20%3Cb%3E15%3C%2Fb%3E%3Cbr
%20%2F%3E%0A%3Cbr%20%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E%3A%20%20Undefined%20offset%
3A%20%202%20in%20%3Cb%3EC%3A%5Chtdocs%5Cphp%5Csendtoflash%2Ephp%3C%2Fb%3E%20on%20line
%20%3Cb%3E15%3C%2Fb%3E%3Cbr%20%2F%3E%0A%3Cbr%20%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E%
3A%20%20Undefined%20offset%3A%20%201%20in%20%3Cb%3EC%3A%5Chtdocs%5Cphp%5Csendtoflash%2Ephp
%3C%2Fb%3E%20on%20line%20%3Cb%3E15%3C%2Fb%3E%3Cbr%20%2F%3E%0Arecords=9&onLoad=%5Btype%20
Function%5D&ref=%5Flevel0
Loaded
undefined

I don't understand why the variable records is undefined... which should have a value of 9.

Thanks for taking a look.

pt
« Last Edit: 07/22/07, 16:34 by Jorge Solis » Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #6 on: 07/22/07, 16:36 »

PHP is sending a notice. Modify the error level, try adding:

error_reporting(E_ALL ^ E_NOTICE);

At the begining of the PHP script

Jorge
Logged

pt01
Server what's that
*
Posts: 18


View Profile
« Reply #7 on: 07/22/07, 17:01 »

Thanks for the reply Jorge.  After I added the line at the beginning of my PHP script as you suggested, the  trace in AS returns this:

wholePx8=0%2E00%0A%20%0D%0A&salePx8=0%2E00&oldPx8=1111%2E00&item8=s1&action8=act1&tsp8=12%3A35%3A36pm&sID8=1&wholePx7=
0%2E00%0A&salePx7=0%2E00&oldPx7=2222%2E00&item7=s2&action7=act1&tsp7=12%3A35%3A45pm&sID7=2&wholePx6=0%2E00%0A&salePx6=0%2E
00&oldPx6=2222%2E25&item6=s2&action6=act2&tsp6=12%3A39%3A42pm&sID6=3&wholePx5=0%2E00%0A&salePx5=0%2E00&oldPx5=1111%2E00&item5
=s1&action5=act2&tsp5=01%3A25%3A12pm&sID5=4&wholePx4=0%2E0000%0A&salePx4=0%2E0000&oldPx4=3333%2E2112&item4=s3&action4=act1&tsp4
=01%3A55%3A48pm&sID4=5&wholePx3=0%2E00%0A&salePx3=0%2E00&oldPx3=2222%2E25&item3=s2&action3=act1&tsp3=02%3A34%3A15pm&sID3=6&
wholePx2=0%2E00%0A&salePx2=0%2E00&oldPx2=1111%2E75&item2=s1&action2=act1&tsp2=02%3A35%3A05pm&sID2=7&wholePx1=0%2E00%0A&sale
Px1=0%2E00&oldPx1=4444%2E80&item1=s4&action1=act1g&tsp1=02%3A35%3A14pm&sID1=8&wholePx0=0%2E0%0A&salePx0=0%2E0&oldPx0=5555%2
E0&item0=s5&action0=act1&tsp0=02%3A35%3A18pm&sID0=9&records=9&onLoad=%5Btype%20Function%5D&ref=%5Flevel0
Loaded
undefined


The variable records is still un-defined.

By the way, how did you put line breaks on that long string?

Thanks for taking a look.

pt
« Last Edit: 07/23/07, 01:18 by Jorge Solis » Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #8 on: 07/23/07, 01:23 »

in the output there are variables like wholePx0, salePx0, oldPx0, item0, action0, ID0, so looking for s10 or s20 will output undefined of course, Try to match the variables you receive

Jorge

PD: To break just press enter at differents points of the output, and please, just post a line, not the whole thing
Logged

pt01
Server what's that
*
Posts: 18


View Profile
« Reply #9 on: 07/23/07, 07:12 »

sorry about the typo in variable names in the original post of AS code...they are actually all matched with PHP's var names...still the big puzzle is why the first variable in the string sent by PHP, records, is still undefined in AS.... the php code is:
Code:
<?php
error_reporting(E_ALL E_NOTICE);
$inFile='rtmsg_test.txt';
if (file_exists($inFile)) {
   $rtSignal=fopen($inFile'rt');
   $aIndex=0;
   while(!feof($rtSignal)) {
     $inlineA[$aIndex]=fgets($rtSignal);
     $aIndex=$aIndex+1;
   }
   $j=0;
   for ($x=$aIndex-1;$x>-1;$x--) {
     $inline=$inlineA[$x];
 list ($p0,$p1,$p2,$p3,$p4,$p5,$p6)=explode("|",$inline);
     if($p0!="" AND $p0!="\n"
  {$p03=(int)$p0+10800;$ts=date('h:i:sa',$p03);}
     else $ts="";
     if ($ts!=""){
      $xx $x+1;
$sID[$j]=$xx;
$tsp[$j]=$ts;
$action[$j]=$p2;
$symbol[$j]=$p3;
$sigPx[$j]=$p4;
$stopPx[$j]=$p5;
$tgtPx[$j]=$p6;
$j=$j+1;
     }
   }
   $sendsignal  'records='.$j."&";
//echo '<pre>';
// print_r($sendsignal);
//echo '</pre>';

   for ($i=0;$i<$j;$i++) {
$sendsignal .= "&sID{$i}=".urlencode($sID[$i]);
$sendsignal .= "&tsp{$i}=".urlencode($tsp[$i]);
$sendsignal .= "&action{$i}=".urlencode($action[$i]);
$sendsignal .= "&item{$i}=".urlencode($symbol[$i]);
$sendsignal .= "&oldPx{$i}=".urlencode($sigPx[$i]);
$sendsignal .= "&salePx{$i}=".urlencode($stopPx[$i]);
$sendsignal .= "&wholePx{$i}=".urlencode($tgtPx[$i]);
   }

   fclose($rtSignal);

   echo $sendsignal;
}
else {
   $j=0;
   $sendsignal  'records='.$j;
   echo $sendsignal;
}
?>



Thank you for taking a look.

pt
« Last Edit: 07/23/07, 07:14 by pt01 » Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #10 on: 07/23/07, 07:26 »

You don't need to urlencode the output, just utf8_encode if you use some special characters. This will help in checking the output: all variables should be separated by & and no garbage should be around there.

Jorge
Logged

pt01
Server what's that
*
Posts: 18


View Profile
« Reply #11 on: 07/23/07, 07:52 »

thank you for the reply.

I don't use any special characters.  I took away the urlencode command/keyword in the PHP script...still the first variable records is still undefined in AS trace.  The output from AS trace statements:
Code:
wholePx8=0%2E00%0A%20%0D%0A&salePx8=0%2E00&oldPx8=1111%2E00&item8=s1&action8=act1&tsp8=12%3A35%3A36pm&sID8=1&
...
&wholePx0=0%2E0%0A&salePx0=0%2E0&oldPx0=5555%2E0&item0=s5&action0=act1&tsp0=02%3A35%3A18pm&sID0=9&
records=9&onLoad=%5Btype%20Function%5D&ref=%5Flevel0

Loaded
undefined

as you can see, there is "records=9" in the trace but it is not been parsed.  What is the stuff infront of it: onLoad=%5Btype%20Function%5D&ref=%5Flevel0 -- is that some standard padding by loadVars function?

Tnx for taking a look.

pt
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #12 on: 07/23/07, 08:16 »

Probably you're tracing this inside the onLoad handler, so it outputs LoadVars specific stuff. Again the output is urlencoded and difficult to inspect. Don't urlencode, open directly the PHP file, copy&paste inside a txt file, check content, all the variables should be like this:

var1=1&var2=2&var3=3 .....

As you seem ecah name/value is splited by a &. As you can see your output look like this, will be fine.

Jorge
Logged

pt01
Server what's that
*
Posts: 18


View Profile
« Reply #13 on: 07/23/07, 08:27 »

this is the thing ... I am no longer urlencoding the output string from php.  The echo out put from PHP in the browser is this:
Code:
records=9&sID0=9&tsp0=02:35:18pm&action0=act1&item0=s5&oldPx0=5555.0&salePx0=0.0&wholePx0=0.0
...  &sID8=1&tsp8=12:35:36pm&action8=act1&item8=s1&oldPx8=1111.00&salePx8=0.00&wholePx8=0.00

which is exactly like you said, var1=val1&var2=val2& ... etc.

I am sorry I don't understand what you mean by:
Quote
open directly the PHP file, copy&paste inside a txt file

You mean to do that in AS?

sorry about my slowness in comprehending this issue.

Thanks again...

pt
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #14 on: 07/23/07, 08:48 »

In your browser write:

http://localhost/php/sendtoflash.php?ck=12345

(ck is just some random to avoid cache according to your AS code)

Inspect the output

Jorge
Logged

Pages: [1] 2 3 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything