Me (Stanislav Stankov) growing up

Problems showing hebrew from AMFPHP

By default, AMFPHP encoding is:

1
$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");

If you change it to:

1
$gateway->setCharsetHandler("iconv", "UTF-8", "UTF-8");

All set. This is in gateway.php file

Regular Expression specific URI check

This is Regular Expression that my friend written for my project. It check if the URL is from specific domain:

1
var reg:RegExp = /^(.*:\/\/)?(www\.)?([a-zA-Z0-9_-]*\.)*mydomain\.com(.*)$/;

In this RegExp I check if URLs belong to mydomain.com as root domain.

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
var reg:RegExp = /^(.*:\/\/)?(www\.)?([a-zA-Z0-9_-]*\.)*mydomain\.com(.*)$/;

var test1:String = "http://mydomain.com/ecard4/";
var test2:String = "mydomain.com/ecard4/";
var test3:String = "http://www.mydomain.com/ecard4/";
var test4:String = "www.mydomain.com/ecard4/";
var test5:String = "http://notmydomain.com/ecard4/";
var test6:String = "notmydomain.com/ecard4/";
var test7:String = "http://asdas.asdasd.mydomain.com.asd.mydomain.com/ecard4/";
var test8:String = "http://www.notmydomain.com/mydomain.com/ecard4/";
var test9:String = "http://stanislav.com.notmydomain.com/mydomain.com/ecard4/";
var test10:String = "http://sdfsmydomain.com/";
var test11:String = "http://www.stanislav.com.notmydomain.com/mydomain.com/ecard4/";
var test12:String = "https://mydomain.com/ecard4/";
var test13:String = "ftp://mydomain.com/ecard4/";

trace(1, reg.test(test1));
trace(2, reg.test(test2));
trace(3, reg.test(test3));
trace(4, reg.test(test4));
trace(5, reg.test(test5));
trace(6, reg.test(test6));
trace(7, reg.test(test7));
trace(8, reg.test(test8));
trace(9, reg.test(test9));
trace(10, reg.test(test10));
trace(11, reg.test(test11));
trace(12, reg.test(test12));
trace(13, reg.test(test13));

the output is:

1 true
2 true
3 true
4 true
5 false
6 false
7 true
8 false
9 false
10 false
11 false
12 true
13 true

JVM heap size, or why Flash is not compiling

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

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

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

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

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

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

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

ScanScout AS3 Overlay Manager

Hi I will post some code that will make you easier to implement Scan Scout AS3 Overlay.

We have class that hold the needed values:

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
package com.stanislavstankov.ss.dto {
   
    public final class ScanScoutAS3OverlayDTO {
       
        private var _partnerId:String;
        private var _pageURL:String;
        private var _mediaId:String;
        private var _mediaURL:String;
        private var _mediaTitle:String;
        private var _mediaDescription:String;
        private var _mediaKeywords:String;
        private var _mediaCategories:String;
       
        /*------------------------------------
            Constructor
        ------------------------------------*/

        public function ScanScoutAS3OverlayDTO($partnerId_:String, $pageURL_:String, $mediaId_:String, $mediaURL_:String, $mediaTitle_:String, $mediaDescription_:String, $mediaKeywords_:String, $mediaCategories_:String):void {
            _partnerId = $partnerId_;
            _pageURL = $pageURL_;
            _mediaId = $mediaId_;
            _mediaURL = $mediaURL_;
            _mediaTitle = $mediaTitle_;
            _mediaDescription = $mediaDescription_;
            _mediaKeywords = $mediaKeywords_;
            _mediaCategories = $mediaCategories_;
        }
        /*------------------------------------
            Public methods
        ------------------------------------*/

       
        public function get partnerId():String {
            return _partnerId;
        }
       
        public function get pageURL():String {
            return _pageURL;
        }
       
        public function get mediaId():String {
            return _mediaId;
        }
       
        public function get mediaURL():String {
            return _mediaURL;
        }
       
        public function get mediaTitle():String {
            return _mediaTitle;
        }
       
        public function get mediaDescription():String {
            return _mediaDescription;
        }
       
        public function get mediaKeywords():String {
            return _mediaKeywords;
        }
       
        public function get mediaCategories():String {
            return _mediaCategories;
        }
       
        public function toString():String {
            return "[ ScanScoutAS3OverlayDTO partnerId='" + partnerId + "'\n\t pageURL='" + pageURL + "'\n\t mediaId='" + mediaId + "'\n\t mediaURL='" + mediaURL + "'\n\t mediaTitle='" + mediaTitle + "'\n\t mediaDescription='" + mediaDescription + "'\n\t mediaKeywords='" + mediaKeywords + "'\n\t mediaCategories='" + mediaCategories + "'\n ]";
        }
       
    }
}

