【发布时间】:2014-08-10 07:31:08
【问题描述】:
我是 Flex 的新手,现在正在学习如何在工作项目中使用 gif 动画。下面的示例是一个非常简单的 Flash 播放器(用于测试目的)。我需要做的就是在播放器播放时显示 spinner.gif 正在运行。没有微调器,播放器可以正常工作,但是当我添加“show_spinner”函数和行时,屏幕上什么也没有出现
<local:AnimatedGIFImage id="spinner" source="spinner.gif" visible="false" verticalCenter="0" horizontalCenter="0"/>。
brouser 窗口只是空白。我在网上搜索,但还没有找到答案。我认为我不完全理解 Flash 播放器显示组件的方式。非常感谢任何建议。
Spinner.mxml 文件:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:local="*"
xmlns:s="spark.components.*" layout="vertical" verticalAlign="top"
backgroundColor="white"
viewSourceURL="srcview/index.html"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.events.VideoEvent;
private function videoDisplay_ready():void {
videoDisplay.visible = true;
controlBar.visible = true;
}
private function show_spinner(evt:mx.events.VideoEvent):void {
if (evt.state == "playing") {
spinner.setVisible(true);
} else {
spinner.setVisible(false);
}
}
private function initApp(){
videoDisplay.addChild(spinner);
}
]]>
</mx:Script>
<s:Group>
<mx:VideoDisplay id="videoDisplay" visible="false" width="{200}" height="{200}"
ready="videoDisplay_ready()"
source="http://www.derekentringer.com/flv/purple_plasma.flv"
stateChange="show_spinner(event)">
</mx:VideoDisplay>
<mx:ControlBar id="controlBar" visible="false">
<mx:Button id="play" name="play" label="Play" click="videoDisplay.play()"></mx:Button>
<mx:Button id="pause" name="pause" label="Pause" click="videoDisplay.pause()"></mx:Button>
</mx:ControlBar>
<local:AnimatedGIFImage id="spinner" source="spinner.gif" visible="false" verticalCenter="0" horizontalCenter="0"/>
</s:Group>
</mx:Application>
AnimatedGIFImage.as 文件(来自http://iamjosh.wordpress.com/2009/02/03/animated-gifs-in-flex/):
package
{
import flash.net.URLRequest;
import mx.controls.Image;
import mx.core.UIComponent;
import org.bytearray.gif.player.GIFPlayer;
public class AnimatedGIFImage extends Image
{
private var _gifImage : UIComponent;
public function AnimatedGIFImage()
{
super();
this._gifImage = new UIComponent();
}
override public function set source(value : Object) : void
{
if (!value is String)
{
throw new ArgumentError("Source must be of type String");
}
super.source = value;
}
override protected function createChildren() : void
{
super.createChildren();
var player : GIFPlayer = new GIFPlayer();
player.load(new URLRequest(this.source as String));
this._gifImage.addChild(player);
}
override protected function updateDisplayList(unscaledWidth : Number, unscaledHeight : Number) : void
{
this.addChild(this._gifImage);
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
}
}
【问题讨论】:
-
如果您只在 MXML 标记中设置
visible="true",而不调用show_spinner,您会看到微调器吗? -
谢谢,我刚试过这个,答案是“否”,屏幕是空白的(没有播放器,也没有微调器)。
-
您的项目中的 spinner.gif 在哪里?
-
spinner.gif 与 Spinner.mxml 和 AnimatedGIFImage.as 文件一起位于 src 文件夹中。
标签: actionscript-3 flash apache-flex