In Utils class we put all the usefull functions used to deal with medias and standard user interactions. in the repository : /trunk/core/Utils.as
1
Alexandre Hoyau
| org. | In Utils class we put all the usefull functions used to deal with medias and standard user interactions. |
| silex_ptr | Reference to silex main Api object (org.silex.core.Api). |
| Utils | Constructor. |
| Date and time accessors | to display today date as 08/02/14 : ((<<silex.utils.YY>>/<<silex.utils.MM>>/<<silex.utils.DD>>)) to display today date as monday 14 february : ((<<silex.utils.DAY>> <<silex.utils.DD>> <<silex.utils.MONTH>>)) |
| YY | the year on 2 digits (eg 08 for 2008) |
| MM | the month number on 2 digits (eg 01 for january) |
| DD | the day number on 2 digits (eg 08 for 8th day of the month) |
| HH | the hour (from 0 to 23) on 2 digits |
| HH12 | the hour (from 0 to 12) on 2 digits |
| MMIN | the minutes (from 0 to 59) on 2 digits |
| YEAR | the year on 4 digits (eg 2008) |
| DAY | dependent on the language config |
| MONTH | dependent on the language config |
| HOUR | the hour (from 0 to 23) |
| HOUR12 | the hour (from 0 to 12) |
| AMPM | AM or PM |
| MINUT | the minutes (from 0 to 59) |
| Conversions | |
| getRawTextFromHtml | Convert an html formated text into a raw text (removes all tags). |
| cleanID | Remove unwanted chars from ID. |
| addslashes | Add slashes to a string before characters that need to be quoted in database queries etc. |
| formatNumberWithNDigits | Convert num into string and adds 0s before it so that it has nDigits numbers. |
| User interaction windows | |
| lastOpenedAlertSimpleName | Name of the last opened alertSimple dialog box. |
| alert | Display a message in a dialog box. |
| alertSimple | Display a message without a dialog box. |
| confirm | Display a question in a dialog box with “ok” and “cancel” buttons. |
| prompt | Ask the user to write a string. |
| promptPassword | Ask the user to login |
| swf related functions | |
| getRootUrl | Takes the url from which _root was downloaded, remove the file name and return the url of the folder from which _root was downloaded. |
| getTarget | retrieve an object from its path, starting in a given MovieClip |
| media functions | |
| loadingMedias | Array which contains all the files and streams being downloaded. |
| resizeMedia | Resize the given movie clip so that it fits the rectangle and it keeps the same width/height ratio. |
| centerMedia | Center a movie clip in a specifyed zone or container. |
| loadMedia | Loads a media into a container. |
| trace | Custom trace function. |
| dump | Dump an object recursively. |
| obj2json | Serialize an object recursively into a json string |
| strings utilities | |
| replace | Replace a string by another string in the source string. |
| deaccent | Replace accented UTF-8 characters by unaccented ASCII-7 equivalents. |
| splitTags | Use the accessors delimiters paterns to split the input string into an array. |
| revealAccessors | Replaces accessors by their values in a String. |
| revealWikiSyntax | Reveal wiki tags. |
| processWikiImageTag | Reveal images. |
| processWikiLinkTag | Reveal links. |
| processWikiLinkTagCallback | Callback function executed when the user clicks on a link in a text. |
| revealTags | Reveal all wiki tags or accessors contained in a string. |
| validators | |
| checkValidMail | Mail validation. |
| arrays utilities | |
| isPartOf | check if an array is part of another array |
| effects | |
| applyTypeWriterEffect | Typewriter effect. |
| removeTypeWriterEffect | Remove the effect from the TextFiled |
| createDelegate | Creates a functions wrapper for the original function so that it runs in the provided context.<br/> You can pass parameters to the function @parameter obj Context in which to run the function. |
function cleanID( id: String ):String
Remove unwanted chars from ID. Cleans a given ID to only use allowed characters. Accented characters are converted to unaccented ones. Comes from dokuwiki inc/pageutils.php. @example filterSectionName(“my Section. NAME”) returns “my_section._name”
| param | raw_id The pageid to clean |
function addslashes( _str: String ):String
Add slashes to a string before characters that need to be quoted in database queries etc. These characters are single quote (‘), double quote (“), backslash (\).
| param | _str the string to which to add the slashes |
a string with backslashes before characters that need to be quoted in database queries etc.
function formatNumberWithNDigits( num: Number, nDigits: Number ):String
Convert num into string and adds 0s before it so that it has nDigits numbers.
| param | num the number to convert |
| param | nDigits the number of digits which the output string will have |
a string with nDigits digit and which represents the input number
public function alert( text_str: String, cbkFunction: Function ):MovieClip
Display a message in a dialog box. when the user closes the window (click on “ok” button or on “close” button), the desired callback function is called.
| text_str | the text to be displayed (the message) |
| cbkFunction | the callback function to be called when the user closes the window |
the dialog box (use it to force the dialog box to close for example)
public function alertSimple( text_str: String, time_num: Number, cbkFunction: Function ):MovieClip
Display a message without a dialog box.
| text_str | the text to be displayed (the message) |
| time_num | duration in milliseconds for the message to be displayed |
| cbkFunction | the callback function to be called when the time has elapsed |
the dialog box (use it to force the dialog box to close for example)
public function confirm( text_str: String, cbkFunction: Function ):MovieClip
Display a question in a dialog box with “ok” and “cancel” buttons. When the user closes the window (click on “ok” button or on “close” button or “cancel” button), the desired callback function is called.
| text_str | the text to be displayed (the message) |
| cbkFunction | the callback function to be called when the user closes the window |
the dialog box (use it to force the dialog box to close for example)
public function prompt( text_str: String, default_str: String, cbkFunction: Function ):MovieClip
Ask the user to write a string. when the user closes the window (click on “ok” button or on “close” button or “cancel” button), the desired callback function is called.
| text_str | the text to be displayed (the message) |
| default_str | the default string to be displayed before the user modify it |
| cbkFunction | the callback function to be called when the user closes the window |
the dialog box (use it to force the dialog box to close for example)
public function promptPassword( text_str: String, cbkFunction: Function ):MovieClip
Ask the user to login
| text_str | the text to be displayed (the message) |
| cbkFunction | the callback function to be called when the user closes the window |
the dialog box (use it to force the dialog box to close for example)
public function getTarget( source_mc/*: Object*/, path_str: String, separator: String ):Object
retrieve an object from its path, starting in a given MovieClip
| param | source_mc the object in which to start looking for the target |
| param | path_str the target path starting in the source MovieClip |
| param | separator the separator used for inclusion in the notation (path.to.a.variable or path/to/a/variable) - default is “.” |
the targeted object
public function resizeMedia( target_mc: MovieClip, w: Number, h: Number ):Number
Resize the given movie clip so that it fits the rectangle and it keeps the same width/height ratio.
| target_mc | the movie clip to be resized |
| w | the maximum width that the media can have |
| h | the maximum height that the media can have |
the ratio by which the media has been resized
public function centerMedia( target_mc, w: Number, h: Number, delta_x: Number, delta_y: Number )
Center a movie clip in a specifyed zone or container.
| target_mc | movie clip to be centered |
| w | container’s width |
| h | container’s height |
| delta_x | optional - container’s upper left corner x-coordinate |
| delta_y | optional - container’s upper left corner y-coordinate |
public function loadMedia( url_str: String, target_mc: MovieClip, resObj: Object, container_rect: Object, resize_bool: Boolean, center_bool: Boolean )
Loads a media into a container. the media can be of any type (jpg, swf, mp3, flv, and other once the frame development will be done). While downloading, the media will be referenced in an object stored in loadingMedias. TO DO : USE IT IN org.silex.ui.players.Image
| url_str | url of the media to be loaded |
| target_mc | the MovieClip in which to load the media |
| resObj | optional - the listener object |
| container_rect | optional - object representing the rectangle used to center or resize the media once loaded, contains left, top, right and bottom attributes |
| resize_bool | optional - if true, the media is resized to fit container_rect |
| center_bool | optional - if true, the media is centered with container_rect’s center |
function splitTags( input_str: String, leftTag: String, rightTag: String ):Array
Use the accessors delimiters paterns to split the input string into an array.
| param | input_str a string containing accessors |
| param | leftTag [[optional]]left delimiter, (( by default |
| param | rightTag [[optional]]right delimiter, )) by default |
the array of strings containing accessors
function revealAccessors( input_str/*: String*/, source_mc: Object, separator: String )//:String
Replaces accessors by their values in a String. for example “my text is for <<dbdata.name1>>!!! not for <<dbdata.name2>> ((nor for <<dbdata.name3>>!!! ))” becomes - “my text is for value name1!!! not for value name2 ((nor for value name3!!! ))” if all name variables exist - “my text is for !!! not for <<dbdata.name2>>” if only dbdata.name2 exists
| input_str | a string containing accessors (“((...<<path.to.a.variable>>...))”) |
| source_mc | the movie clip from which to start when looking for the variable (see org.silex.Utils.getTarget) |
| separator | the separator used for inclusion in the notation (path.to.a.variable or path/to/a/variable) - default is “.” |
the resulting string [or object if only 1 accessor in the string, or an array of objects if only accessors and no other chars]
function processWikiLinkTag( tag_str: String ):String
Reveal links. If you use this, you have to declare a function like this one in the same movie than the text field which displays the text: function processWikiLinkTagCallback (escapedCommands_str:String) { silexInstance.utils.processWikiLinkTagCallback(escapedCommands_str); }
| param | tag_str the string between {{ and }} |
the equivalent html code
function processWikiLinkTagCallback ( escapedCommands_str: String )
Callback function executed when the user clicks on a link in a text. Execute the commands associated with this link.
| escapedCommands_str | escaped string containing SILEX commands separated by a pipe character (“|”) |
function revealTags( input_str: String, openTag_str: String, closeTag_str: String, processTagFunction: Function ):String
Reveal all wiki tags or accessors contained in a string.
| param | input_str string containing wiki tags or accessors |
| param | openTag_str accessor left patern |
| param | closeTag_str accessor right patern |
| param | processTagFunction callback function to be called for each tag found |
the resulting string
function isPartOf( localContext_array: Array, globalContext_array: Array ):Boolean
check if an array is part of another array
| param | localContext_array the context that may be contained in the other context |
| param | globalContext_array the context that may contain the other context |
true if localContext is included in globalContext
function applyTypeWriterEffect( _txt: TextField, text_str: String, speen_num: Number, callback: Function )
Typewriter effect. @example _global.getSilex().utils.applyTypeWriterEffect(_txt,”My display text”, 40);
| param | _txt TextField to which to apply the effect |
| param | text_str the text to display |
| param | speen_num the speed of the effect |
| param | callback callback called at the end of the anomation |
static function createDelegate( obj: Object, func: Function ):Function
Creates a functions wrapper for the original function so that it runs in the provided context.<br/> You can pass parameters to the function @parameter obj Context in which to run the function. @paramater func Function to run. @paramater ... parameters to pass to the delegated function
Reference to silex main Api object (org.silex.core.Api).
private var silex_ptr: org.silex.core.Api
Constructor.
function Utils( api: org.silex.core.Api )
the year on 2 digits (eg 08 for 2008)
function get YY():String
the month number on 2 digits (eg 01 for january)
function get MM():String
the day number on 2 digits (eg 08 for 8th day of the month)
function get DD():String
the hour (from 0 to 23) on 2 digits
function get HH():String
the hour (from 0 to 12) on 2 digits
function get HH12():String
the minutes (from 0 to 59) on 2 digits
function get MMIN():String
the year on 4 digits (eg 2008)
function get YEAR():String
dependent on the language config
function get DAY():String
dependent on the language config
function get MONTH():String
the hour (from 0 to 23)
function get HOUR():String
the hour (from 0 to 12)
function get HOUR12():String
AM or PM
function get AMPM():String
the minutes (from 0 to 59)
function get MINUT():String
Convert an html formated text into a raw text (removes all tags).
public function getRawTextFromHtml( html_str ):String
Remove unwanted chars from ID.
function cleanID( id: String ):String
Add slashes to a string before characters that need to be quoted in database queries etc.
function addslashes( _str: String ):String
Convert num into string and adds 0s before it so that it has nDigits numbers.
function formatNumberWithNDigits( num: Number, nDigits: Number ):String
Name of the last opened alertSimple dialog box.
var lastOpenedAlertSimpleName: String
Display a message in a dialog box.
public function alert( text_str: String, cbkFunction: Function ):MovieClip
Display a message without a dialog box.
public function alertSimple( text_str: String, time_num: Number, cbkFunction: Function ):MovieClip
Display a question in a dialog box with “ok” and “cancel” buttons.
public function confirm( text_str: String, cbkFunction: Function ):MovieClip
Ask the user to write a string.
public function prompt( text_str: String, default_str: String, cbkFunction: Function ):MovieClip
Ask the user to login
public function promptPassword( text_str: String, cbkFunction: Function ):MovieClip
Takes the url from which _root was downloaded, remove the file name and return the url of the folder from which _root was downloaded.
public function getRootUrl():String
retrieve an object from its path, starting in a given MovieClip
public function getTarget( source_mc/*: Object*/, path_str: String, separator: String ):Object
Array which contains all the files and streams being downloaded.
public var loadingMedias: Array
Resize the given movie clip so that it fits the rectangle and it keeps the same width/height ratio.
public function resizeMedia( target_mc: MovieClip, w: Number, h: Number ):Number
Center a movie clip in a specifyed zone or container.
public function centerMedia( target_mc, w: Number, h: Number, delta_x: Number, delta_y: Number )
Loads a media into a container.
public function loadMedia( url_str: String, target_mc: MovieClip, resObj: Object, container_rect: Object, resize_bool: Boolean, center_bool: Boolean )
Custom trace function.
public function trace( _obj: Object, level_str: String )
Dump an object recursively.
function dump( _obj: Object, tab: String ):String
Serialize an object recursively into a json string
function obj2json( _obj ):String
Replace a string by another string in the source string.
function replace( chaine_str: String, a_remplacer_str: String, remplacement_str: String ):String
Replace accented UTF-8 characters by unaccented ASCII-7 equivalents.
function deaccent( _str: String ):String
Use the accessors delimiters paterns to split the input string into an array.
function splitTags( input_str: String, leftTag: String, rightTag: String ):Array
Replaces accessors by their values in a String.
function revealAccessors( input_str/*: String*/, source_mc: Object, separator: String )//:String
Reveal wiki tags.
function revealWikiSyntax( input_str: String ):String
Reveal images.
function processWikiImageTag( tag_str: String ):String
Reveal links.
function processWikiLinkTag( tag_str: String ):String
Callback function executed when the user clicks on a link in a text.
function processWikiLinkTagCallback ( escapedCommands_str: String )
Reveal all wiki tags or accessors contained in a string.
function revealTags( input_str: String, openTag_str: String, closeTag_str: String, processTagFunction: Function ):String
Mail validation.
function checkValidMail( mail_str ):Boolean
check if an array is part of another array
function isPartOf( localContext_array: Array, globalContext_array: Array ):Boolean
Typewriter effect.
function applyTypeWriterEffect( _txt: TextField, text_str: String, speen_num: Number, callback: Function )
Remove the effect from the TextFiled
function removeTypeWriterEffect( _txt: TextField )
Creates a functions wrapper for the original function so that it runs in the provided context.<br/> You can pass parameters to the function @parameter obj Context in which to run the function.
static function createDelegate( obj: Object, func: Function ):Function