Flex 图片自动播放与图片拉伸
2010-03-26 17:45
423 查看
最近,做了个小部件,但是被一些小问题纠缠不清,现在拿出来与大家分享。
先看源代码:
<mx:Parallel id="pe">
<mx:Fade id="fe" alphaFrom="0" alphaTo="0.8" duration="600" />
<mx:Blur id="be" blurXFrom="50" blurXTo="0" blurYFrom="50" blurYTo="0" duration="600" />
</mx:Parallel>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.EffectEvent;
import flash.events.MouseEvent;
[Bindable]
[Embed(source="1.jpg")]
private var imgClass1:Class;
[Bindable]
[Embed(source="2.jpg")]
private var imgClass2:Class;
[Bindable]
[Embed(source="3.jpg")]
private var imgClass3:Class;
[Bindable]
[Embed(source="4.jpg")]
private var imgClass4:Class;
[Bindable]
[Embed(source="5.jpg")]
private var imgClass5:Class;
[Bindable]
[Embed(source="6.jpg")]
private var imgClass6:Class;
private var imgArray:ArrayCollection;
private var t:Timer = new Timer(3000);
private var index:int = 0;
public function init():void{
imgArray = new ArrayCollection();
imgArray.addItem(imgClass1);
imgArray.addItem(imgClass2);
imgArray.addItem(imgClass3);
imgArray.addItem(imgClass4);
imgArray.addItem(imgClass5);
imgArray.addItem(imgClass6);
img.scaleX = 2;
img.scaleY = 1;
img.source = imgArray[index] as Class;
img.addEventListener(MouseEvent.ROLL_OVER,stopPlay);
img.addEventListener(MouseEvent.ROLL_OUT,countinuePlay);
t.addEventListener(TimerEvent.TIMER,autoPlay);
t.start();
}
public function completeEvent(event:Event):void {
Bitmap(event.target.content).smoothing = true;
img.content.width = thumbnailContainer.width;
img.content.height = thumbnailContainer.height;
}
//每次完成载入,就对图片进行重新的大小定义
public function autoPlay(event:TimerEvent):void{
index++;
if(index > imgArray.length - 1) index=0;
img.source = imgArray[index];
}
public function stopPlay(event:MouseEvent):void{
t.stop();
}
public function countinuePlay(event:MouseEvent):void{
t.start();
}
public function remove(event:EffectEvent):void{
event.effectInstance.reverse();
event.effectInstance.play();
}
]]>
</mx:Script>
<mx:Canvas id="thumbnailContainer" width="529" height="191" y="0" x="0">
<mx:Image width="100%" height="100%" id="img" completeEffect="pe"
maintainAspectRatio="false" scaleContent="true"
complete="completeEvent(event)" x="0" y="0"/>
</mx:Canvas>
Flex image组件中有一个scaleContent属性,可使载入的图片按比例放大缩小,当然也可以使用scaleX与scaleY属性来定义,但是放大缩小的比例就很难自定义了,以上的脚本就实现了图片与外面容器大小相当的填充效果。
先看源代码:
<mx:Parallel id="pe">
<mx:Fade id="fe" alphaFrom="0" alphaTo="0.8" duration="600" />
<mx:Blur id="be" blurXFrom="50" blurXTo="0" blurYFrom="50" blurYTo="0" duration="600" />
</mx:Parallel>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.EffectEvent;
import flash.events.MouseEvent;
[Bindable]
[Embed(source="1.jpg")]
private var imgClass1:Class;
[Bindable]
[Embed(source="2.jpg")]
private var imgClass2:Class;
[Bindable]
[Embed(source="3.jpg")]
private var imgClass3:Class;
[Bindable]
[Embed(source="4.jpg")]
private var imgClass4:Class;
[Bindable]
[Embed(source="5.jpg")]
private var imgClass5:Class;
[Bindable]
[Embed(source="6.jpg")]
private var imgClass6:Class;
private var imgArray:ArrayCollection;
private var t:Timer = new Timer(3000);
private var index:int = 0;
public function init():void{
imgArray = new ArrayCollection();
imgArray.addItem(imgClass1);
imgArray.addItem(imgClass2);
imgArray.addItem(imgClass3);
imgArray.addItem(imgClass4);
imgArray.addItem(imgClass5);
imgArray.addItem(imgClass6);
img.scaleX = 2;
img.scaleY = 1;
img.source = imgArray[index] as Class;
img.addEventListener(MouseEvent.ROLL_OVER,stopPlay);
img.addEventListener(MouseEvent.ROLL_OUT,countinuePlay);
t.addEventListener(TimerEvent.TIMER,autoPlay);
t.start();
}
public function completeEvent(event:Event):void {
Bitmap(event.target.content).smoothing = true;
img.content.width = thumbnailContainer.width;
img.content.height = thumbnailContainer.height;
}
//每次完成载入,就对图片进行重新的大小定义
public function autoPlay(event:TimerEvent):void{
index++;
if(index > imgArray.length - 1) index=0;
img.source = imgArray[index];
}
public function stopPlay(event:MouseEvent):void{
t.stop();
}
public function countinuePlay(event:MouseEvent):void{
t.start();
}
public function remove(event:EffectEvent):void{
event.effectInstance.reverse();
event.effectInstance.play();
}
]]>
</mx:Script>
<mx:Canvas id="thumbnailContainer" width="529" height="191" y="0" x="0">
<mx:Image width="100%" height="100%" id="img" completeEffect="pe"
maintainAspectRatio="false" scaleContent="true"
complete="completeEvent(event)" x="0" y="0"/>
</mx:Canvas>
Flex image组件中有一个scaleContent属性,可使载入的图片按比例放大缩小,当然也可以使用scaleX与scaleY属性来定义,但是放大缩小的比例就很难自定义了,以上的脚本就实现了图片与外面容器大小相当的填充效果。
相关文章推荐
- Flex 图片自动播放(亦可手动控制)
- JS特效实现图片自动播放并可控的效果
- 写一个图片轮播效果的Demo(自动播放)附代码
- JS实现图片自动播放,并在鼠标悬停某个圆点时,图片改变为其代表的图片。
- 一个自动动态播放图片的类(downmoon)新增图片效果
- UIImage类目-返回一张拉伸的图片、自动设配6 7
- 图片定时自动播放
- table中background背景图片自动拉伸
- Axure 图片轮播(广告通栏图片自动播放效果)
- JFileChooser实现对选定文件夹内图片自动播放和暂停播放实例代码
- js图片自动循环播放
- flex做图片切换(播放)
- 图片自动播放也可通过按钮控制显示
- css 背景图片随分辨率自动拉伸
- 自动播放图片,可以调整速度。
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- Web前端-JS效果-网站首页+图片自动播放、切换等效果
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- 图片自动播放器脚本之家修正