im developing a simple Mxml application using flex 3. I have used simple text and combo box.
combobox contains items left right up and down while i click each element in combo box the scrolling text will scroll in selected direction it is working fine.
my question is how i can modify this application by pressing key board Arrow keys up, down, right and left. instead of using combobox elements??
my application code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Script>
<![CDATA[
public var mytimer:Timer=new Timer(10);
[Bindable]public var arr:Array=new Array("upScroll","LeftScroll","right","down");
private function initApp():void
{
mytimer.start();
mytimer.addEventListener(TimerEvent.TIMER,scrollme);
}
private function scrollme(event:TimerEvent):void
{
if(cmb.selectedLabel=="LeftScroll")
{
if(mytext.x==0)
mytext.x=this.width-mytext.width;
mytext.x--;
}
if(cmb.selectedLabel=="upScroll")
{
if(mytext.y==0)
mytext.y=600;
mytext.y--;
}
if(cmb.selectedLabel=="right")
{
if(mytext.x==this.width-mytext.width)
mytext.x=0;
mytext.x++;
}
if(cmb.selectedLabel=="down")
{
if(mytext.y==600)
mytext.y=0;
mytext.y++;
}
}
]]>
</mx:Script>
<mx:Text id="mytext" text="SCROLLING" fontSize="16" fontStyle="italic" fontWeight="bold"/>
<mx:ComboBox dataProvider="{arr}" prompt="Select" id="cmb" change="initApp()"/>
</mx:Application>
You can subscribe to Keyboard events of an Application: