How to create a PDF of my web application using AlivePdf - apache-flex

I have a large web application with verticalScrollBar with few charts and large datagrid. I am planning to create pdf of my web application using AlivePdf.
Right now, Im using below code to creat a pdf of my application, but no luck.
var printView:DisplayObject = new InteractionsAnalysis() as DisplayObject;
printView.width = Application.application.width;
printView.height = Application.application.height;
var printPDF:PDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4);
printPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );
printPDF.addPage();
printPDF.addImage(printView,0,0,0,0,"PNG",100,1,ResizeMode.FIT_TO_PAGE);
var f:FileReference = new FileReference();
var b:ByteArray = printPDF.save(Method.LOCAL);
f.save(b);
Can anybody give me some directions?

Verify that the method which is calling f.save() was triggered due from a user event. According to the FileReference doc:
In Flash Player, you can only call
this method successfully in response
to a user event (for example, in an
event handler for a mouse click or
keypress event). Otherwise, calling
this method results in Flash Player
throwing an Error exception. This
limitation does not apply to AIR
content in the application sandbox.

Related

Sending POST variables to a browser window from AIR application

I'm building an AIR application. Basically, what I'm looking to do is using navigateToUrl() to open a browser window, assign it a "name" and then, send variables to that newly opened window using the POST method.
EDIT : I need the window to be visible, this is why I absolutely need to use the navigateToUrl() function
I already know that I CAN'T DO something like this, that the AIR application will send the variables using the GET method...
var vars:URLVariables = new URLVariables();
vars.myVar = "Hello my friend";
var req:URLRequest = new URLRequest("http://example.com/my-page.php");
req.method = "POST":
req.data = vars;
navigateToURL(req);
Considering the amount of variables I have to send (multiline texts) I absolutely need to send my variables using the POST method else Internet Explorer is truncating the query string... Works fine in Firefox and Safari but unfortunately, we will always have (hope not!) to deal with IE..
So I was thinking something like this :
import flash.net.navigateToURL;
private var _timer:Timer;
protected function loadPage():void
{
var req:URLRequest = new URLRequest("http://example.com/my-page.php");
navigateToURL(req, "myPageName");
_timer = new Timer(3000, 1);
_timer.addEventListener(TimerEvent.TIMER, postVars);
_timer.start();
}
protected function postVars(event:TimerEvent):void
{
// I'm looking to send variables using the POST method to "myPageName"
// and possibly using URLVariables()??
_timer.stop();
}
Any idea Flex coders? THANKS!
I think what you're going to need to do is open up a page you have control over, then use ExternalInterface to inject the values into a hidden form and then execute the post operation in that page form.submit(), etc.
This can happen almost instantly and it will all appear very seamless to the end user.

adding dynamic message at end of flash video

I am working on a Flash training video. I would like at the end of the video for a message to pop up with a dynamic confirmation code. I have the code for the confirmation code, but am having trouble creating something either at the end of the flash video or within the aspx page to trigger this message. Any thoughts or ideas of how to solve this would be greatly appreciated.
Thank You.
Depend on the purpose of the application, you can do either one. One thing to consider is does the user has to go through the flash video to obtain the code. If so, you need to organize the flow of the application in a way that the user can't cheat their way to obtain the code.
The ideal way is to have the flash called aspx page at the end of the movie to obtain the dynamic code. This can be done using URLLoader in ActionScript 3.0 or LoadVars in ActionScript 2.0.
URLLoader example
//this is the data
var data = "This is data";
//url of your aspx code
var request:URLRequest = new URLRequest("http://www.yourdomain.com/GenerateCode.aspx");
request.contentType = "text/xml";
request.data = data;
//use POST method
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
try
{
//execute the request
loader.load(request);
}
catch (error:ArgumentError)
{
trace("There is an ArgumentError.");
}
LoadVars example:
//create LoadVars object
var lv_in:LoadVars = new LoadVars();
var lv_out:LoadVars = new LoadVars();
//set onLoad event
lv_in.onLoad = function(success:Boolean)
{
//if success, meaning data has received response from .net page, run this code
if (success)
{
//lv_in.status is use to get the posted data from .Net page
statusMsg.text = "Thank you!" + lv_in.status;
}
//if fail, run this code
else
{
statusMsg.text = "Error!";
}
}
//this is the data
lv_out.data = "This is data";
//begin invoke aspx page
lv_out.sendAndLoad("GenerateCode.aspx", lv_in, "POST");
There another easier way but not the best practice i should say. The easier way would be to direct user to aspx page that generate dynamic code after users finish the flash movie. The negative side is, the page can be accessed although users did not finish the flash movie.

how can build a txt document and write in flex application?

how can build a txt document and write in flex application ?
// in an init type method
var fileRef:FileReference = new FileReference();
var text:String = "Some text I want to save";
// continue building the text String variable as desired
// in some method that responds to a user event (NOT a system event):
fileRef.save(text, "defaultFileName.txt");
This may require that the user has Flash Player 10.

Web Application Architecture (ASP.NET 3.5,JavaScript)

