Flex: SendPDFAttachment.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#F1F5F9" 
	width="300" height="350" creationComplete="SavePDFMain()" layout="vertical">
	<mx:Script>
		<![CDATA[
		import flash.display.Sprite;
		import flash.display.MovieClip;
		import flash.display.Loader;
		import flash.events.Event;
		import com.flashscriptMVC.AbstractClass;
		import com.flashscriptMVC.IModel;
		import com.flashscriptMVC.Model;
		import com.flashscriptMVC.Controller;
		import com.flashscriptMVC.views.SavePDFView;
		import com.flashscriptMVC.IControlHandler;
		import biz.Flashscript.utils.TextLoader;
		import mx.controls.Alert;
		//
		private static var xmlData:XML;

/*
* SavePDFView is the viewer class from the Flash lbrary, which we also need 
* to change for Flex use.
*/

		public var savePDF:SavePDFView;
		public function SavePDFMain ():void
		{
			var dataFile:String = "xml_files/docclass.xml";
			var myLoader:TextLoader = new TextLoader  ;
			myLoader.initText (dataFile,xmlHandler);
		}

/*
* This function is triggered when the XML file is loaded.
*/

		private function xmlHandler (e:Event,a:String,b:Number,c:Boolean):void
		{
			xmlData = new XML(e.currentTarget.data);

/*
* We create the instances of the model and controller to initiate the 
* viewer instance object here and pass xml data to the model class, 
* which the viewer can then retrieve from the Model class. The viewer
* class has getter and setter methods, which we use to pass parameters.
*/

			var model:IModel = new Model(xmlData.savepdf);
			var controller:IControlHandler = new Controller(model);
			savePDF = new SavePDFView (model,controller);
			savePDF.setTextField(message);
			savePDF.setMyPDF(makeItPDF);

/*
* We need to add eventlisteners for individual responses  from the model class
* to the savePDF viewer object.
*/

			model.addEventListener ("viewWindow", savePDF.update);
			model.addEventListener ("serverResponse", savePDF.update);
		}

/*
* This function is triggered when the button is pressed. We update parameter
* values and from now on everything is done by the classes behind the scene.
*/

		private function generatePDF( event:MouseEvent ):void
		{
			if(myEmail.text == "")
			{
				Alert.show("Enter a valid email address!");
				return;
			}
			savePDF.setemail(myEmail.text);
			savePDF.setMyPDF(makeItPDF);
			savePDF.sendPDF();
		}
		]]>
	</mx:Script>

/*
* These are the Flex objects and methods.
*/

	<mx:HBox>
		<mx:Label color="#000000" text="Enter Email"/>
		<mx:TextInput id="myEmail" width="135"/>
	</mx:HBox>
	<mx:Panel width="220" height="190" title="Kitty-Jane">
		<mx:Image id="makeItPDF" />
	</mx:Panel>
	<mx:HBox>
		<mx:Button id="submitBut" label="Save PDF" click="generatePDF ( event )"/>
		<mx:TextInput id="message" editable="false" color="#FFFFFF" backgroundColor="#000000" 
			borderColor="#000000" width="135"/>
	</mx:HBox>
</mx:Application>