Flex4中的皮肤(4):使用SkinPart约束Skin

在SkinnableComponent中,可以声明SkinPart元标签对Skin进行约束,同时在组件中提供对Skin元素的引用:

[SkinPart(required="false")] public var labelElement:SimpleText;

如果声明了SkinPart并且required="true",则Skin中必须包含该类型灯元素并且具有相同的id:

<s:SimpleText id="labelElement" .../>

SkinnableComponent中还提供了partAdded和partRemoved方法:

//-------------------------------------------------------------------------- // // Methods - Parts // //-------------------------------------------------------------------------- /** * Called when a skin part is added. * You do not call this method directly. * For static parts, Flex calls it automatically when it calls the <code>attachSkin()</code> method. * For dynamic parts, Flex calls it automatically when it calls * the <code>createDynamicPartInstance()</code> method. * * <p>Override this function to attach behavior to the part. * If you want to override behavior on a skin part that is inherited from a base class, * make sure that you do not call the <code>super.partAdded()</code> method. * Otherwise, you should always call the <code>super.partAdded()</code> method.</p> * * @param partname The name of the part. * * @param instance The part. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ protected function partAdded(partName:String, instance:Object):void { } /** * Called when an instance of a skin part is being removed. * You do not call this method directly. * For static parts, Flex calls it automatically when it calls the <code>detachSkin()</code> method. * For dynamic parts, Flex calls it automatically when it calls * the <code>removeDynamicPartInstance()</code> method. * * <p>Override this function to remove behavior from the part.</p> * * @param partname The name of the part. * * @param instance The part. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ protected function partRemoved(partName:String, instance:Object):void { }

在增加或删除SkinPart时会调用这些方法。

通过重写这些方法可以对SkinPart进行额外的操作,比如增加SkinPart时为其添加事件监听:

override protected function partAdded(partName:String, instance:Object) : void { super.partAdded(partName, instance); if (instance == labelElement) labelElement.addEventListener(...); }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值