1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| /**
* Convert netStream.time (or seconds) into String format HH:MM:SS
* @param seconds
* @return formated string HH:MM:SS
*/
public static function formatTime(time:Number):String {
if (time < 0 || isNaN(time)) {
return "00:00";
}
const hours:Number = Math.floor(time / 3600 % 24);
const minutes:Number = Math.floor(time / 60 % 60);
const seconds:Number = Math.floor(time % 60);
const hString:String = hours < 10? "0" + hours: "" + hours;
const mString:String = minutes < 10? "0" + minutes: "" + minutes;
const sString:String = seconds < 10? "0" + seconds: "" + seconds;
return hours > 0 ? hString + ":" + mString + ":" + sString : mString + ":" + sString;
} |
Example:
1 2 3 4 5 6 7 8
| trace(formatTime(103));
//01:43
trace(formatTime(3));
//00:03
trace(formatTime(3653));
//01:00:53 |
Email check if is valid with regular expression.
1 2 3 4
| var email_re:RegExp = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
if (!email_re.test(_email_ctti.text)) {
//Missing field/Invalid email;
} |
Hi I have recently working on saving different format images from flash. My previous work on this script was: Image Encode with Flash and PHP. Here you can create snapshots from video source.
Example
In this example you can save exported images also in your computer. I like this example more, because you can get different images, not boring same image again.
Screenshots:



I created easy to functionality to extend player. Here is the link:

You pass total of 4 flash variables:
1 2 3 4 5
| var flashvars = {};
flashvars.videoURL = "running man.mp4";
flashvars.autoPlay = 0;
flashvars.isImage = 1;
flashvars.imageURL = "RunningMan.jpg"; |
I’m using swfobject ot embed it in page. So lets say little more about variables:
videoURL is link to video location;
autoPlay is flag, if = 1, then video will start automatically playing. If = 0, then will stay stopped until play button is clicked;
isImage is flag, if = 1, them you have to pass image location to imageURL variable, to be loaded.If = 0, then no image is loaded;
isImage is image location;
Note: autoPlay and isImage cannot be 1 at the same time! Player will throw error. Also please use 0 or 1 for flags, not false or true.
hi, this is a little project to save export/save images from flash.

