Flash 在DHTML和SWF10/11运行时中使用OpenLaszlo 5.0中的动画GIF

Flash 在DHTML和SWF10/11运行时中使用OpenLaszlo 5.0中的动画GIF,flash,animated-gif,openlaszlo,lzx,Flash,Animated Gif,Openlaszlo,Lzx,Flash Player不提供对动画GIF文件的本机支持。在DHTML运行时中,您可以像使用任何其他图像资源一样使用动画GIF。但是,如何在SWF10或SWF11运行时将图像用作视图的资源?幸运的是,有许多现有的开源ActionScript库支持播放和生成动画GIF。我们将使用这个项目。我们首先必须将as3gif的ActionScript源代码编译成一个SWC库,然后可以与OpenLaszlo一起使用。下载。解压缩$LPS_主文件夹中的ZIP文件。您应该有一个子文件夹“GIFPlayer 0.6

Flash Player不提供对动画GIF文件的本机支持。在DHTML运行时中,您可以像使用任何其他图像资源一样使用动画GIF。但是,如何在SWF10或SWF11运行时将图像用作视图的资源?

幸运的是,有许多现有的开源ActionScript库支持播放和生成动画GIF。我们将使用这个项目。我们首先必须将as3gif的ActionScript源代码编译成一个SWC库,然后可以与OpenLaszlo一起使用。下载。解压缩$LPS_主文件夹中的ZIP文件。您应该有一个子文件夹“GIFPlayer 0.6”

$LPS_HOME/GIFPlayer 0.6/

进入该文件夹,并使用Flex SDK compc命令将ActionScript类编译成SWC文件。对于OpenLaszlo 4.9或5.0(截至2012年9月),可以在$LPS_HOME/WEB-INF/bin/compc中找到compc命令。如果使用OpenLaszlo的flex4.6分支,则compc命令的路径对于SWF10运行时为WEB-INF/flexsdk/4.5.1/bin/compc,对于SWF11运行时为WEB-INF/flexsdk/4.6.0/bin/compc

$LPS_HOME/WEB-INF/bin/compc-optimize=true -静态链接运行时共享库=true-源路径+=-output=bin/as3gif_0.6.swc-包含类org.bytearray.gif.decoder.gifdedcoder org.bytearray.gif.encoder.gif编码器 org.bytearray.gif.encoder.LZWEncoder org.bytearray.gif.encoder.NeuQuant org.bytearray.gif.errors.FileTypeError org.bytearray.gif.events.FileTypeEvent org.bytearray.gif.events.FrameEvent org.bytearray.gif.events.gifplayervent org.bytearray.gif.events.TimeoutEvent org.bytearray.gif.frames.giframe org.bytearray.gif.player.GIFPlayer

编译后,您将在子文件夹bin中找到生成的SWC文件:

bin/as3gif_0.6.swc

将SWC文件复制到$LPS_HOME/WEB-INF/flexlib文件夹中。我们要用来显示动画GIF的类是org.bytearray.GIF.player.GIFPlayer类

下面是一个OpenLaszlo类在两个运行时都支持GIF的示例:

<canvas>
<!-- Copyright (c) Raju Bitter / MIT license http://www.opensource.org/licenses/mit-license.php -->

  <class name="gifview" extends="view" width="200" height="200">
    <passthrough when="$as3">
      import flash.events.IOErrorEvent;
      import flash.net.URLRequest;
      import org.bytearray.gif.player.GIFPlayer;
      import org.bytearray.gif.events.GIFPlayerEvent;
    </passthrough>
    <attribute name="gifsrc" type="string" value="" />
    <attribute name="__gifplayer" type="object" value="null" />
    <handler name="oninit">
      if (this.gifsrc != '') {
         this.ongifsrc.sendEvent();
      }
    </handler>
    <handler name="ongifsrc">
      if ($dhtml) {
        this.setSource(this.gifsrc);
      } else {
    if (this.__player == null) {
          this.__player = new GIFPlayer();
          this.__player.addEventListener(GIFPlayerEvent.COMPLETE, onGIFLoadComplete);
          this.__player.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
        }
        this.__player.load(new URLRequest(this.gifsrc));
        this.getDisplayObject().addChild(this.__player);
      }
    </handler>
    <method name="onGIFLoadComplete" args="evt"><![CDATA[
      Debug.info("GIF loaded successfully!");
      Debug.info("Total frames: " + this.__player.totalFrames);
      for (var i=1; i <= this.__player.totalFrames; i++) {
        Debug.info("Delay for frame #" + i + ": " + this.__player.getDelay(i));
      }
    ]]></method>
    <method name="onIOError" args="evt">
      Debug.error("Error loading GIF!");
      Debug.inspect(evt);
    </method>
    <!-- Custom unload method -->
    <method name="unload">
       if ($dhtml) {
         super.unload();
       } else {
         this.getDisplayObject().removeChildAt(0);
         // Dispose image resources
     this.__player.dispose();
         this.setAttribute('__player', null);
       }
    </method>
    <method name="stopGIFAnim">
      if ($as3) {
        this.__player.stop();
        Debug.info("Stopped animation at frame " + this.__player.currentFrame);
      } else {
         Debug.warn("Not supported in this runtime");
      }
    </method>
    <method name="startGIFAnim">
      if ($as3) {
        this.__player.play();
      } else {
         Debug.warn("Not supported in this runtime");
      }
    </method>
  </class>

  <gifview x="100" y="10" id="gv" gifsrc="animated.gif" />

  <button text="Start anim" onclick="gv.startGIFAnim()" />
  <button y="50" text="Stop anim" onclick="gv.stopGIFAnim()" />
  <button y="100" text="Unload GIF" onclick="gv.unload()" />
  <button y="150" text="Load again" onclick="gv.setAttribute('gifsrc', 'animated.gif')" />

</canvas>

导入flash.events.IOErrorEvent;
导入flash.net.URLRequest;
导入org.bytearray.gif.player.GIFPlayer;
导入org.bytearray.gif.events.gifplayervent;
如果(this.gifsrc!=''){
this.ongifsrc.sendEvent();
}
如果($dhtml){
this.setSource(this.gifsrc);
}否则{
if(this.\u player==null){
这个。uu player=new GIFPlayer();
此.u player.addEventListener(GIFPlayerEvent.COMPLETE、onGIFLoadComplete);
此.u player.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
}
this.u player.load(新的URLRequest(this.gifsrc));
this.getDisplayObject().addChild(this.\u播放器);
}
错误(“加载GIF时出错!”);
调试检查(evt);
如果($dhtml){
super.unload();
}否则{
此.getDisplayObject().removeChildAt(0);
//处理图像资源
这个.uu player.dispose();
此.setAttribute(“\u播放器”,null);
}
如果($as3){
这个。uu player.stop();
Debug.info(“在帧处停止动画”+this.\u player.currentFrame);
}否则{
Debug.warn(“此运行时不支持”);
}
如果($as3){
这个.uu player.play();
}否则{
Debug.warn(“此运行时不支持”);
}
ActionScript类支持启动和停止动画,并允许您访问GIF每帧的延迟