Skip to content

Instantly share code, notes, and snippets.

@alamboley
Last active October 12, 2015 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamboley/4022014 to your computer and use it in GitHub Desktop.
Save alamboley/4022014 to your computer and use it in GitHub Desktop.
How to access game's graphics (Citrus Engine recipe)
// Citrus object's view management is powerful: when a view is added to the object it is loaded and added to a template
// called SpriteArt which is a container of your art. This template allows to load external files thanks to their path.
// It works the same way with Starling.
var _hero:Hero = new Hero("my hero", {view:"myHero.swf"});
// _hero.view refers to the path "myHero.swf" not to the swf loaded.
// If the view specified is a DisplayObject, you can directly make whatever you want on it (filter, blendMode, ect).
var _heroGraphic:SpriteArt = view.getArt(_hero) as SpriteArt;
// _heroGraphic is the container of the art. It will loads and display the art. Most often you will work with this.
trace((view.getArt(_hero) as SpriteArt).content); // it will trace null, because your swf isn't loaded at this time.
// If your art is an external file you have to be sure it is loaded:
_heroGraphic.loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleHeroLoaded);
private function handleHeroLoaded(e:Event):void {
// the swf is loaded, you have direct access to it.
_heroGraphic.content.alpha = .5;
}
/*Now technically, you could have set the hero graphic's alpha in the initialize() function,
because the SpriteArt object is a wrapper for the actual MovieClip graphic that represents your loaded SWF.
Since the SpriteArt object is created right away, this will also work in the initialize() function:*/
_heroGraphic = view.getArt(_hero) as SpriteArt;
_heroGraphic.alpha = .5;
// Using SWF you can also call some functions that you've defined. Note that it can't work with Starling!
private function handleHeroLoaded(e:Event):void {
MovieClip(_heroGraphic.content).setShirtColor(0xff0000);
}
/*The function setShirtColor() is a function that you would create on the first frame of your Hero graphic's FLA.
MovieClips will allow you to call dynamic functions such as setShirtColor().*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment