我正在尝试扩展 flex 中的文本输入以支持图标,就像 mac os x 搜索文本输入有一个向右对齐的灰色圆圈,文本输入有一个 addChild 方法,但它不起作用我。
有没有办法做到这一点?
提前致谢
我正在尝试扩展 flex 中的文本输入以支持图标,就像 mac os x 搜索文本输入有一个向右对齐的灰色圆圈,文本输入有一个 addChild 方法,但它不起作用我。
有没有办法做到这一点?
提前致谢
一个更简单的方法是创建一个看起来像您想要的文本输入的 mxml 组件。我从未见过 mac OSX 搜索框,但根据您的描述,一个基于带有白色背景的画布的组件,然后适当的边框可以包含没有边框的图像和文本输入。我想这会给你你想要的样子。
我找到了解决方案:D 这是代码
诀窍是覆盖 updateDisplayList。
快乐的黑客。
package
{
import flash.display.DisplayObject;
import mx.controls.Image;
import mx.controls.TextInput;
import mx.core.mx_internal;
use namespace mx_internal;
public class MyTextInput extends TextInput
{
private var _image:Image;
public function MyTextInput()
{
super();
}
override protected function createChildren():void
{
super.createChildren();
_image = new Image();
_image.source = "http://sstatic.net/so/img/replies-off.png",
addChild(DisplayObject(_image));
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
this._image.width = 16;
this._image.height = 16;
this._image.x = this.width - this._image.width - 5;
this._image.y = this.height - this._image.height;
this.textField.width = this.width - this._image.width - 5;
}
}
}