Flex ѧϰ±Ê¼£Ö®1 flexµÄʼþ(1)
Adobe Flex 3 Help > Flex Programming Elements > Using Events
Adobe Flex 3 Help
Flex Programming Elements / Using Events
Using events
Using events in Flex is a two-step process. First, you write a function or class method, known as an event listener or event handler, that responds to events. The function often accesses the properties of the Event object or some other settings of the application state. The signature of this function usually includes an argument that specifies the event type being passed in.
The following example shows a simple event listener function that reports when a control triggers the event that it is listening for:
<?xml version="1.0"?>
<!-- events/SimpleEventHandler.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp();">
<mx:Script><![CDATA[
import mx.controls.Alert;
private function initApp():void {
b1.addEventListener(MouseEvent.CLICK, myEventHandler);
}
private function myEventHandler(event:Event):void {
Alert.show("An event occurred.");
}
]]></mx:Script>
<mx:Button id="b1" label="Click Me"/>
</mx:Application>
As you can see in this example, you also register that function or class method with a display list object by using the addEventListener() method.
Most Flex controls simplify listener registration by letting you specify the listener inside the MXML tag. For example, instead of using the addEventListener() method to specify a listener function for the Button control's click event, you specify it in the click attribute of the <mx:Button> tag:
<?xml version="1.0"?>
<!-- events/SimplerEventHandler.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script><![CDATA[
import mx.controls.Alert;
private function myEventHandler(event:Event):void {
Alert.s
Ïà¹ØÎĵµ£º
ÓÉÓÚavm°æ±¾µÄÎÊÌ⣬flex3ÎÞ·¨Ö±½Óµ÷ÓÃflash×öµÄswfÎļþ£¬ÅªÁËÒ»Ì죬×îºóÖÕÓÚÏëµ½ÁËÒ»¸ö°ì·¨£¬½«LocalConnectºÍflexµ÷ÓÃas3Á½ÖÖ·½Ê½ÔÜÔÚÁËÒ»Æð£¬ËãÊÇÔÝʱ°ÑÕâ¸öÎÊÌâ½â¾öÁË£¡
´æÆðÀ´£¬Áô×ÅÒÔºóÐÞ¸Ä
µÚÒ»²½£ºÓÃflash×öÒ»¸öas2µÄÎļþ
ÎÒÔÚÀïÃæÌí¼ÓÁËÒ»¸ö°´Å¥
ÔÚµÚһ֡дÏÂÃæµÄ´úÂë
mybtn.onRelease=function()
{
......
Õ⼸ÌìҪѧһÏÂflex¿ª·¢£¬µ«ÊÇ°²×°µÄÊÇeclipse²å¼þ°æµÄ£¬¿ÉÊÇ°²×°ºÃºó·¢ÏÖûÓпÉÊÓ»¯µÄ±à¼ÊÓͼ£¬×îºó·¢ÏÖÆäʵÊÇÒòΪflexµÄmxmlÎļþµÄ´ò¿ª·½Ê½ÊÇʹÓõÄspket±à¼Æ÷´ò¿ªµÄ£¬ËùÒÔûÓпÉÊÓ»¯±à¼ÊÓͼ£¬ÓÚÊÇ°ÉspketжÔØÁË¡£¾ÍºÃÁË¡£¼Ç¼һÏ£¬Ï£ÍûÄÜ°ïµ½±ðÈË£¬Ò²ÈÃ×Ô¼º¼Çס ......
¼ÙÉ踸´°¿ÚÊÇp,×Ó´°¿ÚÊÇc,×Ó´°¿Ú½øÐвÙ×÷ºó·µ»Ø¸¸´°¿Ú
¸¸´°¿Ú£º
var flag:Boolean = false;
var c:pop = pop(PopUpManager.createPopUp(this,pop,false)); // н¨×Ó´°Ìå¶ÔÏó
c.callFunction = this.fresh; // ×Ó´°ÌåÖпÉÒÔµ÷Óõĸ¸´°Ì庯Êý£¨ÕâÀïÊÇ×Ó´°Ìå¹Ø±Õʱ£¬ÓÃÀ´Ë¢Ð¸¸´°ÌåµÄÄÚÈÝ
function fresh():void
  ......
±¾ÎÄÁÐÊöÁË13¸öJava³ÌÐòÔ±Ó¦µ±Ñ§Ï°FlexºÍBlazeDSµÄÀíÓÉ£¬ÌÖÂÛ ÁËΪʲôFlex½áºÏBlazeDSÊÇ¿ª·¢RIAµÄ×î¼Ñ×éºÏÖ®Ò»¡£ÎÞ ÂÛÊǸ߶Ƚ»»¥µÄÍøÕ¾»¹ÊÇÒÔJavaΪºó¶ËµÄÆóÒµÓ¦Óã¬ÕâÏî×éºÏ¶¼ÊÇ×î¼ÑÑ¡ÔñÖ®Ò»¡£¸üÖØÒªµÄÊÇ£¬ÕâÏî×éºÏÄÜͬʱΪ¿ª·¢Ô±ºÍÆóÒµ´øÀ´¸ß»Ø±¨£¨ROI£©¡£
ÔÚ²ûÊöJava³ÌÐòÔ±Ó¦µ±Ñ§Ï°BlazeDSµÄ13ÌõÀíÓÉʱ£¬ÎÒÒÔÒ»¸ö¼ÙÏëµ ......
Flex Builder ¿ì½Ý¼ü
AdobeÔÚ¿ª·¢Flex×îÓÐÀûµÄ¹¤¾ß¾ÍÊÇFlex Builder£¬¿ìËÙ¼ü¶ÔÒ»°ã¿ª·¢ÕßÀ´Ëµ¶¼·Ç³£ÓÐÓ㬺ܶà¿ìËÙ¼üÓë×éºÏ¼üÊÇ»áÓëÆäËûÈíÌå»òϵͳ¶¼ÓÐÀ×֮ͬ´¦£¬Æ©Èç Ctrl + C ¾ÍÊǸ´ÖÆ£¬Ctrl + V ¾ÍÊÇÌùÉÏ¡£ÈôÄãÓÐ×¢Òâµ½¾Í»á²»ÄÑ·¢ÏÖ£¬ÆäʵFlex BuilderÓкܶàÓëEclipse±à¼¹¤¾ßÒ²ÊÇÓÐÐí¶àÏàËÆÖ®´¦¡£ ¶à¼ÓÉÆÒÔÀûÓðɣ¡
C ......