Created
March 16, 2011 20:27
-
-
Save rafaelrinaldi/873240 to your computer and use it in GitHub Desktop.
Easy way to set the same properties set for multiple items.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tea.util | |
{ | |
/** | |
* | |
* Easy way to set the same properties set for multiple items. | |
* | |
* @param p_items Items to be processed. | |
* @param p_properties Properties to be setted. | |
* | |
* @example | |
* <pre> | |
* import flash.display.Sprite; | |
* | |
* import tea.util.batch; | |
* | |
* var firstSquare : Sprite, secondSquare : Sprite; | |
* | |
* firstSquare = createSquare(50, 50, 0x0); | |
* secondSquare = createSquare(150, 150, 0xCCCCCC).x = 100; | |
* | |
* batch([firstSquare, secondSquare], {alpha: .5, scaleX: .75, scaleY: .75}); | |
* | |
* function createSquare( p_width : Number, p_height : Number, p_color : Number ) : Sprite { | |
* var square : Sprite = new Sprite; | |
* square.graphics.beginFill(p_color, 1); | |
* square.graphics.drawRect(0, 0, p_width, p_height); | |
* square.graphics.endFill(); | |
* return square; | |
* } | |
* </pre> | |
* | |
* @date 16/03/2011 | |
* @author Rafael Rinaldi (rafaelrinaldi.com) | |
* | |
* */ | |
public function batch( p_items : Array, p_properties : Object ) : void | |
{ | |
var item : *, property : *; | |
var key : String; | |
for each(item in p_items) { | |
for(key in p_properties) { | |
property = String(p_properties[key]).toLowerCase(); | |
if(!isUnassigned(property)) { | |
if(item.hasOwnProperty(key)) item[key] = property; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment