模仿HTML的Marquee组件,组件容器为Group,和flex4中Group使用无区别。
组件代码:
package pizazz.flex4.component{
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.ui.Mouse;
import flash.utils.Timer;
import mx.events.EffectEvent;
import mx.events.FlexEvent;
import pizazz.flex4.component.skin.marquee.MarqueeSkin;
import spark.components.SkinnableContainer;
import spark.effects.Move;
import spark.effects.easing.Linear;
import spark.layouts.HorizontalLayout;
import spark.layouts.VerticalLayout;
import spark.skins.spark.SkinnableContainerSkin;
public class Marquee extends SkinnableContainer{
public static const LEFT:String = "left";
public static const RIGHT:String = "right";
public static const UP:String = "up";
public static const DOWN:String = "down";
private var _moving:Move;
private var _direction:String = RIGHT;
private var _scrolldelay:Number = 0;
private var _scrollamount:Number = 0;
private var _loop:Number = 0;
private var _autoStart:Boolean = true;
private var _times:Timer;
private var _running:Boolean = false;
private var _isPause:Boolean = true;
/**
* 滚动方向设置,可选择left、right、up和down
*/
[Inspectable(enumeration="left,right,up,down")]
public function set direction(value:String):void{
_direction = value;
}
/**
* 每轮滚动之间的延迟时间,越大越慢
*/
public function set scrolldelay(value:Number):void{
_scrolldelay = value;
}
/**
* 一次滚动总的时间量,数字越小滚动越慢
*/
public function set scrollamount(value:Number):void{
_scrollamount = value;
}
/**
* 滚动次数
*/
public function set loop(value:Number):void{
_loop = value;
}
/**
* 是否自动开始move
*/
public function set autoStart(value:Boolean):void{
_autoStart = value;
}
/**
* 鼠标滑过是否暂停
*/
public function set isPause(value:Boolean):void{
_isPause = value;
}
public function Marquee(){
super();
setStyle("skinClass", MarqueeSkin);
addEventListener(FlexEvent.CREATION_COMPLETE,
function(event:FlexEvent):void{
if(_autoStart){
_times.start();
_running = true;
}
}
);
}
public function start():void{
if(!_running){
_times.start();
_running = true;
}
}
override protected function createChildren():void{
super.createChildren();
_moving = new Move(contentGroup);
_moving.duration = _scrollamount;
_moving.easer = new Linear();
_moving.addEventListener(EffectEvent.EFFECT_END,
function(event:EffectEvent):void{
_times.start();
}
);
_times = new Timer(_scrolldelay, _loop);
_times.addEventListener(TimerEvent.TIMER,
function(event:TimerEvent):void{
_times.stop();
play();
}
);
}
override protected function partAdded(partName:String,
instance:Object):void{
super.partAdded(partName, instance);
if(instance == contentGroup){
if(_direction == RIGHT || _direction == LEFT){
var _horizontal:HorizontalLayout = new HorizontalLayout();
_horizontal.clipAndEnableScrolling = true;
contentGroup.layout = _horizontal;
}else if(_direction == UP || _direction == DOWN){
var _vertical:VerticalLayout = new VerticalLayout();
_vertical.clipAndEnableScrolling = true;
contentGroup.layout = _vertical;
}
if(_isPause){
contentGroup.addEventListener(MouseEvent.ROLL_OVER,
function(event:MouseEvent):void{
_moving.pause();
}
);
contentGroup.addEventListener(MouseEvent.ROLL_OUT,
function(event:MouseEvent):void{
_moving.resume();
}
);
}
}
}
private function play():void{
if(_direction == RIGHT){
_moving.xFrom = -(contentGroup.width + 10);
_moving.xBy = width + 10;
}else if(_direction == LEFT){
_moving.xFrom = width + 10;
_moving.xBy = -(width + contentGroup.width + 10);
}else if(_direction == UP){
_moving.yFrom = height + 10;
_moving.yBy = -(height + contentGroup.height + 10);
}else if(_direction == DOWN){
_moving.yFrom = -(contentGroup.height + 10);
_moving.yBy = height + contentGroup.width + 10;
}
_moving.play();
}
}
}
pizazz.flex4.component.skin.marquee.MarqueeSkin.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
xmlns:layout="flexlib.scheduling.scheduleClasses.layout.*"
alpha.disabled="0.5" >
<fx:Metadata>
<![CDATA[
[HostComponent("pizazz.flex4.component.Marquee")]
]]>
</fx:Metadata>
<fx:Script fb:purpose="styling">
<![CDATA[
override protected function updateDisplayList(
unscaledWidth:Number, unscaledHeight:Number):void{
// Push backgroundColor and backgroundAlpha directly.
// Handle undefined backgroundColor by hiding the background object.
if (isNaN(getStyle("backgroundColor"))){
background.visible = false;
}else{
background.visible = true;
bgFill.color = getStyle("backgroundColor");
bgFill.alpha = getStyle("backgroundAlpha");
}
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
]]>
</fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
</s:states>
<s:layout>
<s:BasicLayout clipAndEnableScrolling="true" />
</s:layout>
<s:Rect id="background" left="0" right="0" top="0" bottom="0">
<s:fill>
<s:SolidColor id="bgFill" color="#FFFFFF"/>
</s:fill>
</s:Rect>
<s:Group id="contentGroup" minWidth="0" minHeight="0" />
</s:Skin>
组件执行:
<?xml version="1.0" encoding="utf-8"?>
<s:Application 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:component="pizazz.flex4.component.*"
minWidth="955" minHeight="600">
<s:layout>
<s:VerticalLayout />
</s:layout>
<fx:Script>
<![CDATA[
private function play():void{
marquee.start();
}
]]>
</fx:Script>
<component:Marquee scrollamount="10000" direction="right" width="100%"
backgroundColor="0xFFFF00">
<s:Label text="文字" height="100%" verticalAlign="middle" />
<mx:LinkButton label="可点击文字" />
</component:Marquee>
<component:Marquee id="marquee" direction="up" autoStart="false"
isPause="false" scrollamount="12000" width="320" height="320"
backgroundColor="0xFFFF00">
<mx:HBox width="320" horizontalAlign="center">
<mx:Image source="pizazz/flex4/assets/image/pic_help.png"
width="40" height="40" />
<s:Label width="100" text="这是一张图片的样式" />
</mx:HBox>
<s:Label width="100%" textAlign="center" text="--------------------" />
<s:Button width="100" label="按钮" />
</component:Marquee>
<s:Button width="100" label="开始" click="play()" />
</s:Application>
视图:
- 大小: 7.5 KB
分享到:
相关推荐
jQuery.Marquee是一款jQuery文字跑马灯插件。jQuery.Marquee跑马灯插件可以结合使用CSS3动画,制作文字的上下左右移动效果。
跑马灯或者流水灯电路设计 跑马灯或者叫“流水灯”:实现 LED 灯的循环移动 可采用模块化设计:分成时钟产生模块,移位模块、LED 驱动模块、模式切换模块 具体的流水灯数目自选 是否可以切换模式自选 模式的个数自选...
可以调文字滚动速度的跑马灯 。
Vue实现跑马灯样式文字横向滚动 本文实例为大家分享了Vue实现跑马灯样式文字横向滚动的具体代码,供大家参考...-- 跑马灯组件 --> <div class="marquee-wrap" ref="marquee-wrap"> <div class="scroll" ref="scroll
实现跑马灯上下滚动效果,marquee标签被摒弃后不使用js实现的跑马灯效果保险些
android 水平方向跑马灯
ListView每项跑马灯效果,TextView跑马灯自己写的Demo
简单的安卓跑马灯效果,分享出来.简单的安卓跑马灯效果,分享出来简单的安卓跑马灯效果,分享出来
<marquee>标签,它是成对出现的标签,首标签<marquee>和尾标签</marquee>之间的内容就是滚动内容。...但无意中发现了一个html标签——<marquee></marquee>可以实现多种滚动效果,无需js控制。使用marqu
vb.net 2005跑马灯实例,入门学习的好东西
”marquee” 以跑马灯的方式显示 动画横向移动 好像跑马灯这种效果已经不用咱们来实现了 呵呵 不过有一点 如果文字不过长 在组件的范围内 还想要跑马灯的效果怎么办呢 当然的自己自定义啦 那还能怎么做 哈哈 ">...
防照marquee,使用js实现无缝跑马灯,并实现了横向和纵向。
jQuery.Marquee 跑马灯效果
VHDL描述的跑马灯程序,用于初学者练习
主要介绍了基于Marquee.js插件实现的跑马灯效果,结合实例形式给出了Marquee.js插件的定义及具体使用方法,需要的朋友可以参考下
标题:可快进和倒退的跑马灯或走马灯或Marquee 开发代码:JS 适合项目中使用和学习使用
Android跑马灯 循环文字 Marquee,很不错的源码,可以直接编译运行
实现了TextView控制跑马灯的次数的效果
react-native 水平/竖直滚动跑马灯。支持多个text数据,支持点击事件回调,自定义宽度、样式。
跑马灯,当字数小于一行的时候垂直滚动,大于的时候自动水平滚动。