actionscript 3

JVM heap size, or why Flash is not compiling

Posted in actionscript 3 on June 15th, 2010 by admin – 4 Comments

Its been a while since i write something into my blog, but I want to share my experience over this topic.
As you develop project for sometime one Flash, and your code get bigger and bigger:

Source Code Statistics:

Code lines: 54 937 (59%)
Comment lines: 20 347 (21,9%)
Blank lines: 17 847 (19,2%)

Total lines: 93 121 read more »

Flex Drag and Drop with dynamic image

Posted in actionscript 3, flex 3 on March 15th, 2010 by admin – Comments Off

Hey I was searching in internet how to do a drag that create a exact copy of the image without loading it. All the examples were with Embed images so i needed some example that Image load bitmap and then do drag without having to load bitmap twice. So take a look:

1
2
3
4
5
6
7
8
9
10
11
// fire from MouseEvent.MOUSE_DOWN event
private function doDrag(e:MouseEvent):void {
    var dragInitiator:Image = e.currentTarget as Image;
    var dragSource:DragSource = new DragSource();
    dragSource.addData(_core, "core");
   
    var dragProxy:Image = new Image ();
    dragProxy.source = new Bitmap((dragInitiator.content as Bitmap).bitmapData);
   
    DragManager.doDrag(dragInitiator, dragSource, e, dragProxy);
}

Spinets used:
Simple Flex Drag and Drop

equal function String.fromCharCode in PHP

Posted in PHP, actionscript 3 on February 17th, 2010 by admin – Be the first to comment

Hey it was problem before I see this solution, to pass charactes to PHP like numbers, basicly because Flash use fromCharCode in UTF-8 format and PHP do chr function work in ASCII.

So here is the script solution:

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
function uniord($ch) {

    $n = ord($ch{0});

    if ($n < 128) {
        return $n; // no conversion required
    }

    if ($n < 192 || $n > 253) {
        return false; // bad first byte || out of range
    }

    $arr = array(1 => 192, // byte position => range from
                 2 => 224,
                 3 => 240,
                 4 => 248,
                 5 => 252,
                 );

    foreach ($arr as $key => $val) {
        if ($n >= $val) { // add byte to the 'char' array
            $char[] = ord($ch{$key}) - 128;
            $range  = $val;
        } else {
            break; // save some e-trees
        }
    }

    $retval = ($n - $range) * pow(64, sizeof($char));

    foreach ($char as $key => $val) {
        $pow = sizeof($char) - ($key + 1); // invert key
        $retval += $val * pow(64, $pow);   // dark magic
    }

    return $retval;
}

found on : Unnamed – post number 1799714

Preventing SWFs From Running Locally

Posted in actionscript 3 on February 8th, 2010 by admin – Be the first to comment

IT is great to read this article. Lately the swf that I start localy do not check where they are started and I get a thrown errors… you can just make it little more professional by reading it.
Preventing SWFs From Running Locally

SharedObject between 2 movies

Posted in actionscript 3, projects & snippets on January 28th, 2010 by admin – 1 Comment

So lets create 2 files:

setCookies.fla

setCookies.fla flash env with component names

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var date:Date = new Date();
val_ti.text = ">> " +date.time;

setCookie_btn.addEventListener(MouseEvent.CLICK, clickHandler);
show_btn.addEventListener(MouseEvent.CLICK, showHandler);


function clickHandler(info:MouseEvent):void {
    var local_data:SharedObject = SharedObject.getLocal("VSh", "/");
    local_data.data.key = val_ti.text;
    status_txt.text = local_data.flush();
}

function showHandler(info:MouseEvent):void {
    var local_data:SharedObject = SharedObject.getLocal("VSh", "/");
    read_ti.text = local_data.data.key;
}

getCookies.fla

getCookies.fla flash evn with component names

getCookies.fla flash evn with component names

1
2
3
4
5
6
7
8
9
10
11
var timer:Timer = new Timer(500, 0);
timer.addEventListener(TimerEvent.TIMER, checkForCookieHandker);
timer.start();


info_ta.text = "check for cookies every 0.5 sec ... ";
function checkForCookieHandker(info:TimerEvent):void {
    var local_data:SharedObject = SharedObject.getLocal("VSh", "/");
    local_data.flush();
    info_ta.text = "[" + timer.currentCount + "] key: " + local_data.data.key + ", size: " + local_data.size + "\n" + info_ta.text;
}

Demo

Set cookie

This movie requires Flash Player 10

Get cookie

This movie requires Flash Player 10

see also:
where is .sol files in windows 7

source files in flash-cookie.zip

where is .sol files in windows 7

Posted in actionscript 3 on January 27th, 2010 by admin – Comments Off

Hi if you are searching where .sol files are set in Windows 7, check here:

C:\Users\USER\AppData\Roaming\Macromedia\Flash Player\#SharedObjects

Camera.getCamera problem => solution

Posted in actionscript 3, example on January 23rd, 2010 by admin – Comments Off

When you try to add a camera by name like this:

1
2
var cameraName:String = "WebCam";
var cam:Camera = Camera.getCamera(cameraName);

or like this

1
var cam:Camera = Camera.getCamera(cameranames[0]);

both return cam = null

Solution:

You need to add camera index like String in order to work

1
2
3
4
5
6
7
8
9
10
11
var cameraName:String = "WebCam";
var camera:Camera;
const imax:int = Camera.names.length;
var i:int = 0;
while (i < imax) {
    if (Camera.names[i] == cameraName) {
        camera = Camera.getCamera(String(i));
        break;
    }
    i++;
}

or use this function

1
2
3
4
5
6
7
8
9
10
11
12
13
const camera:Camera = getCamera("webCam");
       
private static function getCamera($cameraName_:String):Camera {
    const imax:int = Camera.names.length;
    var i:int = 0;
    while (i < imax) {
        if (Camera.names[i] == $camName_) {
            return Camera.getCamera(String(i));
        }
        i++;
    }
    return null;
}

so now you will have your camera that you wanted:

thank to:
pooja

Time Display

Posted in actionscript 3 on January 6th, 2010 by admin – Comments Off
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 RegExp

Posted in actionscript 3 on September 28th, 2009 by admin – Comments Off

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;
}

Flash video Player Snapshot

Posted in PHP, actionscript 3, projects & snippets on September 14th, 2009 by admin – Comments Off

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:
snapshot file 1
snapshot file 2
snapshot file 3