hey all ,
background -
I'm using an activx that allow me to access some information on the client side,
By using the activex events and callback i'm updating server side from client.
i wrote a user control that register all activex's events so when one of the events occuer there is a callback to the server that handle this event.
I need to write some other user controls based on this control so on every callback this user controls will be render on the client side.
My question is -
what is the best way to make a shared infrastructure that handle this events and render the right content base on user controls?
is there any other ways i can use ?
thanks!
hey! thanks for your fast reply,
first of all , i'm calling the activex using object tags,
HtmlGenericControl SkypeObject = new HtmlGenericControl("object");
SkypeObject.Attributes.Add("id", "Skype");
SkypeObject.Attributes.Add("codeBase", "http://ip/Skype4COM.dll");
SkypeObject.Attributes.Add("classid", "clsid:830690FC-BF2F-47A6-AC2D-330BCB402664");
SkypeObject.Attributes.Add("name", "Skype");
write callback :
string SkypeAsyncCallbackOnEvent = ClientScript.GetCallbackEventReference(this, "values", ClientScriptName, "context", true);
string SkypeCallbackFunction = "\n<script>\n";
SkypeCallbackFunction += "function SkypeCallback(values,context) {\n";
SkypeCallbackFunction += SkypeAsyncCallbackOnEvent + "\n}\n";
SkypeCallbackFunction += "</script>";
then i register the active'x events :
string SkypeOnUserStatusChange = "\n<script for=\"Skype\" event=\"UserStatus(Status)\">\n";
SkypeOnUserStatusChange += "var values = {\"StatusInfo\" : Status};\n";
SkypeOnUserStatusChange += "var myArray = {\"key\" : \"Status\", \"values\" : values};\n";
SkypeOnUserStatusChange += "var s=JSON.stringify(myArray);";
SkypeOnUserStatusChange += "SkypeCallback(s,null);\n";
SkypeOnUserStatusChange += "</script>";
this is my base user control (in short) so on each events callback is occur.
(this can be change to any class it doesnt metter right now)
now i want to create custom controls that will show the data back from the client.
in my opinion, i can change the call back reference client script to the one that exist in the Child Control and register the child control to the events of the base control.
what do you think ?
thanks :)
A little more info on your project would be helpful, but I think you would be well served using two approaches, one to handle the logic/events... and one to actually handle the visual updates - with some glue in the middle to make it all work like a charm.
First, the events. I could envision some sort of javascript class that registers with your activex control and binds methods to the various event handlers. This class would also expose methods you could bind functions to that would provide callbacks to your display logic.
Second, I would recommend using a library like jQuery to help with the heavy lifting of modifying the user page.
function eventTrap() {}
eventTrap.prototype.hookActiveX() { // your code to attach to your activex object }
eventTrap.prototype.register(event, callback) { // code to register for an event and callback }
// actually use it...
var trapObj = new eventTrap();
trapObj.hookActiveX();
trapObj.register("click", function(){alert('click');});

Passing flash variables to asp.net

I don't know much about Flash but we are working on a site that has a flash form and when the users pick an option, like selecting a value from a drop down list, we need the value to be passed to asp.net server-side code. What's the easiest way to do this?
Flash can invoke server side service. So use GET or POST to pass data
You could explore these options:
1) Communicate between the SWF and the containing page through JavaScript
2) Communicate via asp.net webservices from the SWF directly to the webservice.
3) Not sure but could probably do a POST to a processing aspx page?
HTH
I think a good option is to use the XML class so consider this:
var xmlRequest = new XML();
xmlRequest.onLoad = parseXMLResponse;
xmlRequest.load("http://yourpathtoyourserver/file.aspx?listselectedvalue=something");
function parseXMLRequest(loaded)
{
trace("hi");
}
You can also have the page give you data back this way so it's not just one way communication.
Assuming you are using Action Script 2.
Read the important notes at the bottom of each codes pertain to sending and retrieving data from flash to .net page. Explanation of the code is in the comment inside the code.
Flash Part (Action Script 2)
//function to send collected form data to asp.net page
//use other control/button to call this function
//important: in order for the 'onLoad' event to work correctly, this function has to be 'Void'
function sendForm():Void
{
//create LoadVars object
var lv_in:LoadVars = new LoadVars();
var lv_out:LoadVars = new LoadVars();
//set onLoad event
lv_in.onLoad = function(success:Boolean)
{
//if success, meaning data has received from .net page, run this code
if (success)
{
//lv_in.status is use to get the posted data from .Net page
statusMsg.text = "Thank you for filling up the form!" + lv_in.status;
}
//if fail, run this code
else
{
statusMsg.text = "The form you are trying to fill up has an error!";
}
}
//this is the collected data from the form
lv_out.userName = txtUserName.text;
lv_out.userAddress = txtUserAddress.text;
lv_out.userBirthday = txtUserBirthday.text;
//begin invoke .net page
lv_out.sendAndLoad("ProcessDataForm.aspx", lv_in, "POST");
}
Important note:
The function that contain onLoad event, in this case sendForm function, has to be Void function, meaning it's not returning value. If this function return value, what happen is the function will be executed all the way without waiting for the returned data from .net page, thus the onLoad event will not be set properly.
.Net Part
public void ProcessData
{
//process the data here
Response.Write("status=processed&");
}
Important note:
To send data/message back to flash, you can use Response.Write. However, if you want Action Script to parse the posted message/data from .Net page keep in mind you have to include & symbol at the end of the message. When parsing data/message, Action Script will stop at & symbol, thus leave the rest of the message alone and only get the message under sent variable.

Resources