【问题标题】:Flex 4: Cannot use gif animation in FlexFlex 4:无法在 Flex 中使用 gif 动画
【发布时间】: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


【解决方案1】:

您可以尝试的一件事:

  • 右键单击您的项目并单击“属性”
  • 点击“Flex 编译器”
  • 确保选中“将非嵌入文件复制到输出文件夹”

这将使图像复制到您的输出文件夹中(通常是项目中的 bin-debug)。编译后,您实际上可以打开该文件夹并查看文件是否放入其中。如果它不在那里,请尝试手动将文件复制到那里并查看它是否有效。或者您可以尝试使用普通图像,看看它在该位置是否可以正常工作。

祝你好运。

【讨论】:

  • 谢谢,但这没有帮助。 gif 文件确实在输出文件夹中。
  • 我复制了您的代码并在本地尝试了它,并且 gif 显示良好。我在使用 Flex SDK 4.6 时遇到了堆栈跟踪。您可以将 s:Group 更改为 mx:Canvas 来解决此问题。使用 Flex SDK 4.13,视频部分没有显示,但 gif 仍然没有堆栈跟踪。我唯一没有的是你的 spinner.gif。我使用了 GIFPlayer 附带的 diego.gif。我通过将 org 文件夹复制到我的项目 src 文件夹中来包含 GIFPlayer 代码。
  • 这是个好消息,谢谢,我也会试试 :) 我使用的是 Flex SDK 4.6,也会试试 diego.gif 文件。
  • 我认为当我使用 firefox 浏览器时 gif 文件确实可以工作,但在 Chrome 中却不行。我也在使用 Ubuntu 12.04。你有没有机会知道如何让它在 Chrome 中工作?谢谢你:)
  • 我在 Chrome 中尝试过,并且通过启用 Pepper Flash 播放器能够重现它。深入研究一下代码,当它调用 urlLoader.load 时,它看起来在 GIFPlayer 中失败了。由于没有 Pepper Flash 的调试版本,因此不确定它到底是什么失败了。
猜你喜欢
  • 2010-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多