Featured Post

FLASH image processing / tailoring, dynamic selection

Here is the code related technologies. //Marquee package com.moorwind.imageprocesser.utils { import com.moorwind.imageprocesser.ui.ScaleButton; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Rectangle; import flash.net.URLLoader; public class...

Read More

Flex in the custom event

Posted by activetofocus | Posted in Flash Technology | Posted on 22-10-2009

0

Event is a very useful feature, often used for interactive transmissionof information greatly increased programming flexibility. In the high-level language features will be integrated in this regard;Flex is no exception in almost all controls are integrated into a large number of events, if the Button’s Click events. But the actualapplication of the control events that are not full of their own real needs, especially in their own write custom control, the custom control inside information on how changes in the container where the timely notification must become; this time, the custom event on the to play its role.
Are defined in the Flex in the event there are two situations are
defined in the ActionScript and MXML.

In the definition of ActionScript:

[Event(name="myEnableEvent",)]

public class MyComponent extends UIComponent

{

}

In the definition of  MXML:

<mx:Metadata>

[Event(name="DataChange",)]

</mx:Metadata>

DataChangeEvent the event parameter definition:

import flash.events.Event;

public class DataChangeEvent extends flash.events.Event

{

public function DataChangeEvent()

{

super(“DataChange”);

}

public var Data:Object;

}

Is defined in a custom control and trigger events:

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:Form xmlns:mx=”http://www.adobe.com/2006/mxml” width=”212″ height=”56″>

<mx:Metadata>

[Event(name="DataChange",)]

</mx:Metadata>

<mx:Button label=”Button” click=”Change()”/>

<mx:Script>

<![CDATA[

function Change():void

{

this.dispatchEvent(new DataChangeEvent());

}

]]>

</mx:Script>

</mx:Form>

Custom Control to receive the container-related events:

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” xmlns:ns1=”*”>

<ns1:EmployeeCombo x=”146″ y=”132″ DataChange=”onChange(event)” >

</ns1:EmployeeCombo>

<mx:Script>

<![CDATA[

import mx.controls.Alert;

function onChange(e:DataChangeEvent)

{

}

]]>

</mx:Script>

</mx:Application>

Write a comment

Powered by WP Hashcash