/** * Copyright (c) 2006 Peter Goodman * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php */ //-------------------------------------------- // Import needed classes. //-------------------------------------------- import FA.*; //-------------------------------------------- // Global variable to keep track of the levels/depths // (which one?) of movie clips. Whatever is put // will be the base level that the first movie // clip created starts at. //-------------------------------------------- FA.Globals.set('mc_level', 10); //-------------------------------------------- // Global variable to keep track of all movie clips // created and their appropriate scopes. An example // of what is stored is: 'mc_name' => '_root.mc_name' //-------------------------------------------- FA.Globals.set('mc_cache', { }); //-------------------------------------------- // Global variable to keep track of the x and y positions // of all dynamically created movie clips on the stage. //-------------------------------------------- FA.Globals.set('mc_positions', { }); //-------------------------------------------- // Set the object of all of our subclasses so // that there is only 1 instance of the subclasses. //-------------------------------------------- FA.Globals.set('fa_query_subclasses', [ new FA.build.fn(), new FA.build.fx(), new FA.build.draw_fns(), new FA.build.mc(), new FA.build.xml_fns(), new FA.build.evt() ]); //-------------------------------------------- // The function that we use to access strings, objects, // and other nice things. //-------------------------------------------- _global.$ = function (thing, scope) : FA.Query { var object; var dirty:Boolean = false; //-------------------------------------------- // Look at the different types of what is being // passed to the FA.Query class. //-------------------------------------------- switch ((typeof thing).toLowerCase()) { //-------------------------------------------- // We are passing an object to it. //-------------------------------------------- case 'array': case 'movieclip': case 'textfield': case 'object': { //-------------------------------------------- // This object happens to be an FA.Query instance. // Let's get the object that this FA.Query instance // modifies and use it. //-------------------------------------------- if (thing instanceof FA.Query) { thing = thing.get(); } object = thing; break; } //-------------------------------------------- // A string is being passed. //-------------------------------------------- case 'string': { if(thing.indexOf(',') != -1) { var mc_names:String = thing.split(','); var objects:Array = []; for(var i = 0; i < mc_names.length; i++) { objects.push($(mc_names[i]).get()); } object = objects; } else { //-------------------------------------------- // Make sure we're in the right scope to be // looking for movie clips. //-------------------------------------------- var mc_scope:MovieClip = scope || _root; if (mc_scope[thing] != undefined) { //-------------------------------------------- // Hooray! This movie clip exists. We'll use it. //-------------------------------------------- object = mc_scope[thing]; } else { //-------------------------------------------- // The movie clip doesn't exist in the root so // see if we've created this movie clip and if // its ancestry is stored in the mc_cache global //-------------------------------------------- var mc_clip_cache:Object = FA.Globals.get('mc_cache'); if(mc_clip_cache[thing] != undefined) { object = eval("" + mc_clip_cache[thing] + ""); if(!(object instanceof MovieClip)) { dirty = true; object = null; } } else { //-------------------------------------------- // Uh oh. //-------------------------------------------- dirty = true; } } } break; } default: { //-------------------------------------------- // Uh oh. //-------------------------------------------- dirty = true; } } return new FA.Query(object, dirty); }; //-------------------------------------------- // Make it so that functions where the _object is // not needed can be called via $.function_name() //-------------------------------------------- _global.$.__resolve = function (method_name:String) : Function { return (new FA.Query(null, true)).__resolve(method_name); }; //-------------------------------------------- // setTimout function, thanks Senocular! // source: http://www.actionscript.org/forums/showpost.php3?p=116265&postcount=3 //-------------------------------------------- _global.setTimeout = function (a, b, c, args) { // for a basic function call: if (arguments[0].constructor == Function) { args = arguments.slice(2); var id, func = function() { a.apply(null, args); clearInterval(id); }; id = setInterval(func, b, args); // for an object method call: } else { args = arguments.slice(3); var id, func = function() { a[b].apply(a, args); clearInterval(id); }; id = setInterval(func, c, args); } return id; }; _global.clearTimeout = clearInterval;