Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

php output xml for flash problem

This is a discussion on php output xml for flash problem within the Flash CS3 | PHP | mySQL forums, part of the Flash CS3 generale category; hi i`m not sure if i`m in the right plcae but i`m desparate:) i have a php ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 e Actionscript 3.0 > Flash CS3 generale > Flash CS3 | PHP | mySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 04-02-08, 12:27
Junior Member
 
Join Date: Jul 2007
Posts: 9
Rep Power: 0
derrida is on a distinguished road
php output xml for flash problem

hi

i`m not sure if i`m in the right plcae but i`m desparate:)

i have a php file that takes the data from a database and convert it as xml, because the new abilities to work with xml in flash are great (no more disfunctional families issues:).
when i output the php file to the browser i get the xml i needed.

but when i try to load this php file in flash ,i do not get the xml.

if i take copy the xml the pgp outputed and load it as xml file it works, but obviously that goes against making things dynamic.

this is the php file:


$host= "localhost";
$db="";
$username="";
$pass="";

$link=mysql_connect($host,$username,$pass) or die(mysql_error());
mysql_select_db($db);

$q="SELECT * FROM contacts";
$r=mysql_query($q);
$row=mysql_fetch_assoc($r);
$total_rows=mysql_num_rows($r);

//headers
header('Content-type:text/xml');
header('Cache-control:private');
header('Expires:-1');


?>
'); ?>

0) { // Show if recordset not empty ?>


$value) { ?>
<>

>







and this is the flash AS3 code:

import fl.data.DataProvider;


var addRequest:URLRequest= new URLRequest("addBookToXML2.php");
var addLoader:URLLoader= new URLLoader(addRequest);

var addXML:XML= new XML();
addXML.ignoreWhitespace=true;

addLoader.addEventListener(Event.COMPLETE,doGrid);

function doGrid (evt:Event):void {
//trace(evt.target.data);
//trace (addXML.person.firstName.text());
addXML = XML(evt.target.data);
var myDP:DataProvider = new DataProvider(addXML);
aDg.dataProvider= myDP;
aDg.setSize(600,200);
aDg.columns= ["firstName","lastName","phoneNum","email"];
aDg.columns[0].width= 80;
aDg.columns[1].width= 80;
aDg.columns[2].sortable=false;
aDg.columns[3].sortable=false;
aDg.editable=true;
aDg.move(80,50);

}

add_btn.addEventListener(MouseEvent.CLICK, addIt);
delete_btn.addEventListener(MouseEvent.CLICK, deleteIt);
update_btn.addEventListener(MouseEvent.CLICK, updateIt);

aDg.addEventListener(Event.CHANGE, takeChange);

function takeChange (evt:Event):void {
//trace(evt.target.selectedIndex);
//addXML.update();
}


function addIt (evt:MouseEvent):void {
//trace("selectedIndex is: " +aDg.selectedIndex) ;

}

function deleteIt (evt:MouseEvent):void {
aDg.removeItemAt(aDg.selectedIndex);


}

function updateIt (evt:MouseEvent):void {
//trace (aDg.selectedIndex);
}


i hope someone can help me with it.

best regards

ron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 04-02-08, 12:46
tem's Avatar
tem tem is offline
Moderator
 
Join Date: Jan 1970
Posts: 488
Rep Power: 39
tem is on a distinguished road
Re: php output xml for flash problem

Hi !

Flep has written this explaination code about it:

xml here:

Interpretare i dati di un file XML esterno con Flash CS3


As
Code:
var my_xml:XMLDocument=new XMLDocument();
var loader:URLLoader=new URLLoader();
var request:URLRequest=new URLRequest('images.xml');

loader.addEventListener(Event.COMPLETE,onComplete);
loader.load(request);

function onComplete(evt:Event):void
{
	var result:XML=new XML(evt.target.data);
	my_xml.ignoreWhite=true;
	my_xml.parseXML(result.toXMLString());
	trace(my_xml);
	
	var node:XMLNode=my_xml;
	var totalNodes:int=node.firstChild.childNodes.length;
	trace('total number of nodes: '+totalNodes);
	
	for(var i:int=0;i < totalNodes;i++)
	{
		var nodeValue:String=node.firstChild.childNodes[i].firstChild.nodeValue;
		var idAttribute:int=int(node.firstChild.childNodes[i].attributes['id']);
		var imageURL:String=node.firstChild.childNodes[i].attributes['url'];
		
		trace('--------------------------------------------------------------------------------------------');
		trace('the value of the node n° '+i+' is '+nodeValue);
		trace("the value of the attribute id of the node n° "+i+' is '+idAttribute);
		trace("the value of the attribute url of the node n° "+i+' is '+imageURL);
	}
}
__________________
http://www.thetconcept.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #3 (permalink)  
Old 04-02-08, 13:02
Junior Member
 
Join Date: Jul 2007
Posts: 9
Rep Power: 0
derrida is on a distinguished road
Re: php output xml for flash problem

hi
thanks for the answer, but the post there is not in english so i cannot read it.
is there any english explanation to the code?

because i thought that once i use:addXML = XML(evt.target.data);

it "turned" the incoming data into xml. well as if i wrote the xml inside flash.
ron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #4 (permalink)  
Old 04-02-08, 17:14
tem's Avatar
tem tem is offline
Moderator
 
Join Date: Jan 1970
Posts: 488
Rep Power: 39
tem is on a distinguished road
Re: php output xml for flash problem

sorry I just understood what you wanted to do..

I have never tryed this way..
what I usually do is:
call the php script;
the php writes an Xml with the data and sends back a confirmation to flash;
when flash receives the confirmation it goes on and loads the Xml just created...

in the post in italian you can find the structure of the xml required for the code I've posted (but now i don't know if u need that! it's just about loading xml data nodes & values)
__________________
http://www.thetconcept.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #5 (permalink)  
Old 05-02-08, 11:50
Junior Member
 
Join Date: Jul 2007
Posts: 9
Rep Power: 0
derrida is on a distinguished road
Re: php output xml for flash problem

hi
thanks for your attention.

my problem is that all is working but the "link" between flash and the php\xml.

my php code does output the right xml structure.
my as3 code can take and deal with the xml that is loaded.
but flash loades and deal with the xml only if it loads a static xml file - "names.xml".
it does not take the php file that output an xml : "names.php".
even though the php file does output an xml in the browser.


ron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Flash Multi Gallery
  #6 (permalink)  
Old 05-02-08, 12:11
tem's Avatar
tem tem is offline
Moderator
 
Join Date: Jan 1970
Posts: 488
Rep Power: 39
tem is on a distinguished road
Re: php output xml for flash problem

Hi,
I've never tryed to get directly the xml output from php..
my suggestion is to work with the static Xml.. in this way:

from flash before loading the Xml you call the php that generates it .. so everytime you have a new xml.. when flash receives the confirmation from the php that the file is created .. you can go on loading the new Xml like that:

Code:
var url='my_xml.xml?cachebuster='+new Date().getTime();
the code is for not charging the file from the cache .. so everytime you get the Xml just created


this is an example from Flep's Email form.. it does something similar to what I've described
Code:
                private function inviaDati():void
		{
                        //in this case we send to the php some variables
			var variables:URLVariables=new URLVariables();
			variables.email=email_txt.text;
			variables.messaggio=message_txt.text;
			variables.titolo=title_txt.text;
			variables.nome=name_txt.text;
			var richiesta:URLRequest=new URLRequest();
			//richiesta means request.. so our request is made to that file
			richiesta.url='http://www.flepstudio.org/utilita/emailForm/inviaMail.php';
			richiesta.method=URLRequestMethod.POST;
			richiesta.data=variables;
			var loader:URLLoader=new URLLoader();
			loader.dataFormat=URLLoaderDataFormat.VARIABLES;
			addListeners(loader);
			try 
			{
				loader.load(richiesta);
			} 
			catch (error:Error) 
			{
				trace('Unable to load richiestaed document.');
			}
		}
		
		private function addListeners(d:IEventDispatcher):void
		{
			d.addEventListener(Event.OPEN,inizio);
			d.addEventListener(ProgressEvent.PROGRESS,inProgresso);
			d.addEventListener(Event.COMPLETE,completato);
			d.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
			d.addEventListener(HTTPStatusEvent.HTTP_STATUS,httpStatus);
			d.addEventListener(IOErrorEvent.IO_ERROR,ioError);
		}
		
		private function inizio(e:Event):void 
		{
			debug_txt.text='Invio messaggio in corso...';
		}
		
		private function inProgresso(e:ProgressEvent):void 
		{
			debug_txt.text='Invio messaggio in corso...';
		}
		
                //this is where it checks the answer from the php
		private function completato(e:Event):void
		{
			var loader:URLLoader=URLLoader(e.target);
			var vars:URLVariables=new URLVariables(loader.data);
                         //here if you get the echo from php you can go on loading the xml..
			if(vars.answer=='ok')
				debug_txt.text='The message has been correctly sent';
			else
				debug_txt.text='System error, please try again';
			togliAlert();
		}
		
		private function securityError(e:SecurityErrorEvent):void 
		{
			debug_txt.text='Errore di sistema, ripova per favore';
		}
		
		private function httpStatus(e:HTTPStatusEvent):void {}
		
		private function ioError(e:IOErrorEvent):void 
		{
			debug_txt.text='Errore di sistema, ripova per favore';
		}
__________________
http://www.thetconcept.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #7 (permalink)  
Old 31-07-08, 01:40
Junior Member
 
Join Date: Jul 2008
Posts: 1
Rep Power: 0
drcode is on a distinguished road
Re: php output xml for flash problem

Check to see what your loader is actually loading by doing a trace:

trace (loader.data);

You're calling the .php file relatively, so you will probably see that youre loading the php code, not the output. To get the file to execute, call it with a full url:

var addRequest:URLRequest= new URLRequest("http://www.myserver.com/addBookToXML2.php");


Michael
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Actionscript 3 il Trace non produce output AmiFlash Actionscript 3.0 base 4 11-11-08 22:52
Creare un output HTML con Flash CS3 Flep Articoli e tutorials 9 28-10-08 14:36
Flash PHP output.appendText su Login As3+Php lambertocudia Flash CS3 | PHP | mySQL 2 25-09-08 11:38
Creating HTML output with Flash CS3 Flep Tutorials 1 31-07-08 09:32
problem with javascript and flash cs3 alexyz4 Flash CS3 eng 8 11-10-07 14:21


All times are GMT. The time now is 19:44.


Powered by vBulletin versione 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406