访问加载的 SWF 文件中另一个剪辑中的剪辑

发布于 2024-08-23 11:44:33 字数 833 浏览 7 评论 0原文

我正在用 AS3 编写一个纸牌游戏。与我合作的艺术家(在 Flash CS4 中)制作了一个包含所有卡片图形和动画的 swf 文件。 fla 工作文件的结构如下所示:

- Scene
  - CardGraphics (Movie Clip)
    - CardFront
    - CardBack
    - CardValueImage (Movie Clip)
    ...

在程序中,我创建了 Card 类的 52 个实例,每个实例都有一个从加载的 swf 创建的 MovieClip 实例。这个想法是设置 CardValueImage MovieClip 的框架以对应于 Card 实例的suit 和rank 成员变量。但是,我无法弄清楚如何访问 CardValueImage 并调用 gotoAndStop (或我需要调用的任何方法)。

这基本上就是我想做的:

// Card Class
[Embed(source = 'CardGraphics.swf')]
private static var CardsClip:Class;
private var clip:MovieClip = new CardsClip;

// Card Constructor
this.valueImageFrame = suit * 13 + rank; // Calculate which frame contains the
                                         // graphical representation of this card
this.clip.CardValueImage.gotoAndStop(valueImageFrame);

I'm writing a card game in AS3. The artist I'm working with has produced (in Flash CS4) a single swf-file containing all the card graphics and animations. The structure of the fla working file looks something like this:

- Scene
  - CardGraphics (Movie Clip)
    - CardFront
    - CardBack
    - CardValueImage (Movie Clip)
    ...

In the program I create 52 instances of my Card class, each having a MovieClip instance created from the loaded swf. The idea is to set the frame of the CardValueImage MovieClip to correspond to the Card instance's suit and rank member variables. However, I can't figure out how I access CardValueImage and call gotoAndStop (or whatever method I will need to call).

This is basically what I want to do:

// Card Class
[Embed(source = 'CardGraphics.swf')]
private static var CardsClip:Class;
private var clip:MovieClip = new CardsClip;

// Card Constructor
this.valueImageFrame = suit * 13 + rank; // Calculate which frame contains the
                                         // graphical representation of this card
this.clip.CardValueImage.gotoAndStop(valueImageFrame);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨敛清荷 2024-08-30 11:44:33

尝试:

this.clip.getChildByName('CardValueImage').gotoAndStop(valueImageFrame);

我不确定 CardValueImage 是否是您在 CardGraphics 中的影片剪辑的实例名称,如果是,那么它应该可以工作:)

编辑:
要访问嵌入式 swf 的时间线,您需要不同的方法,留下代码示例和更详细解释它的博客文章。

package  
{
    import mx.core.ByteArrayAsset;

    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;

    public class App extends Sprite 
    {
        [Embed(source = '../assets/CardGraphics.swf', mimeType="application/octet-stream")]
        public static const CardsClip : Class;

        public var loader : Loader = new Loader;
        public var swfasset : ByteArrayAsset;
        public var clip : MovieClip;

        public function App()
        {
            swfasset = new CardsClip();
            loader.contentLoaderInfo.addEventListener(Event.INIT, loadCompleteListener, false, 0, true);
            loader.loadBytes(swfasset);
        }

        private function loadCompleteListener(e : Event) : void 
        {
            clip = MovieClip(loader.content);

            var cardsGraphics:MovieClip = MovieClip(clip.getChildByName('CardsGraphics'));
            var cardValueImage:MovieClip = MovieClip(cardsGraphics.getChildByName('CardValueImage'));

            cardValueImage.gotoAndStop(2);

            addChild(clip);
        }
    }
}

http://www.8bitrocket.com/newsdisplay.aspx?newspage=36607

*请注意,代码已更改以匹配您的场景。

try:

this.clip.getChildByName('CardValueImage').gotoAndStop(valueImageFrame);

i'm not sure if CardValueImage is the instance name of the movieclip that you have inside CardGraphics, if it is then it should work :)

EDIT:
to access the timeline of a embedded swf you need a different approach, leave a code example, and a blog post that explains it in more detail.

package  
{
    import mx.core.ByteArrayAsset;

    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;

    public class App extends Sprite 
    {
        [Embed(source = '../assets/CardGraphics.swf', mimeType="application/octet-stream")]
        public static const CardsClip : Class;

        public var loader : Loader = new Loader;
        public var swfasset : ByteArrayAsset;
        public var clip : MovieClip;

        public function App()
        {
            swfasset = new CardsClip();
            loader.contentLoaderInfo.addEventListener(Event.INIT, loadCompleteListener, false, 0, true);
            loader.loadBytes(swfasset);
        }

        private function loadCompleteListener(e : Event) : void 
        {
            clip = MovieClip(loader.content);

            var cardsGraphics:MovieClip = MovieClip(clip.getChildByName('CardsGraphics'));
            var cardValueImage:MovieClip = MovieClip(cardsGraphics.getChildByName('CardValueImage'));

            cardValueImage.gotoAndStop(2);

            addChild(clip);
        }
    }
}

http://www.8bitrocket.com/newsdisplay.aspx?newspage=36607

*note that the code was changed to match your scenario.

悲喜皆因你 2024-08-30 11:44:33

Object(a.contentLoaderInfo.content)

例如,如果您有一个 swf 并且想要访问实例名为 some_name 的元件。

 package {
        import flash.display.Loader;
        import flash.display.MovieClip;
        import flash.display.Sprite;
        import flash.events.Event;
        public class Main extends Sprite
            {
              [Embed(source="assets/YourMovie.swf", mimeType="application/x-shockwave-flash")]
              private var ClassName:Class

              private var mov:MovieClip
              private var symbolFromSWF:MovieClip
              public function Main()
              {
                mov=new ClassName();
                mov.addEventListener(Event.COMPLETE,onComp);
                addChild(mov);
              }
              protected function onComp(event:Event):void
              {
                var a:Loader=Loader(mov.getChildAt(0));
                symbolFromSWF=Object(a.contentLoaderInfo.content).some_name;
              }
         }
    }

Object(a.contentLoaderInfo.content)

For example, if you have a swf and want to access to a symbol with instance name some_name.

 package {
        import flash.display.Loader;
        import flash.display.MovieClip;
        import flash.display.Sprite;
        import flash.events.Event;
        public class Main extends Sprite
            {
              [Embed(source="assets/YourMovie.swf", mimeType="application/x-shockwave-flash")]
              private var ClassName:Class

              private var mov:MovieClip
              private var symbolFromSWF:MovieClip
              public function Main()
              {
                mov=new ClassName();
                mov.addEventListener(Event.COMPLETE,onComp);
                addChild(mov);
              }
              protected function onComp(event:Event):void
              {
                var a:Loader=Loader(mov.getChildAt(0));
                symbolFromSWF=Object(a.contentLoaderInfo.content).some_name;
              }
         }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文