Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-31-2008, 04:27 PM   #1
Registered User
Join Date: Aug 2008
Posts: 5
Default Passing Variables from PHP to AS3

Okay, i got this working in AS2 and PHP, but i can't use the VAR option on the dynamic text ... so how would i do this in AS3 ?

here's the simple code
using AS2 and PHP 5.2.6
ActionScript Code:
// // create an object to store the variables varReceiver = new LoadVars(); // load the variables from the text file varReceiver.load("info.php"); // trigger something - when the variables finish loading varReceiver.onLoad = function(){ //the variables have finished loading //do something... trace(this.fName); // you use the this keyword to call the variables stored in the object varReceiver trace(this.age); };
and the PHP Code in info.php
PHP Code:
$lname "mira";
$age 24;
// echo or print the variables
echo ("&fName=$fName&lName=$lName&age=$age&");

Last edited by CyanBlue; 06-23-2010 at 03:53 PM. Reason: Code Formatting Tag applied...
Nightshifter is offline   Reply With Quote
Old 08-31-2008, 05:20 PM   #2
Join Date: Aug 2008
Posts: 96

uhm i don't like pass viariable in this way.
isn't clean, mantenable, and only for flash... i ever prefer to use xml, but in this case you need only a porting.

php it's ok.

as3 will result:

ActionScript Code:
package {     import flash.display.Sprite;     import flash.events.*;     import flash.net.URLLoader;     import flash.net.URLLoaderDataFormat;     import flash.net.URLRequest;     public class URLLoaderDataFormatExample extends Sprite     {         public function URLLoaderDataFormatExample()         {             var request:URLRequest = new URLRequest("http://www.[yourdomain].com/params.txt");             var variables:URLLoader = new URLLoader();             variables.dataFormat = URLLoaderDataFormat.VARIABLES;             variables.addEventListener(Event.COMPLETE, completeHandler);             try             {                 variables.load(request);             }             catch (error:Error)             {                 trace("Unable to load URL: " + error);             }         }         private function completeHandler(event:Event):void         {             var loader:URLLoader = URLLoader(event.target);             trace(loader.data.dayNames);         }     } }

see more here http://livedocs.adobe.com/flash/9.0/...=00000316.html
kilian.c is offline   Reply With Quote
Old 08-31-2008, 11:50 PM   #3
Registered User
Join Date: Aug 2008
Posts: 5

Da! Nice replay, but we need to load the value of the variable from a PHP Script file, not txt. from an external text file into a text field which is created manually with AS3.. although this is a good reply if you want to do that... so how do we get the value of the variable $fName only into the text field (if we can use a text field...)
Nightshifter is offline   Reply With Quote
Old 09-01-2008, 12:18 AM   #4
Super Moderator
CyanBlue's Avatar
Join Date: Jan 2002
Location: Centreville, VA
Posts: 27,041

Just change 'params.txt' to 'info.php' and the code should work... You see how kilian.c is accessing the data in the format of loader.data.dayNames inside the completeHandler, that should give you a clue... Try and see if that works for you...
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 09-01-2008, 08:06 AM   #5
Join Date: Aug 2008
Posts: 96

replace this line: var request:URLRequest = new URLRequest("http://www.[yourdomain].com/params.txt");

whit this line: var request:URLRequest = new URLRequest(filename_tf.text);

where filename_tf is the textfield where you digit the phpfilename.

remember that in completeHandler you have all viariables loaded in loader.data!!!!!!!

loader.data.var3 ...

Last edited by kilian.c; 09-01-2008 at 08:10 AM.
kilian.c is offline   Reply With Quote
Old 06-23-2010, 11:05 AM   #6
Registered User
Join Date: Jun 2010
Posts: 1

ActionScript Code:
// package com.artoon.loadvar {     import flash.display.MovieClip;     import flash.events.MouseEvent;     import flash.net.URLLoader;     import flash.events.*;     import flash.net.*;         /**      * ...      * @author Vipul      */     public class Application extends MovieClip     {         private var loader:URLLoader;         private var request:URLRequest;                 public function Application()         {             init();         }                 private function init():void         {             btnClick.buttonMode = true;             btnClick.addEventListener(MouseEvent.CLICK, onClick);         }                 private function onClick(e:MouseEvent):void         {             request = new URLRequest("one.php");             request.method = URLRequestMethod.POST;             loader = new URLLoader();             loader.dataFormat = URLLoaderDataFormat.VARIABLES;             loader.addEventListener(Event.COMPLETE, completeHandler);             loader.load(request);         }                 private function completeHandler(e:Event)         {             var namenew:String = e.target.data;             //trace("Good :"+ namenew);             var mailnew = e.target.data.mail;             var comnew = e.target.data.com;             //lblMail.text = namenew.toString;             lblMail.text = namenew.toString();             trace ('username is ' + namenew.toString());             trace ('email is ' + mailnew);             trace ('email is ' + comnew);         }           } }

Last edited by CyanBlue; 06-23-2010 at 03:54 PM. Reason: AS Tag applied...
vipul@artoonsolutions.com is offline   Reply With Quote
Old 07-16-2010, 11:44 PM   #7
hugs Hugs HUGS!
Join Date: Jun 2006
Posts: 2
Default need the one.php file too

hey vipul at artoonsolutions.com thanks for posting that code. If I could get the one.php file or code within that file I think that would help me a ton! I know php but don't know what to do within the php. I know php so all i have to do is see it and i hope that will get me to be able how to understand how to get the as3 vars from flash then alter what i need to and send them back to flash from the php. it's driving me nuts! thanks
threebrain is offline   Reply With Quote

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing variables from PHP to Flash fuadusman ActionScript 2.0 4 02-26-2008 05:50 PM
Passing variables from php to flash kitsunegari ActionScript 3.0 0 02-14-2008 11:32 PM
Passing variables from flash to PHP and back jonmod ActionScript 2.0 0 07-02-2007 01:43 PM
Passing Variables To PHP holtzy Server-Side Scripting 9 03-09-2003 10:34 PM
passing multiple variables to php Ricod Server-Side Scripting 7 12-06-2001 04:22 PM

All times are GMT. The time now is 03:03 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2015, 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.