Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-27-2009, 03:25 PM   #1
ebrett
Registered User
 
Join Date: Feb 2009
Posts: 4
Default Actionscript + PHP

I need some help. Basically i'm trying to connect my Sandy3d project to a MySQL database. I understand actionscript cannot directly link to the database, so you use PHP to create a string which actionscript understands.

This part i'm alright with, but where i'm stuck is understanding how to perform a loop function to extract this data into my project within actionscript.

This is my code atm, which imports a model into Sandy. What I would like to do is modify the code so it pulls 'filename' from the PHP string then moves onto the next record with a loop.

I just can't get my head around how to go about doing this. Please help, thanks.

Code:
public function Example()
      { 
		var parser:IParser = Parser.create("assets/main1.ASE",Parser.ASE );
		var parser1:IParser = Parser.create("assets/main2.ASE",Parser.ASE );
		var parser2:IParser = Parser.create("assets/models/ASE/media.ASE",Parser.ASE );
	    
		parserStack = new ParserStack();
		parserStack.add("main1",parser);
		parserStack.add("main2",parser1);
		parserStack.add("media",parser2);
		parserStack.addEventListener(ParserStack.COMPLETE, parserComplete );
		parserStack.start();
		
	  }
ebrett is offline   Reply With Quote
Old 02-28-2009, 02:09 AM   #2
ebrett
Registered User
 
Join Date: Feb 2009
Posts: 4
Default

This is drivig me crazy, but I think i'm getting somewhere. I need someone who knows more about actionscript 3.0 though. I had some code, which starting pulling data from the PHP string however i've now found AS 3.0 wont support loadVars, so it needs modifying and i'm abit stuck.

Actionscript 2.0 code (working)

Code:
 
var sender:LoadVars = new LoadVars(); 
var receiver:LoadVars = new LoadVars(); 
receiver.onLoad = function(ok){ 
     if(ok){ 
         for(var i =1;i<=receiver.total;i++){ 
             receiver["dataPacket"+i] = receiver["user_data"+(i)].split("|"); 
             var _id:String = receiver["dataPacket"+i][0]; 
             var _xCoord:String = receiver["dataPacket"+i][1]; 
             var _yCoord:String = receiver["dataPacket"+i][2]; 
             var _zCoord:String = receiver["dataPacket"+i][3];
             var _nameLong:String = receiver["dataPacket"+i][4];
	     var _description:String = receiver["dataPacket"+i][5]; 
             delete(receiver["user_data"+i]); 
	
trace( "id=" + _id + " xCoord=" + _xCoord + " yCoord=" + _yCoord + " zCoord=" + _zCoord + " Description=" + _description );
trace("");
         } 
     }else{ 
         trace("error loading PHP file");
     } 
} 
		 
sender.sendAndLoad("http://edd.servehttp.com/fyp/getBuildingDetails.php",receiver,"post");
What I need is the version below to work. I have started editing to AS 3.0 but theres an error with lines 13 and 17.

Code:
import flash.net.URLLoader 
import flash.net.URLRequest 

var receiver:URLLoader;
receiver = new URLLoader();


var req:URLRequest = new URLRequest("http://edd.servehttp.com/fyp/getBuildingDetails.php");

receiver.onLoad = function(ok){ 
     if(ok){ 
         for(var i =1;i<=receiver.total;i++){ 
             receiver["dataPacket"+i] = receiver["user_data"+(i)].split("|"); 
             var _id:String = receiver["dataPacket"+i][0]; 
             var _xCoord:String = receiver["dataPacket"+i][1]; 
             var _yCoord:String = receiver["dataPacket"+i][2]; 
             var _zCoord:String = receiver["dataPacket"+i][3];
	var _nameLong:String = receiver["dataPacket"+i][4];
	    var _description:String = receiver["dataPacket"+i][0];
              
             delete(receiver["user_data"+i]); 
			 trace( "id=" + _id + " xCoord=" + _xCoord + " yCoord=" + _yCoord + " zCoord=" + _zCoord + " Description=" + _description );
			 trace("");
         } 
     }else{ 
trace("error loading PHP file");	 
     } 
}
ebrett is offline   Reply With Quote
Old 02-28-2009, 02:50 AM   #3
RelaxGuy
Member
 
RelaxGuy's Avatar
 
Join Date: Oct 2007
Posts: 84
Default

So you want to send a string from PHP to Flash correct?
I've never used AS2 or Sandy 3D but this should help with your AS3:

ActionScript Code:
import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.URLLoaderDataFormat; import flash.events.Event; //new URLLoader, set the data type var receiver:URLLoader = new URLLoader(); receiver.dataFormat = URLLoaderDataFormat.TEXT; //.php file we want to call var req:URLRequest = new URLRequest("http://edd.servehttp.com/fyp/getBuildingDetails.php"); //listen for when the urlLoad is complete receiver.addEventListener(Event.COMPLETE, loadingComplete); //initialize urlLoad receiver.load(req); function loadingComplete(event:Event):void {      //get a reference to the URLLoader;      var receiver:URLLoader = URLLoader(event.target);      // look at the incoming data, your PHP string should show up here      trace(receiver.data); }
RelaxGuy is offline   Reply With Quote
Old 02-28-2009, 03:35 AM   #4
ebrett
Registered User
 
Join Date: Feb 2009
Posts: 4
Default

I actually found an example very similar to yours on the internet, which I got working. Yours however, seems more logical, so i probs go with that.

Problem i'm having now of course is spliting up the data so its useful. Need a For Loop like the AS 2.0 example so i can extract the data to variables. Everything I try however wont work. I understand what the AS 2.0 example is doing, however I lack enough knowledge to make it work with AS 3.0.
ebrett is offline   Reply With Quote
Old 02-28-2009, 10:52 AM   #5
ebrett
Registered User
 
Join Date: Feb 2009
Posts: 4
Default

All is well now. Decided to create an XML page using PHP as its alot easier to reference in Actionscript.
ebrett is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache, MYSQL, PHP and actionscript to load images noyzy ActionScript 2.0 13 10-10-2008 01:15 PM
Actionscript and PHP error checking? kilauea Server-Side Scripting 0 06-25-2008 09:55 AM
How do I control images/text in Flash using PHP & actionscript dynamically? bongobongo ActionScript 2.0 2 01-03-2008 10:32 AM
XML, Actionscript and PHP WaZz ActionScript 2.0 0 03-23-2007 04:02 PM
PHP XML with ActionScript jimmytboi ActionScript 2.0 2 03-10-2007 02:04 AM


All times are GMT. The time now is 11:19 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.