Hi, I can't seem to get my flash site to communicate with one of the private folders on the web server it is hosted on. I am trying to use PHP to fetch an XML file from the folder and make it available to flash. I have scripting enabled on the server and I have verified the scripting path to use. The page loads all content but says it is still waiting to access the server when trying to load in the XML file.
The AS3 code is:
ActionScript Code:
package com.net.php
{
import flash.events.*;
import flash.net.*;
public class PHPExtLoader extends EventDispatcher
{
public var phpFile:String;
public var remoteFile:String;
public var req:URLRequest;
private var vars:URLVariables = new URLVariables();
private var loader:URLLoader = new URLLoader();
public var data:String;
public function PHPExtLoader()
{
}
public function load(php:String, remote:String):void
{
phpFile = php;
remoteFile = remote;
req = new URLRequest(phpFile);
vars.fileName = remoteFile;
req.data = vars;
req.method = URLRequestMethod.POST;
loader.addEventListener(Event.COMPLETE, contentLoaded);
loader.load(req);
}
private function contentLoaded(event:Event):void
{
data = loader.data;
dispatchEvent(new Event(Event.COMPLETE));
}
}
}
The PHP code is:
PHP Code:
<?php
$file = $_POST['fileName'];
echo file_get_contents($file);
?>
I don't know if it is a problem but the calling swf has been loaded by another using the following class to make sure that the parent swf can access the child swf methods:
ActionScript Code:
/*
::DESCRIPTION::
This will load in a SWF and allow it to be accessed through the getPage method in a state where its functions can be accessed by an external caller. It can be unloaded via the unloadPage method. The _currentProgress variable wil return the current percentage of bytes loaded.
*/
package net
{
import flash.events.*;
import flash.display.*;
import flash.net.*;
public class PageLoader extends Loader
{
//::::::::::::VARS:::::::::::
//*********************CONNECTION/LOADING VARS**********************
public var _page:DisplayObject;
public var _currentProgress:Number = 0;
private var _pageURL:String;
private var _pageLoader:Loader;
private var _loaderInfo:LoaderInfo;
//::::::::::::PROGRAM:::::::::::
public function PageLoader(PAGESWF:String)
{
_pageURL = PAGESWF;
_pageLoader = new Loader();
}
public function loadPage():void
{
_pageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, setProg);
_pageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, pageLoaded);
_pageLoader.load(new URLRequest(_pageURL));
}
private function pageLoaded(event:Event):void
{
_pageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, pageLoaded);
_loaderInfo = event.target as LoaderInfo;
this.dispatchEvent(new Event(Event.COMPLETE));
}
private function setProg(event:ProgressEvent):void
{
_currentProgress = (event.bytesLoaded / event.bytesTotal);
if(event.bytesLoaded == event.bytesTotal)
{
_pageLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, setProg);
}
}
public function getPage():*
{
return _loaderInfo;
}
public function pageUnload():void
{
_pageLoader.unload();
}
}
}
Any help would be really appreciated!! Thanks,
James