Flex:如何创建一个全新的组件?

Dav*_*lle 5 apache-flex user-interface

我想为Flex开发一个网络图应用程序 - 想象一下将节点放在Canvas上并用链接连接它们.节点应具有可编辑的文本和其他UI组件.

我试图找到从头开始创建一个全新的UI组件的示例,但我能够找到的只是扩展现有组件的简单示例:例如,扩展Button的RedButton,或者具有状态的ComboBox从中选择.

我的主要问题是,ActionScript方法定义了组件的绘制? 什么是Java的paint()方法的ActionScript等价物?

dar*_*all 5

您想要创建一个覆盖updateDisplayList方法的组件,并在那里进行绘制:

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
  super.updateDisplayList( unscaledWidth, unscaledHeight );

  // The drawing API is found on the components "graphics" property
  graphics.clear();
  graphics.lineTo( 0, unscaledWidth );
  // etc
}
Run Code Online (Sandbox Code Playgroud)

可以在此处找到更多信息:http://livedocs.adobe.com/flex/3/html/help.html?content = ascomponents_advanced_3.html