views:

392

answers:

2

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);
A: 

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.

dome
I'm afraid the only child the clip has is a Loader object.
Anders
you are right, check again the answer above, i've updated with a different approach so you can gain access to the timeline of a embedded swf.
dome
Thanks for the help. I solved it setting CardGraphics to be exported as a class in Flash CS4 and publishing to a swc-file. That way I can skip using 'Embed' and simply create an instance of CardGraphics direcly. The CardValueImage clip appears as a property of CardGraphics and I can call gotoAndStop like so:var cg:CardGraphics = new CardGraphics;cg.CardValueImage.gotoAndStop(...);
Anders
A: 

I can't yet flag dome's answer as useful, but it did help me to migrate a Flash CS4 project using a Document class into Flash Builder.

Panax