Skip to main content

Posts

Showing posts with the label Convert

Check if a string converted to a number is actually a number in ActionScript (Flex) and setting scale of a number

An easy way to check if a String is actually a number of not is to actually convert the string to a Number and test if it's NaN. Flex API reference mentions that the top-level function Number(str) returns NaN if the string passed to the method cannot be converted to a Number. The problem with this approach is that if you take Number(null) or Number(undefined) or Number(""), all will return 0 and will evaluate to "is a number". The correct way to do this is shown in following code snippet. It also sets scale of the converted number to two decimal digits. public static function getNumberFromString(val:*, scale:uint = 2):* {     if ((val === null || StringUtil.trim(val) === "" || isNaN(val)) == false)         return setScale(Number(val)).toFixed(scale);     else         return ""; } public static function setScale(number:Number, scale:uint = 2):Number {      scale ...

Convert and cut an avi file using mencoder from MPlayer

To convert an avi file to rmvb using mencoder try: mencoder "src.avi" -o "dest.rmvb" -ovc lavc -lavcopts vcodec=mpeg4 -oac mp3lame If real player fails to play generated file, then play it using mplayer. To cut an avi file (5 seconds is the total length to cut), use following command: mencoder -ss 00:10:10 -endpos 00:05:00 -ovc copy -oac copy "src.avi" -o "dest.avi"