使用类级别的嵌入访问MainTimeline符号 [英] Access MainTimeline symbol using class-level embed

查看:145
本文介绍了使用类级别的嵌入访问MainTimeline符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的情况:

我们有一个创意团队,工作在Flash CS5.5并产生在他们两个图形元素和动作code SWF资产,一个工程团队,作家。作为文件,并建立code主权财富基金。在code SWF文件必须加载或嵌入的广告资源,并与code其中为我们的应用程序的功能进行交互。

有关的iOS移动开发的,还有另一种考虑 - 这是不可能的加载运行code,因为苹果TOS的AIR应用程序包的iOS(见<一href="http://stackoverflow.com/questions/8688645/is-it-possible-to-embed-or-load-swfs-when-making-iphone-apps-is-it-allowed-by-a">related问题)。因此,它不可能使用Loader加载的SWF中在iOS环境,并保留其code

嵌入一个SWF到ActionScript文件的标准方式导致装载机直接加载嵌入的SWF以字节为单位。这会导致访问顶层,主时间线如下:

  [嵌入(来源=embed_test.swf)
  私人VAR no_aot_support:类;

公共函数main():无效
{
  VAR no_ios:* =新no_aot_support();
  的addChild(no_ios);
  no_ios.addEventListener(引发Event.COMPLETE,函数():无效{
    VAR时间表:影片剪辑= no_ios.getChildAt(0).getChildAt(0);
    跟踪(timeline.foo); // foo的变量存在,输出嗒嗒
  });
}
 

不过,这种嵌入机制不能在iOS设备上工作,因为runtime- code是不是每个苹果的服务条款允许的 - 所有的code必须通过提前 - - 时间的编译器(AOTCompiler)在编译传递-time,且SWF嵌入这种方式不符合此标准。

询问之下,我发现一个可以使用类级别的嵌入来解决这个问题,作为一类级别的嵌入并经过编译器,并会导致工作code的iOS下的:

 包
{
  进口的flash.display.MovieClip;

  [嵌入(来源=embed_test.swf,象征=符号1)
   公共动态final类动画扩展MovieClip的{};
}
 

这工作得很好,但我并不想引用一个符号的SWF,我想整个SWF(又名引用主时间轴),但在一个编译器错误,结果如下:

 包
{
  进口的flash.display.MovieClip;

  [嵌入(来源=embed_test.swf)
   公共动态final类动画扩展MovieClip的{};
}
 

我也反编译的SWF,发现主时间轴的象征,并尝试这样的:

 包
{
  进口的flash.display.MovieClip;

  [嵌入(来源=embed_test.swf,象征=embed_test_fla.MainTimeline)
   公共动态final类动画扩展MovieClip的{};
}
 

但是编译器坚持这个符号不存在。

因为我有很多很多的SWF资产,我需要的,不涉及改变我的整个工作流程的解决方案(即进入每个FLA,并进行更改)。这应该是可能的,如果不是,这是一个问题的工作流的Adobe应处理

所以在这里我坚持 - 定期EMBEDS得到MainTimeline,但没有在iOS的工作,类级别的嵌入工作,iOS和不能访问MainTimeline

随时下载我expample项目以及与此玩耍。

解决方案

我张贴我自己解决此问题的,在任何情况下发生此问题:

还有一个更详细的应对这里:<一href="http://stackoverflow.com/questions/8688645/is-it-possible-to-embed-or-load-swfs-when-making-iphone-apps-is-it-allowed-by-a/8916210#8916210">Is它可以嵌入或加载的主权财富基金时,使得iPhone应用程序(它是由苹果公司允许)

我已经创建了一个工具,通过合并嵌入式主权财富基金到主SWF以解决此问题。通过这种方式,在EMBEDS是AOT编译并转换成Objective-C的code,所以我让我的资产(主时间轴)的一个实例,以及资产的code是正确的交叉编译工作iOS设备。

它的工作原理通过使用嵌入这样的:

  [嵌入(来源=GameLevel.swf)
  私人VAR GameLevel:类;

公共函数main():无效
{
  VAR my_level:* =新GameLevel();
  的addChild(my_level);
}
 

在这种情况下,如果gameLevel.swf有code中,它通常不会在iOS的工作,因为新gameLevel()将创建一个Loader和跨preT SWF字节code。但是,如果你先通过我的工具,称为SWFMerge运行上面的SWF文件,它会采取嵌入式的SWF并将其合并到你的根SWF。然后,ADT将编译主SWF(包括嵌入式code)为目标C,它会工作在iOS,及注意事项:新gameLevel()现在的结果直接在您的资产的一个实例 - 不是一个Loader

该SWFMerge工具是在这里:

http://www.onetacoshort.com/temp/SWFMerge_alpha.swf

让我知道在评论,如果这个解决方法适合您,或者如果你有麻烦了。

我要补充一点,使用SWC工作流较好,官方支持,但这种解决办法是伟大的在紧要关头的时候,你要么不拥有原始的FLA源文件,或只是想快速使用带有$ C现有资产$ C在其中。

Here's the scenario:

We have a creative team that operates in Flash CS5.5 and produces SWF assets which have both graphics elements and actionscript code in them, and an engineering team which authors .as files and builds "code SWFs". The code SWF files must load or embed the creative assets and interact with the code therein for our apps to function.

For iOS mobile development, there is another consideration - it is not possible to load runtime code in an AIR app packages for iOS because of Apple TOS (see related question). Hence, it is not possible to use a Loader to load SWFs in an iOS environment and retain their code.

Embedding a SWF into an ActionScript file the standard way results in a Loader that loads the embedded SWF directly as bytes. This results in access to the top-level, main timeline as follows:

[Embed(source="embed_test.swf")]
  private var no_aot_support:Class;

public function main():void
{
  var no_ios:* = new no_aot_support();
  addChild(no_ios);
  no_ios.addEventListener(Event.COMPLETE, function():void {
    var timeline:MovieClip = no_ios.getChildAt(0).getChildAt(0);
    trace(timeline.foo); // foo variable exists, output is 'blah'
  });
}

However, this embedding mechanism doesn't work on iOS devices because runtime-code is not allowed per Apple's TOS - all code must be passed through the ahead-of-time compiler (AOTCompiler) at compile-time, and the SWF embedded in this way does not meet this criteria.

Asking around, I found that one can use a class-level embed to get around this, as a class-level embed does go through the compiler and will result in working code under iOS:

package
{
  import flash.display.MovieClip;

  [Embed(source="embed_test.swf", symbol="Symbol1")]
   public final dynamic class anim extends MovieClip { };
}

This works fine, but I don't want to reference a symbol in the SWF, I want the whole swf (aka reference the main timeline), but the following results in a compiler error:

package
{
  import flash.display.MovieClip;

  [Embed(source="embed_test.swf")]
   public final dynamic class anim extends MovieClip { };
}

I've also decompiled the SWF, found the main timeline symbol, and tried this:

package
{
  import flash.display.MovieClip;

  [Embed(source="embed_test.swf", symbol="embed_test_fla.MainTimeline")]
   public final dynamic class anim extends MovieClip { };
}

But the compiler insists this symbol doesn't exist.

Since I have many, many SWF assets, I need a solution that doesn't involve changing my whole workflow (i.e. going into each FLA and making changes). This should be possible, and if not, this is a workflow problem Adobe should address.

So here I am stuck - regular embeds get the MainTimeline but don't work in iOS, class-level embeds work in iOS and can't access the MainTimeline.

Feel free to download my expample project and play with this.

解决方案

I'm posting my own workaround to this problem, in case any happens by this question:

There is a more details response here: Is it possible to embed or load SWFs when making iphone apps (Is it allowed by Apple)

I've created a tool to workaround this issue by merging embedded SWFs into the main SWF. In this way, the embeds are AOT-compiled and converted into objective-c code, so I get an instance of my asset (the main timeline), and the asset's code is properly cross-compiled to work on iOS devices.

It works by using an embed like this:

[Embed(source="GameLevel.swf")]
  private var GameLevel:Class;

public function main():void
{
  var my_level:* = new GameLevel();
  addChild(my_level);
}

In this scenario, if gameLevel.swf has code in it, it typically wouldn't work in iOS, because new gameLevel() would create a Loader and interpret SWF bytecode. But, if you first run the above SWF through my tool called SWFMerge, it will take your embedded SWF and merge it into your root SWF. Then ADT will compile your main swf (including embedded code) into objective-C, it will work on iOS, and note: new gameLevel() now results directly in an instance of your asset - NOT a Loader.

The SWFMerge tool is here:

http://www.onetacoshort.com/temp/SWFMerge_alpha.swf

Let me know in the comments if this workaround works for you or if you have trouble.

I'll add that using a SWC workflow is better and officially supported, but this workaround is great in a pinch when you either don't have the original FLA source file, or simply want to quickly use existing assets with code in them.

这篇关于使用类级别的嵌入访问MainTimeline符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