Reputation: 2077
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);
Upvotes: 0
Views: 2279
Reputation: 11
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;
}
}
}
Upvotes: 1
Reputation: 4782
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.
Upvotes: 1