Flex菜单弹跳效果

一个很简单的单击效果(弹跳,选中时加下划线),可适用于菜单单击,将下面代码作为MenuItemRenderer。实现这个效果无非就是使用了Move3D。(选自FlexViewer)
<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:components="com.components.*"
implements="mx.managers.IFocusManagerComponent"
buttonMode="true"
focusEnabled="true"
useHandCursor="true"
click="itemClickHandler(event)">

<fx:Declarations>
<s:Move3D id="moveEffect" duration="200" effectEnd="moveEffectEndHandler(event)" repeatBehavior="reverse" repeatCount="2" target="{icon}" yBy="-8" yFrom="0"/>
</fx:Declarations>

<fx:Script>
<![CDATA[
import mx.events.EffectEvent;
import mx.events.FlexEvent;

/**
* 是否打开标识
*/
private var isOpen:Boolean = false;


/**
* 数据更改时触发函数,如果作为菜单的ItemRenderer时,监听DataChangeEvent。否则要外部调用执行。以便实现窗口关闭还原状态
*/
public function itemrenderer_dataChangeHandler(open:Boolean):void
{
//itemrenderer_dataChangeHandler(event:CustomEvent):void
//作为renderer时,派发自定义事件,data属性中设置open状态,直接赋值即可。
// icon.source = event.data.icon;
// underline.open = event.data.open;

underline.open = open;
}


/**
* 鼠标移出事件处理
*/
private function mouseOutHandler(event:MouseEvent):void
{
//执行鼠标移出处理
}

/**
* 鼠标移上事件处理
*/
private function mouseOverHandler(event:MouseEvent):void
{
//执行鼠标移上处理
}

/**
* 单击事件处理函数
*/
private function itemClickHandler(event:MouseEvent):void
{
if ( !isOpen )
{
moveEffect.end();
moveEffect.play();
underline.open = isOpen = true;
}
}

/**
* 单击时效果渲染完毕 处理函数
*/
private function moveEffectEndHandler(event:EffectEvent):void
{
//执行单击操作
}

//--------------------------------------------------------------------------
//
// Focus Management
//
//--------------------------------------------------------------------------

/**
* 获取焦点,可在此函数中通过焦点来执行鼠标移上移出处理。
*/
override public function drawFocus(isFocused:Boolean):void
{
super.drawFocus(isFocused);

// Popup the tooltip or remove the menu
if (isFocused)
{
mouseOverHandler(null);
}
else
{
mouseOutHandler(null);
}
}


/**
* 空格事件处理,按下空格键派发Click事件
*/
private var keyboardPressed:Boolean = false;

override protected function keyDownHandler(event:KeyboardEvent):void
{
if (event.keyCode != Keyboard.SPACE)
{
return;
}

keyboardPressed = true;
event.updateAfterEvent();
}

override protected function keyUpHandler(event:KeyboardEvent):void
{
if (event.keyCode != Keyboard.SPACE)
{
return;
}

if (enabled && keyboardPressed)
{
// Mimic mouse click on the button.
keyboardPressed = false;
dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
event.updateAfterEvent();
}
]]>
</fx:Script>

<s:VGroup width="50" height="30" gap="2" horizontalAlign="center" verticalAlign="middle">
<s:Image id="icon" source="@Embed('assets/images/icons/i_clock.png')" width="25" height="25" buttonMode="true"
mouseOut="mouseOutHandler(event)" mouseOver="mouseOverHandler(event)" smooth="true" useHandCursor="true"/>
<components:Underline id="underline"/>
</s:VGroup>

</s:VGroup>


Underline
<?xml version="1.0" encoding="utf-8"?>
<!--

绘制线段

-->
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
[Bindable]
public var open:Boolean = false;
]]>
</fx:Script>
<s:Line width="10" includeInLayout="{open}" visible="{open}">
<s:stroke>
<s:SolidColorStroke caps="square" color="0x000000" weight="2"/>
</s:stroke>
</s:Line>
</s:Group>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值