• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Php TO Flash

Explorer ,
Dec 21, 2011 Dec 21, 2011

Copy link to clipboard

Copied

I'm sure that I just haven't come across the right article yet, but I can't seem to find a decent tutorial addressing sending a PHP variable to Flash. I definitely have looked, but haven't come up with a working solution. In my PHP file, I declare a variable with content from a MySql database. I know for sure that going from the database to PHP works, but I'm not sure how to reach that variable and display it in Flash. Right now, here is my code:

var loader:URLLoader = new URLLoader();

loader.dataFormat = URLLoaderDataFormat.VARIABLES;

loader.addEventListener(Event.COMPLETE, varsLoaded);

loader.load(new URLRequest("reciever.php"));

var varToAppend:String = "";

function varsLoaded(e:Event):void

{

varToAppend = e.target.data.all_content.toString();

all_txt.text = String(varToAppend);

}

all_content is my variable I'm trying to reach. But when I run my program, it comes up with this error:

TypeError: Error #1010: A term is undefined and has no properties.

at Base_fla::MainTimeline/varsLoaded()

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at flash.net::URLLoader/onComplete()

This is the line it does not like:

varToAppend = e.target.data.all_content.toString();

When I take out the .toString(); it shows null. Does any one have any suggestions with more productive code?

Thank you, Alex.

TOPICS
ActionScript

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 22, 2011 Dec 22, 2011

Copy link to clipboard

Copied

Do a trace to see what you get:

function varsLoaded(e:Event):void {

   trace(e.target.data);

}

--

Kenneth Kawamoto

http://www.materiaprima.co.uk/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2011 Dec 22, 2011

Copy link to clipboard

Copied

Thank you for the reply. I am assuming you wanted to do this locally? Well, I did, and it gave me:

%3C%3Fphp%20require%5Fonce%28%27%2E%2E%2FConnections%2FFlashCon%2Ephp%27%29%3B%20%3F%3E%0D%0A%3C%3Fphp%0D%0Aif%20%28%21function%5Fexists%28%22GetSQLValueString%22%29%29%20%7B%0D%0Afunction%20GetSQLValueString%28%24theValue%2C%20%24theType%2C%20%24theDefinedValue%20=%20%22%22%2C%20%24theNotDefinedValue%20%3D%20%22%22%29%20%0D%0A%7B%0D%0A%20%20if%20%28PHP%5FVERSION%20%3C%206%29%20%7B%0D%0A%20%20%20%20%24theValue%20%3D%20get%5Fmagic%5Fquotes%5Fgpc%28%29%20%3F%20stripslashes%28%24theValue%29%20%3A%20%24theValue%3B%0D%0A%20%20%7D%0D%0A%0D%0A%20%20%24theValue%20%3D%20function%5Fexists%28%22mysql%5Freal%5Fescape%5Fstring%22%29%20%3F%20mysql%5Freal%5Fescape%5Fstring%28%24theValue%29%20%3A%20mysql%5Fescape%5Fstring%28%24theValue%29%3B%0D%0A%0D%0A%20%20switch%20%28%24theType%29%20%7B%0D%0A%20%20%20%20case%20%22text%22%3A%0D%0A%20%20%20%20%20%20%24theValue%20%3D%20%28%24theValue%20%21%3D%20%22%22%29%20%3F%20%22%27%22%20%2E%20%24theValue%20%2E%20%22%27%22%20%3A%20%22NULL%22%3B%0D%0A%20%20%20%20%20%20break%3B%20%20%20%20%0D%0A%20%20%20%20case%20%22long%22%3A%0D%0A%20%20%20%20case%20%22int%22%3A%0D%0A%20%20%20%20%20%20%24theValue%20%3D%20%28%24theValue%20%21%3D%20%22%22%29%20%3F%20intval%28%24theValue%29%20%3A%20%22NULL%22%3B%0D%0A%20%20%20%20%20%20break%3B%0D%0A%20%20%20%20case%20%22double%22%3A%0D%0A%20%20%20%20%20%20%24theValue%20%3D%20%28%24theValue%20%21%3D%20%22%22%29%20%3F%20doubleval%28%24theValue%29%20%3A%20%22NULL%22%3B%0D%0A%20%20%20%20%20%20break%3B%0D%0A%20%20%20%20case%20%22date%22%3A%0D%0A%20%20%20%20%20%20%24theValue%20%3D%20%28%24theValue%20%21%3D%20%22%22%29%20%3F%20%22%27%22%20%2E%20%24theValue%20%2E%20%22%27%22%20%3A%20%22NULL%22%3B%0D%0A%20%20%20%20%20%20break%3B%0D%0A%20%20%20%20case%20%22defined%22%3A%0D%0A%20%20%20%20%20%20%24theValue%20%3D%20%28%24theValue%20%21%3D%20%22%22%29%20%3F%20%24theDefinedValue%20%3A%20%24theNotDefinedValue%3B%0D%0A%20%20%20%20%20%20break%3B%0D%0A%20%20%7D%0D%0A%20%20return%20%24theValue%3B%0D%0A%7D%0D%0A%7D%0D%0A%0D%0Amysql%5Fselect%5Fdb%28%24database%5FFlashCon%2C%20%24FlashCon%29%3B%0D%0A%24query%5FFlash%20%3D%20%22SELECT%20%2A%20FROM%20messages%22%3B%0D%0A%24Flash%20%3D%20mysql%5Fquery%28%24query%5FFlash%2C%20%24FlashCon%29%20or%20die%28mysql%5Ferror%28%29%29%3B%0D%0A%0D%0Awhile%28%24row%5FFlash%20%3D%20mysql%5Ffetch%5Farray%28%24Flash%29%29%0D%0A%7B%0D%0A%24all%5FContent%20%3D%20%24row%5FFlash%5B%27fullName%27%5D%20%2E%20%22%2D%2D%2D%2D%2D%22%20%2E%20%24row%5FFlash%5B%27email%27%5D%20%2E%20%22%2D%2D%2D%2D%2D%22%20%2E%20%24row%5FFlash%5B%27message%27%5D%20%2E%20%22%3Cbr%20%2F%3E%22%3B%0D%0A%7D%0D%0A%0D%0A%2F%2Fmysql%5Ffree%5Fresult%28%24Flash%29%3B%0D%0A%3F%3E

Any new instruction, can I decode this?

Thank you, Alex

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2011 Dec 22, 2011

Copy link to clipboard

Copied

So I think I might have gotten part of this, here:

var loader:URLLoader = new URLLoader();

loader.dataFormat = URLLoaderDataFormat.VARIABLES;

loader.addEventListener(Event.COMPLETE, varsLoaded);

loader.load(new URLRequest("reciever.php"));

function varsLoaded(e:Event):void

{

var i:int = 0;

while (i < loader.data.all_Content.length)

{

  all_txt.text.concat(loader.data.all_Content + "\n");

}

}

Any one know any other way to get info from PHP?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 23, 2011 Dec 23, 2011

Copy link to clipboard

Copied

You should output your PHP to an XML file. To import the XML (AS3!) there is an Flash code example from Flash itself however there was a error in that code (may have been corrected in the meantime) there used to be  a comment in which the code was corrected.

I explored that 2 years ago and it works. In one of his books David Powers I believe explains the output to XML. If you have got that working you can import the XML in your Flash (AS3) file. There is a book called XML and E4X for Flash and Flex which describes all kinds of ways to get your XML data into Flash.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 24, 2011 Dec 24, 2011

Copy link to clipboard

Copied

LATEST

Ha! In the mean time, while I was waiting for a reply, I did that! I actually got the database into XML and went from there! Great minds think alike( Although its been thought up before)

Thank you, Alex

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines