LoadData

Package:
Class:
Inheritance:
biz.flashscript.utils
public class LoadData
N/A
The LoadData class allows loading data and allows transferring variables over event listeners. Although these variables are optional they need to be added as function parameters to the function listening to the event (see Example). Use the constructor new LoadData() to create a new LoadData object and add parameters as desired.
Public Methods
Method Defined By
LoadData()
Creates a new instance of the LoadData class.
LoadData
initLoader(myURL:String, loadFinished:Function, myTarget:Object, variables:URLVariables, myProgressBar:ProgressBar=null, aNum:Object=null, bStr:Object=null, cBool:Object=null)
Proceeds with loading data.
LoadData
Constructor Detail
LoadData ()  Constructor
public function LoadData()
Intializes a new LoadData instance with the specified parameters.
Method Detail
initLoader ():void  method
public function initLoader(myURL:String, loadFinished:Function, myTarget:Object, variables:URLVariables, myProgressBar:ProgressBar=null, aNum:Object=null, bStr:Object=null, cBool:Object=null)

Parameters

  • myURL:String ____ The server-side file used to handle the variables.
  • loadFinished:Function ____ The name of the function for the completed event.
  • myTarget:Object ____ The object to dispatch the event to.
  • variables:URLVariables ____ The variables to be transferred to the server.
  • myProgressBar:ProgressBar=null ____ Optional progressbar, which can be added to monitor loading.
  • aNum:Object=null ____ Optional: Any object to be transferred to the loadFinished function.
  • bStr:Object=null ____ Optional: Any object to be transferred to the loadFinished function.
  • cBool:Object=null ____ Optional: Any object to be transferred to the loadFinished function.
Examples
Create a new fla file and name it LoadData.fla. Place the fla in the same folder as the biz folder. Add a TextField and name it "myText". Place a button component on the timeline and name it submitBut. Then create an Actionscript file, name it Loaddata.as and place this script. Test the file on the server or where php files are processed and upload also a php file named "simple.php".

package 
{
	import flash.display.Sprite;
	import flash.net.URLVariables;
	import flash.events.Event;
	import biz.flashscript.utils.LoadData;
	import fl.controls.Button;
	import flash.events.MouseEvent;

	public class Loaddata extends Sprite
	{
		public var submitBut:Button;
		
		public function Loaddata ():void
		{
			submitBut.label = "SUBMIT";
			submitBut.addEventListener (MouseEvent.CLICK, clickHandler);
		}
		private function clickHandler (event:MouseEvent):void
		{
			var myLoader:LoadData = new LoadData();
			var myVariables:URLVariables = new URLVariables();
			var myString:String = "passed";
			myVariables.myString = myString;
			var passVar:String = "Hello World";
			myLoader.initLoader ("simple.php",completeHandler,myText,myVariables,passVar);
		}
		private function completeHandler (event:Event, myVar:Object, b:Object, c:Object):void
		{
			myText.appendText("VAR PASSED: "+myVar+"\n");
			myText.appendText ("processed!\nRESULT for myString: "+unescape(event.target.data.myString)+"\n");
			if (event.target.data.result == "Okay")
			{
				var myData:XML = new XML("<data>"+unescape(event.target.data.myString+"</data>"));
				myText.appendText ("Data are stored:" + "    " + event.target.data.myString+"\n");
				myText.appendText ("myData.age:    "+myData.age);
			}
			else
			{
				myText.appendText("Problem returning data!");
			}
		}
	}
}
			
The following php file (simple.php) is an example how to use the LoadData class:

<?php

if ($myString == "passed") 
{
   echo "myString=$myString&result=Okay";
}
else
{
	echo "result=not okay";
}
exit();

?>