image encoder
This application allow you to see how to export in different image formats like: png, jpg and bmp.
I create class ImageCreator, whit it it’s this easy create images on server. You call the class like this:
1 2
| var imagecreator:ImageCreator = new ImageCreator(image_spr, ImageCreator.EXPORT_TYPE_PNG, name);
imagecreator.addEventListener(ImageCreator.EVENT_COMPLETE_SAVING, completeWritingEvent); |
Event ImageCreator.EVENT_COMPLETE_SAVING, will be dispatched when image is correctly saved on your server.
This is ImageCreator Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| package com.stanislavstankov.images {
import com.adobe.images.*;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.utils.ByteArray;
public final class ImageCreator extends EventDispatcher {
public static const EVENT_COMPLETE_SAVING:String = "eventCompleteSaving";
public static const EXPORT_TYPE_JPG:int = 0;
public static const EXPORT_TYPE_PNG:int = 1;
public static const EXPORT_TYPE_BMP:int = 2;
private const _FOLDER_FILE:String = "http://projects.stanislavstankov.com/imageEncoder/php";
private const _PHP_FILE:String = "/imgEncoder.php";
private var _filename:String;
/*------------------------------------
Constructor
------------------------------------*/
/**
* ImageCreator will create image on the server where the php file is.
* Event EVENT_COMPLETE_SAVING, will be dispatched when image is created on server.
* Also there is one get propert filepath, that will return the path where the image is saved.
* @param Dispaly object - sprite or moviclip that will be exported for image
* @param type of image that will be saved
* @param name of the file
* @param background color if transperent, leave it 0. If you need background change the value. It is ARGB type.
*/
public function ImageCreator($displayObjectExport_:Sprite, $exportType_:int, $name_:String, $fillColorARGB_:uint = 0x0):void {
var transperentFlag:Boolean = false;
if ($exportType_ == EXPORT_TYPE_PNG) {
transperentFlag = true;
}
const bmpdata:BitmapData = new BitmapData($displayObjectExport_.width, $displayObjectExport_.height, transperentFlag, $fillColorARGB_);
bmpdata.draw($displayObjectExport_);
createImage(bmpdata, $exportType_, $name_);
}
/*------------------------------------
Public methods
------------------------------------*/
public function get filepath():String {
return _filename;
}
/*------------------------------------
Private methods
------------------------------------*/
private function createImage($bmpdata_:BitmapData, $exportType_:int, $name_:String):void {
var byteArray:ByteArray;
var contentType:String;
switch ($exportType_) {
case EXPORT_TYPE_JPG:
var jpgencode:JPGEncoder = new JPGEncoder(100);
byteArray = jpgencode.encode($bmpdata_);
contentType = 'image/jpg';
$name_ += ".jpg";
break;
case EXPORT_TYPE_PNG:
byteArray = PNGEncoder.encode($bmpdata_);
contentType = 'image/png';
$name_ += ".png";
break;
case EXPORT_TYPE_BMP:
byteArray = BMPEncoder.encode($bmpdata_);
contentType = 'image/bmp';
$name_ += ".bmp";
break;
default:
break;
}
const request:URLRequest = new URLRequest(_FOLDER_FILE + _PHP_FILE + "?name=" + $name_);
request.contentType = contentType;
request.method = URLRequestMethod.POST;
request.data = byteArray;
const loader:URLLoader = new URLLoader(request);
loader.addEventListener(Event.COMPLETE, loadResultHandler);
}
/*------------------------------------
Event Functions
------------------------------------*/
private function loadResultHandler(info:Event):void {
info.target.removeEventListener(Event.COMPLETE, loadResultHandler);
var urlvars:URLVariables = new URLVariables(info.target.data);
_filename = _FOLDER_FILE + "/" + urlvars.filename;
dispatchEvent(new Event(EVENT_COMPLETE_SAVING));
}
}
} |
PHP imgEncoder.php file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
//$fullFilePath = dirname(__FILE__) . "/" . $_GET['name'];
$fullFilePath = $_GET['name'];
$handle = fopen($fullFilePath,"w");
fwrite($handle, $GLOBALS["HTTP_RAW_POST_DATA"]);
fclose($handle);
echo "result=1&filename=" . $fullFilePath;
} else {
echo 'result=0';
}
?> |
Source file here
Edit 14.09.2009
Flash video Player Snapshot
Hi here is resources of ActionScript 3 libraries.
From Adobe Labs
The Adobe Developer Rel
ations team is releasing a set of free and open ActionScript 3.0 APIs to help developers get started building Flex 2.0 applications. These libraries are of beta quality and we have released them as-is under this license. Adobe does not support them.
- corelib
- FlexUnit
- Flickr
- Mappr
- RSS and Atom libraries
- Odeo
- YouTube
Hi, this is class that I user when I have to parse RSS or XML data. I use it because there are several character that appear like NN and I use in this case escapeASCIICharacters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| package com.stanislavstankov.shared.api {
import flash.xml.XMLDocument;
import flash.xml.XMLNode;
public final class ParseUtils {
public static function escapeFotDB($value_:String):String {
var regTest:RegExp;
regTest = /&/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/&/g, "&");
}
regTest = /'/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/'/g, "'");
}
regTest = /"/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/"/g, '"');
}
regTest = /</;
if (regTest.test($value_)) {
$value_ = $value_.replace(/</g, "<");
}
regTest = />/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/>/g, ">");
}
return $value_;
}
public static function escapeXMLCharacters($value_:String):String {
var regTest:RegExp;
regTest = /&/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/&/g, "&");
}
regTest = /'/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/'/g, "'");
}
regTest = /"/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/"/g, '"');
}
regTest = /</;
if (regTest.test($value_)) {
$value_ = $value_.replace(/</g, "<");
}
regTest = />/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/>/g, ">");
}
return $value_;
}
public static function escapeASCIICharacters($value_:String):String {
var regTest:RegExp;
regTest = /\n/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/\n/g, " ");
}
$value_ = $value_.replace(/[ ]{2,}/g, " ");
regTest = /&/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/&/g, "&");
}
regTest = /&/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/&/g, "&");
}
regTest = /‘/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/‘/g, '"');
}
regTest = /'/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/'/g, "'");
}
regTest = /'/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/'/g, "'");
}
regTest = /’/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/’/g, "'");
}
regTest = /‘/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/‘/g, "'");
}
regTest = /‘/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/‘/g, '"');
}
regTest = /’/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/’/g, '"');
}
regTest = /"/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/"/g, '"');
}
regTest = /</;
if (regTest.test($value_)) {
$value_ = $value_.replace(/</g, "<");
}
regTest = />/;
if (regTest.test($value_)) {
$value_ = $value_.replace(/>/g, ">");
}
return $value_;
}
public static function allEscapes($value_:String):String {
return escapeASCIICharacters(escapeXMLCharacters($value_));
}
}
} |
This is class that with which you can create TextField in couple of lines:
1 2 3 4 5 6 7
| var text1_txt:TextField = TextCreator.createTextField(TextCreator.FONT_MYRIADPRO_12, 0x0, 11, true, 0, true);
//var text1_txt:TextField= TextCreator.createTextField(TextCreator.FONT_MYRIADPRO_12, 0xffffff, 11, true, -0.3, true, TextCreator.TFA_CENTER);
//var text1_txt:TextField= TextCreator.createTextField(TextCreator.FONT_MYRIADPRO_12, 0x565656, 11);
text1_txt.text = "text1";
text1_txt.x = 93;
text1_txt.y = 20;
addChild(text1_txt); |
You have to keep in mind that VerdanaEmbedded and MyRiadPro12Embedded are extended Font classes in package com.stanislavstankov.fonts Example:
1 2 3 4 5 6 7 8 9 10 11 12 13
| package com.stanislavstankov.fonts {
import flash.text.Font;
public final class MyRiadPro12Embedded extends Font {
/*------------------------------------
Constructor
------------------------------------*/
public function MyRiadPro12Embedded():void {
}
}
} |
Text Creator Class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| package com.stanislavstankov.utils {
import com.stanislavstankov.fonts.*;
import flash.text.AntiAliasType;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
public final class TextCreator {
public static const FONT_VERDANA:int = 1;
public static const FONT_MYRIADPRO_12:int = 2;
/**
* Constant; centers the text in the text field.
* Use the syntax TextFormatAlign.CENTER.
*/
public static const TFA_CENTER:String = "center";
/**
* Constant; justifies text within the text field.
* Use the syntax TextFormatAlign.JUSTIFY.
*/
public static const TFA_JUSTIFY:String = "justify";
/**
* Constant; aligns text to the left within the text field.
* Use the syntax TextFormatAlign.LEFT.
*/
public static const TFA_LEFT:String = "left";
/**
* Constant; aligns text to the right within the text field.
* Use the syntax TextFormatAlign.RIGHT.
*/
public static const TFA_RIGHT:String = "right";
public static function createTextField(font_:int, color_:int, size_:int, kerning_:Boolean = true, letterSpacing_:Number = 0, bold_:Boolean = false, align_:String = TFA_LEFT):TextField {
var textformat:TextFormat = new TextFormat();
textformat.align = align_;
textformat.color = color_;
textformat.bold = bold_;
textformat.font = getFont(font_).fontName;
textformat.size = size_;
textformat.kerning = kerning_;
textformat.letterSpacing = letterSpacing_;
var textfield:TextField = new TextField();
textfield.antiAliasType = AntiAliasType.ADVANCED;
textfield.embedFonts = textfield.cacheAsBitmap = true;
textfield.selectable = textfield.mouseEnabled = textfield.mouseWheelEnabled = false;
textfield.defaultTextFormat = textformat;
textfield.autoSize = TextFieldAutoSize.LEFT;
return textfield;
}
private static function getFont($fontID_:int):Font {
var font:Font;
switch ($fontID_) {
case FONT_VERDANA:
font = new VerdanaEmbedded();
break;
case FONT_MYRIADPRO_12:
font = new MyRiadPro12Embedded();
break;
}
return font;
}
public static function noMoreLine($txt_:TextField, $fromLine_:int, $suffix_:String = "..."):void {
var imax:int = $txt_.numLines - $fromLine_;
//added !!! on 28!
$txt_.height = $txt_.textHeight + $fromLine_ * 2;
if (imax < 1) {
return void;
}
var numSymb:int = 0;
for (var i:int = i; i < imax; i++) {
numSymb += $txt_.getLineLength(i + $fromLine_);
}
var txt:String = $txt_.text;
$txt_.text = txt.substr(0, txt.length - numSymb - $suffix_.length) + $suffix_;
$txt_.height = $txt_.textHeight + $fromLine_ * 2;
}
}
} |
Hi to all,
this is one class that I used in all my projects, where I need bitmap resizing.
Class main purpoise is to help you with resizing images, when you load them. It have only one public static function resize.
You pass there bitmap image, the width you want, the height you want and the type of resizing.
Hope it helps you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| package com.stanislavstankov.shared.utils {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.geom.Matrix;
import flash.display.PixelSnapping;
public final class BitmapFunctions {
/**
* Specifies that the image be visible in the specified area without distortion while maintaining the original aspect ratio of it.
*/
public static const SHOW_ALL:String = "showAll";
/**
* Specifies that the image be visible in the specified area without distortion but possibly with some cropping, while maintaining the original aspect ratio of the application.
*/
public static const NO_BORDER:String = "noBorder";
/**
* Specifies that the image be visible in the specified area without trying to preserve the original aspect ratio.
*/
public static const EXACT_FIT:String = "exactFit";
public static function resize(image_:Bitmap, width_:int, height_:int, type_:String = BitmapFunctions.EXACT_FIT):Bitmap {
var outBitmap:Bitmap;
var bitmapData:BitmapData = new BitmapData(image_.width, image_.height, false);
bitmapData.draw(image_);
switch (type_ ) {
case EXACT_FIT:
bitmapData = resizeBitmapData(bitmapData, width_, height_);
outBitmap = new Bitmap(bitmapData, PixelSnapping.AUTO, true);
break;
case SHOW_ALL:
if ((image_.width < 2) || (image_.height < 2)) {
return null;
}
if ((image_.width <= width_) && (image_.height <= height_)) {
outBitmap = image_;
} else {
var propToHeight:Number = height_ / image_.height;
var propToWidth:Number = width_ / image_.width;
var beW:int;
var beH:int;
if (propToWidth > propToHeight) {
beW = image_.width * propToHeight;
beH = image_.height * propToHeight;
} else {
beW = image_.width * propToWidth;
beH = image_.height * propToWidth;
}
bitmapData = resizeBitmapData(bitmapData, beW, beH);
outBitmap = new Bitmap(bitmapData, PixelSnapping.AUTO, true);
}
break;
case NO_BORDER:
var nbpropToHeight:Number = height_ / image_.height;
var nbpropToWidth:Number = width_ / image_.width;
var nbbeW:int;
var nbbeH:int;
if (nbpropToWidth < nbpropToHeight) {
nbbeW = image_.width * nbpropToHeight;
nbbeH = image_.height * nbpropToHeight;
} else {
nbbeW = image_.width * nbpropToWidth;
nbbeH = image_.height * nbpropToWidth;
}
bitmapData = resizeBitmapData(bitmapData, nbbeW, nbbeH);
outBitmap = new Bitmap(bitmapData, PixelSnapping.AUTO, true);
break;
}
return outBitmap;
}
private static function resizeBitmapData(bmpSource:BitmapData, setWidth:Number, setHeight:Number):BitmapData {
var scaleWidth:Number = setWidth / bmpSource.width;
var scaleHeight:Number = setHeight / bmpSource.height;
var bmp:BitmapData = new BitmapData (setWidth, setHeight, true, 0);
var matrix:Matrix = new Matrix ();
matrix.scale(scaleWidth, scaleHeight);
bmp.draw(bmpSource, matrix);
return bmp;
}
}
} |
hi, I’m posting link to flash banner code because of numerous requests of link to my scripting style.

billboard flash banner
here is the zip file of source files