Re: sendAndLoad

uniontek <[email protected]> Thu, 06 Nov 2003 20:02:01 +0100
Newsgroups gmane.comp.web.ming.general
Organization Uniontek (association Union-Technologique)
Message-ID <[email protected]>
Le jeu 06/11/2003 à 08:31, Wolfgang Hamann a écrit :
> Hi,
> 
> all these things should work (I recently used netconnection quite a bit instead of loadvars)
> Are you sure you set movie version to 6?
> 
> Wolfgang
> 
> >> Peace to all mingers!!
> >> 
> >> i'm currently testing ming0.3a from CVS.
> >>  
> >> Actionscript load() works fine for me but i spend hours trying to get a
> >> result from sendAndLoad() to exchange data with php files via POST,
> >> but all the codes i tested didn't work.
> >> The question about loadVariables and sendAndLoad on this list
> >> seems to have no answer...
> >> I browse all the web, but i can't get a ming native working example
> >> using this...
> >> 
> 
> 
Waoooooo!!!
Yes it works perfectly ...
My syntax was wrong, i was misundertanding the way sendAndLoad was
working.
Here is a modification of http://www16.brinkster.com/gazb/ming/ barchart
to demonstrate (if it could be usefull for someone).

a Simple phpvars.php
<?php
function get(){
	$var1 = rand(0, 100);
	$var2 = rand(0,100);
	$var3 = rand(0,100);
	$var4 = rand(0,100);
	$var5 = rand(0, 100);
	return
"var1=$var1&var2=$var2&var3=$var3&var4=$var4&var5=$var5&loaded=1";
}
if(isset($HTTP_POST_VARS["action"]))
{
   switch($HTTP_POST_VARS["action"])
   {
      case "get":
         $result = get();
         print $result;
         break;
   }
}else{
	print "loaded=0";
}
?>

and the barchart file...

<?
Ming_setScale(20.00000000);
ming_useswfversion(6);
$movie = new SWFMovie();
$movie->setDimension(550,400);
$movie->setBackground(0xc0,0xc0,0xc0 );
$movie->setRate(31); 

$strAction = "
// make bar
createEmptyMovieClip('bar', 1);
with(bar){
beginFill(255, 90); moveTo(0, 0); lineTo(0, -100); lineTo(40, -100);
lineTo(40, 0); lineTo(0, 0); endFill(); _x=-500; _y=-500;
}

// duplicate bar
for(i=1;i<6;i++) {
bar.duplicateMovieClip('bar'+i,100+i);
with(_root['bar'+i]){
_y=110; _x=110+i*42;
_yscale=0;
}
var col=new Color(_root['bar'+i]);
col.setRGB(random(0x666666));
};

// make textfield
createTextField('mytext',2,10,10,360,100);
with (mytext){ 
multiline = true;
wordWrap = true; 
border = true;
text='loading data every fifteen seconds.....';
type = 'dynamic';
}

// make textformat
myformat = new TextFormat();
myformat.color = 0x006600;
myformat.size = 14;
myformat.font = '_serif';
myformat.bold = false;
mytext.setTextFormat(myformat);

// make bars rescale
onEnterFrame=function() {
for(i=1;i<6;i++) {
var disty=lv['var'+i]-this['bar'+i]._yscale;
var movey=disty/5;
this['bar'+i]._yscale+=movey;
}};

// make loadVars
lv = new LoadVars();
lv.action = 'get';
lv.onLoad = function(success) {
if(success) {
mytext.text='loaded= ' + success;
for(i=1;i<6;i++) { mytext.text+='\n this.var'+i+'=' + this['var'+i]; }
mytext.setTextFormat(myformat);  // hack
}else { mytext.text='failed'; }
};

// make callback
callback = function()  {
counter=++counter%3;
lv.sendAndLoad('phpvars.php');
};
counter=0;
lv.sendAndLoad('phpvars.php',_level0,POST);

// set callback
intervalID = setInterval( callback, 15000 ); 
";
$movie->add(new SWFAction(str_replace("\r", "", $strAction)));
//$movie->save("dynbarchart.swf");
header("Content-type: application/x-shockwave-flash");
$movie->output();

?>

Thanks