Sunday, February 8, 2009
Setting focus to a UI control
Sunday, December 21, 2008
Global Variables in Flex Apps
import mx.core.Application
Step 2: Declare the variable in the main application (in our case it should be Indemand_Video.mxml)
public var gVariable:String = "gVariable";
Step 3: Use the variable "gVariable" anywhere in the application as follows
Application.application.gVariable
I ran a test to access this global variable in chat.mxml. It worked fine.
I think we can use the same application object to access any public function in the Indemand_Video.mxml main application.. Is it strinking any bells ?
Update:
1) I created public alertTest():void function in indemand_video.mxml.
2) called the function in chat.mxml as Application.application.alertTest();
Bingo it worked.....
Friday, November 28, 2008
AIR - Call a method of different application and pass variable
I have created a function called changeItem() in ParentWindow. Since the function is triggered by an event, it should have a variable of type Event.
The code of the changeItem() is
public function changeItem(event:Event,inItem:String):void
{
/* variable inItem is passed by the ChildWindow */
txtSelectedItem.text=inItem;
}
(To create and call a window please see multiple windows in AIR )
Pass the application as a parameter.
When creating the instance of the ChildWindow in the ParentWindow, declare a variable of type ParentWindow and initialize to "this" i.e current application. The code is given here
declare variable
private var thisInstance:ParentWindow;
calling the ChildWindow
/*newChildWindow is of type ChildWindow*/
newChildWindow=new ChildWindow();
/* intialize the variable thisInstance in init() function if you are referring the intansce in multiple places*/
thisInstance=this;
newChildWindow.parentWindowInstance=thisInstance;
newChildWindow.open();
In the ChildWindow (select item window), add a listener to the select button/component and call the function of the Parent window (changeItem).
add event listener function
cmd.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void
{
/* parentWindowInstance variable is the instance of the ParentWindow and it is initialized by the ParentWindow when the instance of the ChildWindow is created
parentWindowInstance is declared in ChildWindow <Script> section */
parentWindowInstance.changeItem(e,pTxtInput.text);
}
here, a function is declared in the parameter place. This declaration acts as parameter passing trick.
Multiple window in AIR application
This piece of code gives a brief idea of how to work with multiple window. Invoking an application(mxml) from other applications(mxml).This piece is different from pop up window. Pop up window is a pre-defined class while creating a window application is user defined application.
In this example, I am calling ChildWindow.mxml from ParentWindow.mxml.
Call child Window
ParentWindow
in "<mx:Script>"
Declare the intance of the child
private var newChild:ChildWindow;
initialize the instance
newChild= new ChildWindow();
to open the window
newChild.open();
ChildWindow
ChildWindow should be of Window component type (
declare the variable in the ChildWindow. When creating the instance, initialize the variable from the mainwindow. For example, to pass the value "yaazh" to the variable "name" of the child window, the code is given below
in ChildWindow
declare variable name in "<Script>"
in ParentWindow when creating intance of the ChildWindow, assign the value to the variable of the ChildWindow instance.
newChild= new ChildWindow();
newChild.name="yaazh";
newChild.open();
this will work :-)
Tuesday, November 25, 2008
Get IPAddress into Flash
MXML CODE:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
- <mx:Button label="Get IP" click="dir.send()" x="258" y="238"/>
- <mx:TextInput text="Ip:{dir.lastResult.ip}" x="210" y="208"/>
- </mx:Application>
PHP CODE:
- <?php
- $REMOTE_ADDR;
- if ($REMOTE_ADDR)
- {
- $message = "<result><ip>$REMOTE_ADDR</ip></result>";
- }
- else
- {
- $message = "<result><ip>No Ip or any message.</ip></result>";
- }
- echo $message;
- ?>
Detecting Display Settings: Use the screenResolutionX and screenResolutionY properties of the system.capabilities object.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
trace(flash.system.Capabilities.screenResolutionX);
trace(flash.system.Capabilities.screenResolutionY);
}
}
}
प्रेम watch out, this might be userful to us in detecting the video resolution & laying out accordingly.import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
trace(flash.system.Capabilities.screenResolutionX);
trace(flash.system.Capabilities.screenResolutionY);
}
}
}
more useful samples like this can be found here - http://www.java2s.com/Code/Flash-Flex-ActionScript/CatalogFlash-Flex-ActionScript.htm
Monday, November 24, 2008
Amazon AWS - Remote Desktop (RDP) max users connected error
Use this whenever this happens next time
mstsc /v:75.xxx.yyy.99 /admin
replace the ip for the corresponding server (ip address masked for security)
Thanks to Sandy boy for giving this tip