Packagecom.soma.utils
Classpublic class SomaUtils

Author: Romuald Quantin - www.soundstep.com

Information:
Blog page - SomaUI
How does it work - Soma Protest
Project Host - Google Code
Documentation - Soma ASDOC
Class version: 2.0
Actionscript version: 3.0

Copyright:

The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied.
See the License for the specific language governing rights and
limitations under the License.

The Original Code is Soma.
The Initial Developer of the Original Code is Romuald Quantin.
Initial Developer are Copyright (C) 2008-2009 Soundstep. All Rights Reserved.

Usage:
SomaUtils is static utility class containing some methods that might help in every project.



Public Methods
 MethodDefined by
  
SomaUtils is a static class, trying to create an instance will throw an Error, instead use the method this way: SomaUtils.stringToBoolean("true")
SomaUtils
  
getRootURL(container:DisplayObjectContainer):String
[static] Get the URL of a Flash Movie.
SomaUtils
  
killCache(url:String):String
[static] Get a modified URL to force the browser to load a file and never use its cache (the trick is using a Date in miliseconds as a param), can be useful for XML or any files.
SomaUtils
  
setBaseUIProperties(target:DisplayObject, baseUI:BaseUI, node:XML):void
[static] Set BaseUI values (such as top, ratio, horizontalCenter, and so on) to a DisplayObject, it will add the DisplayObject in the BaseUI instance if not found.
SomaUtils
  
setProperties(target:Object, node:XML, exception:Array = null):void
[static] Set values to the properties of an Object (can be anything) using an XML node.
SomaUtils
  
[static] Trace in the output the list of the fonts embedded in the flash movie.
SomaUtils
  
stringToBoolean(value:String):Boolean
[static] Cast a String value to a Boolean.
SomaUtils
Constructor detail
SomaUtils()constructor
public function SomaUtils()

SomaUtils is a static class, trying to create an instance will throw an Error, instead use the method this way: SomaUtils.stringToBoolean("true")

Method detail
getRootURL()method
public static function getRootURL(container:DisplayObjectContainer):String

Get the URL of a Flash Movie. For example if have a movie Main.swf located on http://www.server.com/Main.swf, add this code in the main class to get its URL:

   trace(SomaUtils.getRootURL(this)); // will trace http://www.server.com/
   

Parameters
container:DisplayObjectContainer — A DisplayObject instance (for example the main class).

Returns
String — A String (URL).
killCache()method 
public static function killCache(url:String):String

Get a modified URL to force the browser to load a file and never use its cache (the trick is using a Date in miliseconds as a param), can be useful for XML or any files.

   var urlToLoad:String = "http://www.server.com/file.xml";
   var urlToLoadModified:String = SomaUtils.killCache(urlToLoad);
   

Parameters
url:String — A String (URL).

Returns
String — A String (URL).
setBaseUIProperties()method 
public static function setBaseUIProperties(target:DisplayObject, baseUI:BaseUI, node:XML):void

Set BaseUI values (such as top, ratio, horizontalCenter, and so on) to a DisplayObject, it will add the DisplayObject in the BaseUI instance if not found.

   SomaUtils.setProperties(mySprite, instanceBaseUI, new XML('<node width="80%" top="10" bottom="10"/>'));
   

Parameters
target:DisplayObject — A DisplayObject (such as Sprite, Bitmap, etc).
 
baseUI:BaseUI — A BaseUI instance.
 
node:XML — A XML node describing the BaseUI properties and values.
setProperties()method 
public static function setProperties(target:Object, node:XML, exception:Array = null):void

Set values to the properties of an Object (can be anything) using an XML node.

   SomaUtils.setProperties(mySprite, new XML('<node x="10" alpha="1" visible="true" name="mySpriteName" mouseChildren="false"/>'), ['mouseChildren']);
   

Parameters
target:Object — A Object (can be a class, a Sprite or anything).
 
node:XML — A XML node describing the properties and values.
 
exception:Array (default = null) — An Array of property names that won't be applied to the target.
showEmbeddedFonts()method 
public static function showEmbeddedFonts():void

Trace in the output the list of the fonts embedded in the flash movie.

   SomaUtils.showEmbeddedFonts();
   

stringToBoolean()method 
public static function stringToBoolean(value:String):Boolean

Cast a String value to a Boolean.

trace(SomaUtils.stringToBoolean("0")); // return a Boolean false
trace(SomaUtils.stringToBoolean("1")); // return a Boolean true
trace(SomaUtils.stringToBoolean("false")); // return a Boolean false
trace(SomaUtils.stringToBoolean("true")); // return a Boolean true
trace(SomaUtils.stringToBoolean("whatever")); // return a Boolean false
   

Parameters
value:String — A String.

Returns
Boolean — A Boolean.