【问题标题】:ActionScript Drawing Code From Vector Graphic?ActionScript 从矢量图形绘制代码?
【发布时间】:2011-09-21 14:18:07
【问题描述】:

有没有一种通用的方法可以将 Flash Professional 中绘制的矢量图形转换为绘图 API 的代码?

这些绘制或导入的矢量图形资源的代码在源文件 (.xfl) 中以 XML 数据的形式提供。例如,下面绘制的矢量图就是尾随的 XML 数据。

<DOMSymbolItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ns.adobe.com/xfl/2008/" name="MSprite" itemID="4e03ae4f-00002c0f" linkageExportForAS="true" linkageBaseClass="flash.display.Sprite" linkageClassName="MSprite" sourceLibraryItemHRef="Symbol 1" lastModified="1308864079" isSpriteSubclass="true">
  <timeline>
    <DOMTimeline name="MSprite">
      <layers>
        <DOMLayer name="Layer 1" color="#4FFF4F" current="true" isSelected="true">
          <frames>
            <DOMFrame index="0" keyMode="9728">
              <elements>
                <DOMShape>
                  <fills>
                    <FillStyle index="1">
                      <SolidColor color="#00CCFF"/>
                    </FillStyle>
                  </fills>
                  <strokes>
                    <StrokeStyle index="1">
                      <SolidStroke scaleMode="normal">
                        <fill>
                          <SolidColor/>
                        </fill>
                      </SolidStroke>
                    </StrokeStyle>
                  </strokes>
                  <edges>
                    <Edge fillStyle0="1" strokeStyle="1" edges="!6883 745S5[6369 340 5741 148!5741 148[5534 85 5314 78!5314 78[4037 36 2754 2!2754 2[1956 -18 1222 211!1222 211[693 376 393 745!393 745[139 1056 48 1512!48 1512[-130 2404 354 3085!354 3085[799 3713 1505 3927!1505 3927[1675 3979 1817 3876
!1817 3876[1970 3765 2071 3564!2071 3564|1474 3205!1474 3205[1230 2199 2029 1548!2029 1548[2144 1454 2274 1365!2274 1365|2834 1365!2834 1365|3194 1585!3194 1585|3254 1705!3254 1705|3434 2245!3434 2245|3514 2305!3514 2305[3652 1520 4512
 1353!4512 1353[5351 1190 5981 1839!5981 1839[6054 1915 6115 1995!6115 1995[6394 2358 6314 2845!6314 2845[6188 3617 6664 4084!6664 4084[6710 4129 6761 4171!6761 4171[6898 4282 7071 4308!7071 4308[7421 4359 7733 4184!7733 4184[7760 4134
 7785 4084!7785 4084[8238 3170 7920 2182!7920 2182[7733 1598 7325 1156!7325 1156[7115 929 6883 745"/>
                    <Edge cubics="!5741 148(;5603,106 5461,83 5314,78q5741 148Q5534 85q5314 78);"/>
                    <Edge cubics="!5981 1839(;6030,1890 6074,1942 6115,1995q5981 1839Q6054 1915q6115 1995);"/>
                    <Edge cubics="!6115 1995(;6301,2237 6367,2520 6314,2845q6115 1995Q6394 2358q6314 2845);"/>
                    <Edge cubics="!6761 4171(;6852,4245 6956,4291 7071,4308q6761 4171Q6898 4282q7071 4308);"/>
                    <Edge cubics="!6314 2845(;6230,3363 6348,3778 6664,4084q6314 2845Q6188 3617q6664 4084);"/>
                    <Edge cubics="!6664 4084(;6699,4118 6729,4145 6761,4171q6664 4084 6761 4171);"/>
                    <Edge cubics="!7733 4184(;7751,4152 7768,4119 7785,4084q7733 4184 7785 4084);"/>
                    <Edge cubics="!7785 4084(;8086,3476 8132,2842 7920,2182q7785 4084Q8238 3170q7920 2182);"/>
                    <Edge cubics="!4512 1353(;5071,1244 5561,1406 5981,1839q4512 1353Q5351 1190q5981 1839);"/>
                    <Edge cubics="!7071 4308(;7304,4342 7525,4301 7733,4184q7071 4308Q7421 4359q7733 4184);"/>
                    <Edge cubics="!7920 2182(;7795,1793 7597,1451 7325,1156q7920 2182Q7733 1598q7325 1156);"/>
                    <Edge cubics="!7325 1156(;7188,1007 7043,872 6883,745q7325 1156Q7115 929q6883 745);"/>
                    <Edge cubics="!6883 745(;6546,478 6163,277 5741,148q6883 745Q6369 340q5741 148);"/>
                    <Edge cubics="!2029 1548(;2106,1485 2187,1424 2274,1365q2029 1548Q2144 1454q2274 1365);"/>
                    <Edge cubics="!2834 1365(;2834,1365 3194,1585 3194,1585q2834 1365 3194 1585);"/>
                    <Edge cubics="!2274 1365(;2274,1365 2834,1365 2834,1365q2274 1365 2834 1365);"/>
                    <Edge cubics="!2754 2(;2222,-11 1711,58 1222,211q2754 2Q1956 -18q1222 211);"/>
                    <Edge cubics="!3254 1705(;3254,1705 3434,2245 3434,2245q3254 1705 3434 2245);"/>
                    <Edge cubics="!3434 2245(;3434,2245 3514,2305 3514,2305q3434 2245 3514 2305);"/>
                    <Edge cubics="!1505 3927(;1618,3962 1722,3945 1817,3876q1505 3927Q1675 3979q1817 3876);"/>
                    <Edge cubics="!1222 211(;870,321 594,498 393,745q1222 211Q693 376q393 745);"/>
                    <Edge cubics="!393 745(;224,951 109,1207 48,1512q393 745Q139 1056q48 1512);"/>
                    <Edge cubics="!1474 3205(;1311,2534 1496,1982 2029,1548q1474 3205Q1230 2199q2029 1548);"/>
                    <Edge cubics="!3194 1585(;3194,1585 3254,1705 3254,1705q3194 1585 3254 1705);"/>
                    <Edge cubics="!48 1512(;-71,2107 31,2631 354,3085q48 1512Q-130 2404q354 3085);"/>
                    <Edge cubics="!354 3085(;651,3504 1034,3784 1505,3927q354 3085Q799 3713q1505 3927);"/>
                    <Edge cubics="!3514 2305(;3606,1782 3939,1464 4512,1353q3514 2305Q3652 1520q4512 1353);"/>
                    <Edge cubics="!5314 78(;4463,50 3609,25 2754,2q5314 78Q4037 36q2754 2);"/>
                    <Edge cubics="!2071 3564(;2071,3564 1474,3205 1474,3205q2071 3564 1474 3205);"/>
                    <Edge cubics="!1817 3876(;1919,3802 2004,3698 2071,3564q1817 3876Q1970 3765q2071 3564);"/>
                  </edges>
                </DOMShape>
              </elements>
            </DOMFrame>
          </frames>
        </DOMLayer>
      </layers>
    </DOMTimeline>
  </timeline>
</DOMSymbolItem>

这证明了创建一个可以将 XML 代码移植到 AS3 的实用程序当然是可能的。这样一来,AS3 开发人员就不必担心处理矢量资源,尤其是当他们从 Flash Professional 迁移到 Flash Builder 时。

就个人而言,如果还没有可用的实用程序,我有兴趣最终为此创建一个实用程序,但我想知道是否已经有可用的实用程序?


[编辑]

自从我发布了这个问题后,我了解到 SVG Web 项目,它包含一个 ActionScript 3.0 分支,用于读取 SVG 数据并将其添加到显示列表中。该库允许开发人员创建 SVG 图形并将源代码嵌入为 XML 文字。虽然这仍然没有打开使用绘图 API 简单地编辑图形的可能性,但编辑 SVG XML 并没有那么困难,并且可以避免在 Flash Builder 中使用 .swf 资源来制作图形。该库并不完美,我花了很短的时间使用它,我了解到它似乎无法渲染超过 2 种颜色的径向渐变,并且它不允许缩放(看起来你只能更改宽度和高度属性,这既奇怪又非常不幸),但至少现在我可以包含图形代码而不是使用资产。

来源:com.zavoo.labs - New Flex and Flash SVGWeb Components

【问题讨论】:

  • 好问题。一直在想同样的事情
  • SO +1 的精彩补充。不过,恐怕这超出了我的理解范围。

标签: xml flash actionscript-3 graphics translation


【解决方案1】:

我不知道有什么方法可以转换用于在 XFL 文件结构中存储 MovieClips 的 XML 文件。如果您尝试将 Flash IDE 资源制作到 Flash Builder 中的 ActionScript 项目中,您可以将它们导出为 SWC 文件。如果您真的想创建一个转换工具,您可以尝试从 FXG 文件转换为绘图 API 版本。 FXG 格式在描述路径的方式上与 SVG 相似。该符号应该易于转换为 Flash 的 drawPath 命令和数据。

当您使用它时,您可以为 HTML5 画布移植代码。

【讨论】:

  • 创建和导出用于 FB 的 Flash IDE .swc 文件是我想要避免的。这样做是当前的标准方法,但它并不完全优雅。我可能是错的,但我相信上面的 XML 是一个 FXG - 两者都支持会很棒,但 SVG 可以在 Adob​​e 的工具集之外创建,所以如果只能支持一个,它应该是 SVG。
【解决方案2】:

就个人而言,目前我更喜欢 .swc 方法,因为您会得到一个较小的文件大小,因为您最终会得到一个压缩的二进制文件,并且只有稍后在 actionscript 中需要的资产可用。

如果组/绘图对象/图形符号有名称/ID,那就太好了,但目前没有。这意味着要走 xml 路线,您将加载一个大文件并遍历它以获取您需要的部分(除非您导出单独的 xml 文件)。

XFL 将是整个文档。我建议文件 > 导出图像 > FXG,因为您可以导出单个资产。已经有一个as3 FXGParser,我之前有used,它非常好。

目前,FXG、SWC 或 SWF(使用 @Claus Wahlers 的精彩 AS3SWF 库)可能是从 as3 访问设计器资产的不错方式。

据我了解,在 Flash Builder 项目中使用 XFL 作为资产将省去将资产从 Flash Professional/Authoring 编译/导出为其他格式的额外步骤。可以直接使用设计器 XFL(也可以对其进行适当的版本化),而不是具有中间工作流程步骤和格式,这很有趣。我唯一关心的是处理大型/凌乱且难以管理的 xfl 文件(是的,设计师通常对他们的资产感到“凌乱”)。

不幸的是,XFL 并不完全是 FXG,而且还没有可用的 XFL 规范(不过有一个用于 FXG 的规范)。 在XFL specsXFL Edge definitions 上查看这些答案。 要么有人需要亲自动手并逆向工程/记录 XFL 格式,要么等待 Adob​​e 去做。后者基本上意味着淹没feature request formforums,联系evangelistscampaigning,直到他们这样做。据我所知,如果 LOT 人觉得这很有用,我想 Adob​​e 会愿意为此投入时间。

简而言之,拥有一个体面的库来解析/搜索/获取 XFL 文件中的资产可能非常方便,从长远来看,能够从其他工具导入/导出 XFL 将是有益的。

【讨论】:

  • 感谢您的信息。我认为拥有像我提出的解决方案的好处是,开发人员可以在运行时生成他们的图形,而不是处理显示资产——如果显示资产是一个相当简单的矢量形状,但又足够复杂以至于不能或者愿意使用绘图 API 代码从头开始准确地绘制它。太糟糕了,AS3 不能将上面的 分配给 XML 作为 Shape 或类似的东西。
【解决方案3】:

ActionScript Viewer 在 3.1 及更高版本(2002 年发布)中具有该功能。该工具不是免费的。

他们所做的是解析以 SWF 格式存储的矢量图形。

引自他们的绘画课(由 Peter Joel 撰写):

    The data array is a special format, which can be obtained from graphics in a swf, using
    It is structured as a list of commands, which correspond to the movieClip methods moveTo, 
lineTo etc. Each command is a two-element array. The first element is a string, indicating the
type of command and the second element is another array, containing arguments. The following 
commands are supported:
    ['M',[x,y]]  -  moveTo(x,y)
    ['L',[x,y]]  -  lineTo(x,y)
    ['C',[cx,cy,ax,ay]]  -  moveTo(cx,cy,ax,ay)
    ['S',[th,col,alph]]  -  lineStyle(th,col,alph)
    ['F',[col,alph]]  -  beginFill(col,alph)
    ['EF']  -  endFill()
    ['GF',[a,b,c,d,e,f]]  -  beginGradientFill(a,b,c,d,e,f)

输出可能如下所示(此处为 ASV5 的示例输出):

//Created by Action Script Viewer - http://www.buraks.com/asv
//ASVDrawing Data format specification by Peter Hall (http://www.peterjoel.com)
//See ASV help file for more information.
//bounding rectangle (95,69) (427,327)
var data=new Array(['S',[1,0xFF0000,100]],['M',[426.5,132.5]],['L',[426.5,326.5]],['L',[358.5,326.5]]
,['L',[358.5,246.5]],['L',[249.5,246.5]],['L',[249.5,305.5]],['L',[157.5,305.5]],['L',[157.5,246.5]],['L',[116.5,246.5]]
,['L',[116.5,177.5]],['L',[95.5,177.5]],['L',[95.5,69.5]],['L',[414.5,69.5]],['L',[414.5,132.5]],['L',[426.5,132.5]]
,['M',[414.5,132.5]],['L',[414.5,177.5]],['L',[358.5,177.5]],['L',[358.5,246.5]],['M',[157.5,246.5]],['L',[157.5,177.5]]
,['L',[116.5,177.5]],['M',[249.5,246.5]],['L',[249.5,177.5]],['L',[157.5,177.5]],['M',[358.5,177.5]],['L',[249.5,177.5]]
);

或者

//Created by Action Script Viewer - http://www.buraks.com/asv
//bounding rectangle (95,69) (427,327)
lineStyle(1,0xFF0000,100);
moveTo(426.5,132.5);
lineTo(426.5,326.5);
lineTo(358.5,326.5);
lineTo(358.5,246.5);
lineTo(116.5,246.5);
moveTo(414.5,132.5);
// ......

在我看来,ASV 是一个不错的工具,尽管它没有定期更新。我记得它是市场上最可靠的反编译器的日子。 :)

如果您打算自己实现类似的东西,您可能会发现this great explanation of SWF file format 很有用。

【讨论】:

    【解决方案4】:

    我刚刚了解了Drawscript,这是一个 Adob​​e Illustrator 扩展,可以将绘图转换为 AS3、C++、JavaScript 等的代码,看起来很有前途。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-25
      相关资源
      最近更新 更多