and manger that do all the work

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.stanislavstankov.ss.mngrs {

    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.TimerEvent;
    import flash.net.URLRequest;
    import flash.system.Security;
    import flash.utils.Timer;
    import com.stanislavstankov.videoPlayer.events.VideoEvent;
    import com.stanislavstankov.ss.dto.ScanScoutAS3OverlayDTO;
    import com.stanislavstankov.videoPlayer.player.Player;
   
    public final class ScanScoutAS3OverlayManager {
       
        private var _ss_ads:*;
        //NOTE: Do not append cache-buster. Use this URL as is
        private var _ssURL:String = "http://media.scanscout.com/ads/ss_ads3.swf";
        private var _ssLoader:Loader;
       
        private var _video:Player;
        private var _parent:Sprite;
        private var _core:ScanScoutAS3OverlayDTO;
       
        /*------------------------------------
            Public methods
        ------------------------------------*/

       
        /**
         * Config the manager
         * @param   object that hold the needed values
         * @param   video player
         * @param   the display object that the ads will be added
         */

        public function config($core_:ScanScoutAS3OverlayDTO, $video_:Player, $parent_:Sprite):void {
            _core = $core_;
            _video = $video_;
            _parent = $parent_;
           
            _video.addEventListener(VideoEvent.STARTED, videoStartedHandler);
            _parent.stage.addEventListener(Event.RESIZE, resizeHandler);
        }
       
       
        /*------------------------------------
            Private methods
        ------------------------------------*/

       
        //NOTE: ScanScout must not be loaded unless ScanScout is to be used on the particular stream
        //Also, do not load ScanScout until the video begins
        //These rules are in place to avoid the transfer of assets across the wire unless they are to be used
        private function initiateScanscout():void {
            Security.allowDomain("*");
            _ssLoader = new Loader();
            _parent.addChild(_ssLoader);
            if (_ssLoader.contentLoaderInfo.bytesLoaded == _ssLoader.contentLoaderInfo.bytesTotal) {
                _ssLoader.contentLoaderInfo.addEventListener(Event.INIT, ss_notifyAdsLoad);
            } else {
                _ssLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, ss_notifyAdsLoad);
            }
           
            _ssLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ss_failedAdsLoad);
            _ssLoader.load( new URLRequest(_ssURL) );
        }
       
       
        private function init():void {
           
        }
       
       
        /*------------------------------------
            Event Functions
        ------------------------------------*/

       
        private function resizeHandler(info:Event):void {
            if (_ss_ads != null) {
                _ss_ads.setSize(_parent.stage.stageWidth, _parent.stage.stageHeight - Controls.HEIGHT);
            }
        }
       
        private function videoStartedHandler(info:VideoEvent):void {
            initiateScanscout();
        }
       
        private function ss_failedAdsLoad(e:IOErrorEvent):void  {
            //handle error
            trace(e.text);
        }
       
        private function ss_notifyAdsLoad(e:Event):void {
            _ss_ads = e.target.content;
           
            var timer:Timer = new Timer(1000);
            timer.addEventListener(TimerEvent.TIMER, ss_videoTimeUpdate);
            timer.start();
           
            // Set event listeners:
            _ss_ads.addEventListener("ss_pause", ss_onPause);
            _ss_ads.addEventListener("ss_resume", ss_onResume);
           
            // Set the input parameters for the Ad Rendering Engine:
            _ss_ads.setParam("ss_partnerId", _core.partnerId);
            _ss_ads.setParam("ss_pageURL", _core.pageURL);
            //unique identifier to the video. Can be the mediaURL if that doesn't change on each request
            _ss_ads.setParam("ss_mediaId", _core.mediaId);
            //http URL to the FLV
            _ss_ads.setParam("ss_mediaURL", _core.mediaURL);
            //required metadata: should not be the same across all videos
            _ss_ads.setParam("ss_mediaTitle", _core.mediaTitle);
            _ss_ads.setParam("ss_mediaDescription", _core.mediaDescription);
            _ss_ads.setParam("ss_mediaKeywords", _core.mediaKeywords);
            _ss_ads.setParam("ss_mediaCategories", _core.mediaCategories);
           
            // Size to fit video screen and place top-left:
            _ss_ads.setSize(_parent.stage.stageWidth, _parent.stage.stageHeight - Controls.HEIGHT);
            //TODO: set to left-side of video
            _ssLoader.x = 0;
            //TODO: set to top of video
            _ssLoader.y = 0;
           
            //Kick off the ad presentation:
            _ss_ads.launch();
        }

        private function ss_videoTimeUpdate(evt:TimerEvent):void {
            //playhead_time should be the video time in seconds
            _ss_ads.videoTimeUpdate(_video.time);
        }
       
        private function ss_onPause( evtObj:Object ):void {
            /* TODO: place a call to your video pause routine here */
            _video.pause();
           
        }
       
        private function ss_onResume( evtObj:Object ):void {
            /* TODO: place a call to your video resume routine here */
            _video.resume();
        }
       
        /*------------------------------------
        **************************************
            ScanScoutAS3OverlayManager Singleton Pattern begins
        **************************************
        ------------------------------------*/

       
        private static var _instance:ScanScoutAS3OverlayManager;
        private static var _allowInstance:Boolean = false;
       
        /*------------------------------------
            Constructor
        ------------------------------------*/

        public function ScanScoutAS3OverlayManager():void {
            if (!_allowInstance) {
                throw new Error("This class is Singleton class. Use getInstance method.");
            } else {
                init();
            }
        }
       
        public static function getInstance():ScanScoutAS3OverlayManager {
            if (_instance == null) {
                _allowInstance = true;
                _instance = new ScanScoutAS3OverlayManager();
                _allowInstance = false;
            }
            return _instance;
        }
        /*------------------------------------
        **************************************
            ScanScoutAS3OverlayManager Singleton Pattern ends
        **************************************
        ------------------------------------*/

       
    }
}

and you call it like:

1
2
var sc:ScanScoutAS3OverlayManager = ScanScoutAS3OverlayManager.getInstance();
sc.config(data, player, this);