Tuesday, October 27, 2009

Invoking AIR Application using Batch File



I am pretty sure if we are using a application which interacts with other application we need to invoke it using command propmt . Here is a simple way to invoke the application ..Also while invoking sometime we need to pass variables to the application as we do in flash vars..

First of all we need to set the environment variable for accessing the flex sdk in the system.. Add the following path to the sysytem path variable in your environment variable
C:\Program Files\Adobe\Flex Builder 3\sdks\3.0.0\bin

Note : It should point to the sdk's bin location in mycase it resided in C:/ Drive .

To Run the application we will use ADL(AIR Debug Launcher) using the following syntax:-
adl [-runtime runtime-directory] [-pubid publisher-id] [-nodebug] application.xml [root-directory] [-- arguments]

In my case i used the following line on my command prompt
F:\PROJECTS\Printing\bin>adl Printing-app.xml -- 321 0 active

First i reach to the point where my application bin folder reside(having compiled swf and application descriptor file) then using adl to invoke my application-app.xml

Note:-
After the application-app.xml i added -- and then i gave three arguments separated my space.

In the application i can get the aruments as follows :-
We listen the following function in the application invoke="onInvoke(event)"

private function onInvoke(e:InvokeEvent):void
{
var arguments : ArrayCollection = new ArrayCollection( e.arguments );
}


Here i get all the arguments in a arraycollection.

Sunday, October 11, 2009

Reading and Writing Browser Cookie in Flex


A browser cookie is a small piece of information sent by a web server to a web browser to be stored for future use. The data in the browser cookie will be sent back to the web server whenever the browser reconnects to the web site.

Cookies are commonly used to store user preference information, such as web site options. Cookies are also used to store shopping cart contents. The most security-relevant use of browser cookies is when they are used to store authentication data, such as user names and passwords.

To Read and write Cookie from a flex application we will use Javascript


//Following function will set the cookie in the user browser
function setCookie(c_name,value,expiredays)
{

value = document.getElementById('user').value;
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
}




//Following function will return Cookie
function getCookie(c_name){

if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1 ;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end));
}
}

return "";
}

For reading a cookie Visitor we will use the following line in Flex code:-
var visitorId : String = ExternalInterface.call("getCookie","Visitor");


Cheers
Varun

About Me