/** * Copyright (c) 2006 Peter Goodman * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php */ //-------------------------------------------- // A class to deal with managing movie clip related // stuff. //-------------------------------------------- class FA.build.mc extends FA.Query { //-------------------------------------------- // Recursively get the ancestry of a movie clip. // This function is private. //-------------------------------------------- private function recursiveGetObjectParent (some_objects) : String { var ancestry:String = ''; if (some_objects._parent != undefined and some_objects._parent instanceof MovieClip) { if (some_objects._parent._name != '') { ancestry += '.' + some_objects._parent._name; ancestry += this.recursiveGetObjectParent(some_objects._parent); } } return ancestry; } //-------------------------------------------- // Private function to cache the ancestry of a // movie clip. //-------------------------------------------- private function cacheMovieClip (movie_clip) { //-------------------------------------------- // Cache the route to this movie clip in the globals // singleton. //-------------------------------------------- var mc_clip_cache:Object = FA.Globals.get('mc_cache'); if (mc_clip_cache[movie_clip._name] == undefined) { var ancestors:Array = this.recursiveGetObjectParent(movie_clip).split('.'); ancestors.reverse(); var ancestry:String = ('_root.' + ancestors.join('.')).substr(0, -1); if(ancestry != '_root') { mc_clip_cache[movie_clip._name] = ancestry + '.' + movie_clip._name; FA.Globals.set('mc_cache', mc_clip_cache); } } } //-------------------------------------------- // Create a return an existing movie clip object. //-------------------------------------------- public function movieClip (mc_name) : MovieClip { var movie_clip; if (_object instanceof MovieClip) { //-------------------------------------------- // If this movie clip does not exist under this // parent, or the parent object that we are // modifying _is_ this movie clip, then make/overwrite // it. //-------------------------------------------- if (!_object[mc_name] or _object._name == mc_name) { var mc_level:Number = FA.Globals.get('mc_level')+1; _object.createEmptyMovieClip(mc_name, mc_level); FA.Globals.set('mc_level', mc_level); } movie_clip = _object[mc_name]; this.cacheMovieClip(movie_clip); } return movie_clip; } //-------------------------------------------- // Duplicate a movie clip. //-------------------------------------------- public function duplicate (duplicate_name:String) : MovieClip { var movie_clip; if (_object instanceof MovieClip) { var mc_level:Number = FA.Globals.get('mc_level')+1; _object.duplicateMovieClip(duplicate_name, mc_level); FA.Globals.set('mc_level', mc_level); movie_clip = _object._parent[duplicate_name]; this.cacheMovieClip(movie_clip); } return movie_clip; } //-------------------------------------------- // Mask one movie clip with another. //-------------------------------------------- public function mask (maskee:String, masker:String) : FA.Query { if (_object instanceof MovieClip) { var maskee_is_valid:Boolean = _object[maskee] != undefined and _object[maskee] instanceof MovieClip; var masker_is_valid:Boolean = _object[masker] != undefined and _object[masker] instanceof MovieClip; if (maskee_is_valid and masker_is_valid) { _object[maskee].setMask(_object[masker]); } } return this; } //-------------------------------------------- // Create a text field object and apply any formatting // to it. To use this function, pass an object with whatever // formatting you want to be applied to the text. This includes // the things you find in the TextField and TextFormat objects. //-------------------------------------------- public function text (formatting_or_text) : TextField { var return_val = this; if (_object instanceof MovieClip) { var formatting:Object = formatting_or_text; //-------------------------------------------- // Create the text field. //-------------------------------------------- var mc_level:Number = FA.Globals.get('mc_level')+1; _object.createTextField(t._name, mc_level, t._x, t._y, t._width, t._height); FA.Globals.set('mc_level', mc_level); //-------------------------------------------- // Get the text field and create a format for it. //-------------------------------------------- var text_field:TextField = _object[t._name]; var text_format:TextFormat = new TextFormat(); // hack to use object notation to forgoe an in_array function var n = true; var valid_formats:Object = { align: n, blockIndent: n, bold: n, bullet: n, color: n, font: n, indent: n, italic: n, leading: n, leftMargin: n, rightMargin: n, tabStops: n, target: n, size: n, underline: n, url: n }; //-------------------------------------------- // Loop through the formatting object passed to // the function and apply it to the text. //-------------------------------------------- for (var format in formatting) { if (valid_formats[format]) { text_format[format] = formatting[format]; } else { text_field[format] = formatting[format]; } } text_field.setTextFormat(text_format); //-------------------------------------------- // Set the return value. //-------------------------------------------- return_val = text_field; } //-------------------------------------------- // If we're in an XML object, then create a text // node. //-------------------------------------------- else if (_object instanceof XML) { _object.createTextNode(formatting_or_text); } return return_val; } //-------------------------------------------- // Load a movie into the current movie clip. The // parameter passed is an object with keys 'url' // and 'method' or 'variables', depending on a // user's preference. //-------------------------------------------- public function movie (movie_info:Object) : FA.Query { if(_object instanceof MovieClip) { var variables = undefined; if(movie_info.method or movie_info.variables) { variables = movie_info.method || movie_info.variables; } _object.loadMovie(movie_info.url, variables); } return this; } //-------------------------------------------- // Unload a movie. //-------------------------------------------- public function unmovie () : FA.Query { if (_object instanceof MovieClip) { _object.unloadMovie(); } return this; } //-------------------------------------------- // Attach audio to this movie clip. //-------------------------------------------- public function audio (source) : FA.Query { if (_object instanceof MovieClip) { _object.attachAudio(source); } return this; } //-------------------------------------------- // Detach audio from this movie clip. //-------------------------------------------- public function unaudio () : FA.Query { this.audio(false); return this; } }