zoukankan      html  css  js  c++  java
  • php下swf开发技术文档

    准备资料

    1)swfmill 通过swfmill工具生成swf文件。 参考: http://www.swfmill.org/ 
    2)swfeditor 通过swfeditor工具来编辑swf文件。参考: http://zh.sourceforge.jp/projects/swfed/wiki/SWFEditor.replaceActionStrings?action=showhist&text_id=70348 
    3)反编译工具Flash Decompiler Trillix 通过此工具可以反编译swf文件。 参考:http://flash-decompiler-trillix.softonic.cn/ 
    4)swf文件格式说明书:http://wenku.baidu.com/view/5bb4ad34eefdc8d376ee3296.html 
    5)  swfmill命令实例: 
       xml转swf            
       例如 E:\swfmill-0.3.2-win32\swfmill xml2swf E:\13_1_0.xml E:\13_1_0.swf
       swf转xml            
       例如 E:\swfmill-0.3.2-win32\swfmill swf2xml E:\13_1_0.swf E:\13_1_0.xml

    流程图

    构造Swf模板

     Swf文件生成所依赖的模板就是一个Xml文件,通过编辑此xml文件来控制swf文件的画面以及事件。所以要创建swf模板必须先了解,模板中的各个标签的含义及用法。    

    标签介绍:     SWF中有两种类型的标签(Tag):    

    定义型标签(Tag):这种标签(Tag)定义SWF动画的内容如:变形、文本、位图、声音等。每个定义标签(Tag)定义一个唯一的字符型ID来标示它定义的内容。播放器存储这些字符ID到一个叫做字典(Dictionary)库中。定义标签(Tag)完全由系统自己完成。    

    控制标签(Tag):这种标签(Tag)建立和操作字典(Dictionary)中的字符标示的实例(Instance)并且控制动画的播放。   SWF中的标签(Tag)顺序:     一般来说,SWF中的标签(Tag)可以任意排列。

    然而,必须遵循下面的几点小的规则:    

    1.     标签(Tag)仅仅依靠它上面的标签(Tag)。一个文件中只能有一个结束标签(Tag)。    

    2.     定义标签(Tag)必须定义字符标示在所有控制标签(Tag)之前。    

    3.     声音流标签(Tag)必须顺序排放。错误的排列(Out-of-order)的声音流标签(Tag)会导致播放错误(Out-of-order)。    

    4.     结束标签(Tag)必须在SWF文件末尾。           

    Header:swf文件头,每个swf文件都有一个文件头。     

    framerate: (帧速)表示 每秒帧的播放速度。    

    frames:总的帧数   size:定义画面的大小    

    Rectangle:矩形,单位为twig,1twig=1/20pixels     left:左边位置    right:右边位置    top:顶端位置    bottom:底端位置   

    SetBackgroundColor:设置背景色    color:颜色定义标签     red:红色值    green:绿色值    blue:蓝色值   

    DefineShape:定义形状     

    objectID:对象ID的值   

    bounds:形状对象要限定的形状。    

    styles:样式    StyleList:样式列表    fillStyles:要填充的样式    Solid:样式为密实的    

    DefineSprite:定义图形标签,利用其他的字符内容来定义他们自己的内容    

    DoAction:要执行的动作    actions:动作集    Play:执行播放动作    Stop:执行播放停止动作    EndAction:动作结束标签    

    PlaceObject2:在播放目录中增加一个标识符并设置标识符的深度值。     

    replace:replace=“0”表示该深度值上没有其他元素,该元素为新增的,replace=“1”表示该深度值上有一个元素,要用新元素替换。    

    depth:标识符的深度值   

    transform:定义变形    transform:定义变形     scaleX:沿x坐标放大的系数    scaleY:沿y坐标放大的系数    transX:沿x坐标移动的值    transY:沿y坐标移动的值   

    events:事件集标签    GotoFrame:跳转到某一帧     frame:帧的数值   ShowFrame:按播放目录的顺序播放。                  

    例如:

    <?xml version="1.0" encoding="UTF-8"?>
    <swf version="7" compressed="1">
      <Header framerate="12" frames="1">
        <size>
          <Rectangle left="0" right="11000" top="0" bottom="8000"/>
        </size>
        <tags>
          <SetBackgroundColor>
            <color>
              <Color red="255" green="255" blue="255"/>
            </color>
          </SetBackgroundColor>
          <DefineShape objectID="1">
            <bounds>
              <Rectangle left="-6698" right="-5978" top="-1680" bottom="-960"/>
            </bounds>
            <styles>
              <StyleList>
                <fillStyles>
                  <Solid>
                    <color>
                      <Color red="0" green="102" blue="255"/>
                    </color>
                  </Solid>
                </fillStyles>
                <lineStyles/>
              </StyleList>
            </styles>
            <shapes>
              <Shape>
                <edges>
                  <ShapeSetup x="-6698" y="-1680" fillStyle1="1"/>
                  <LineTo x="720" y="0"/>
                  <LineTo x="0" y="720"/>
                  <LineTo x="-720" y="0"/>
                  <LineTo x="0" y="-720"/>
                  <ShapeSetup/>
                </edges>
              </Shape>
            </shapes>
          </DefineShape>
          <DefineShape objectID="2">
            <bounds>
              <Rectangle left="-6698" right="-5978" top="-1680" bottom="-960"/>
            </bounds>
            <styles>
              <StyleList>
                <fillStyles>
                  <Solid>
                    <color>
                      <Color red="0" green="255" blue="102"/>
                    </color>
                  </Solid>
                </fillStyles>
                <lineStyles/>
              </StyleList>
            </styles>
            <shapes>
              <Shape>
                <edges>
                  <ShapeSetup x="-6698" y="-1680" fillStyle1="1"/>
                  <LineTo x="720" y="0"/>
                  <LineTo x="0" y="720"/>
                  <LineTo x="-720" y="0"/>
                  <LineTo x="0" y="-720"/>
                  <ShapeSetup/>
                </edges>
              </Shape>
            </shapes>
          </DefineShape>
          <DefineSprite objectID="3" frames="2">
            <tags>
              <DoAction>
                <actions>
                  <Stop/>
                  <EndAction/>
                </actions>
              </DoAction>
              <PlaceObject2 replace="0" depth="1" objectID="1">
                <transform>
                  <Transform transX="0" transY="0"/>
                </transform>
              </PlaceObject2>
              <ShowFrame/>
              <DoAction>
                <actions>
                  <Stop/>
                  <EndAction/>
                </actions>
              </DoAction>
              <PlaceObject2 replace="1" depth="1" objectID="2"/>
              <ShowFrame/>
              <End/>
            </tags>
          </DefineSprite>
          <PlaceObject2 replace="0" depth="1" objectID="3" allflags1="3072" allflags2="0">
            <transform>
              <Transform scaleX="5.250000000000000" scaleY="6.313888549804688" transX="38567" transY="12095"/>
            </transform>
            <events>
              <Event flags1="1024" flags2="0">
                <actions>
                  <GotoFrame frame="1"/>
                  <Play/>
                  <EndAction/>
                </actions>
              </Event>
              <Event flags1="2048" flags2="0">
                <actions>
                  <GotoFrame frame="0"/>
                  <Play/>
                  <EndAction/>
                </actions>
              </Event>
              <Event flags1="0" flags2="0"/>
            </events>
          </PlaceObject2>
          <ShowFrame/>
          <End/>
        </tags>
      </Header>
    </swf>


    swf的生成

    生成过程:swf文件的生成是根据预先定义好的Xml模板进行的,通过调用swfmill程序来把xml文件转化为swf文件。 
     在linux系统下,php可以通过popen配合pclose来实现,执行swfmill命令。
     

    /** 
     * create swf file with command 
     */ 
    private function  createSwf() 
    { 
     // Swfmill execute command
     $cmd = $this->swffill_command.' '.$this->outputXml.' '.$this->outputSwf;// 获取swfmill的命令
     
     $handle = popen($cmd, 'r'); // 通过popen函数来执行swfmill的命令
     pclose($handle);
    } 

    swf的编辑

     编辑过程:通过指定路径,获取swf文件,然后通过swfeditor对其进行编辑。例如可以修改,添加,删除节点。  

    /**        
     * prepare for flash file        
     */        
    function prepareFlash($flashParam){        
            
        $userName = $this->getUserName();    
        $userFamilyname = $this->getUserFamilyname();    
        // get swf file    
        $swfPath = $this->container->getParameter('SWF_Path'); // 获取swf文件的路径    
        if ($this->getRequest()->getSession()->has('SANDBOX'))    
        {    
            $swfPath = $this->container->getParameter('SWF_Path_DEV');
        }    
            
        $swfFilename = getcwd().$swfPath."/".$this->getPlatform()."/".$flashParam["swfId"].".swf"; // 根据swf文件路径获得swf文件名    
        $tempSwf = getcwd().$swfPath."/".$this->getPlatform()."/".$flashParam["swfId"]."tmp.swf";    
            
        if(!file_exists($swfFilename)){    
            throw new \Exception("File does not exist! file:".$swfFilename);
        }    
            
        $swfdata = file_get_contents($swfFilename); // 取得swf文件的内容    
        $url =     $this->buildSwfUrl("game/scene5/game_u110_continue");
        $obj = new \SWFEditor();// 创建swfeditor对象    
        $obj->input($swfdata); // 对象载入swf文件内容    
        $variableName = array('NAME' => $userName, 'FNAME' => $userFamilyname);    
        $obj->setActionVariables($variableName);// 修改变量    
        $variableUrl = array('#?' => $url);    
        $obj->replaceActionStrings($variableUrl); // 替换字符串    
        file_put_contents($tempSwf,$obj->output()); // 重新生成swf文件    
        $flashParam["swf"] = $flashParam["img_root"].$swfPath."/".$this->getPlatform()."/".$flashParam["swfId"]."tmp.swf";    
            
        return $flashParam;    
    }        
  • 相关阅读:
    web api 特点
    码农
    到程序员短缺的地方生活,不要到过剩的地方凑热闹
    程序员也要寻找贸易的机会,要参加研讨会
    [Codeforces 863D]Yet Another Array Queries Problem
    [Codeforces 863C]1-2-3
    [Codeforces 864F]Cities Excursions
    [Codeforces 864E]Fire
    [Codeforces 864D]Make a Permutation!
    [Codeforces 864C]Bus
  • 原文地址:https://www.cnblogs.com/Kakasi/p/2847178.html
Copyright © 2011-2022 走看看