example

Multiple ContextMenuItem for different objects

Posted in AS3 optimization, example, projects & snippets on August 11th, 2010 by admin – Be the first to comment

OK here is a simple way to create as many objects as you want context menus:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;


function addContext(sprite_:Sprite):void {
    var menu:ContextMenu = new ContextMenu();
    menu.customItems = [new ContextMenuItem("Select only " + sprite_.name)];
    menu.hideBuiltInItems();
    sprite_.contextMenu = menu;
}

addContext(yellow);
addContext(green);
addContext(red);
addContext(blue);
addContext(this);

note that yellow, green, red, blue are Sprites, but it can be also buttons

Example:

This movie requires Flash Player 10

Nice post about The Right-Click Menu in Flash by Raiyan

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

Flash: Simple flash banner

Posted in actionscript 3, example on June 16th, 2009 by admin – Comments Off

hi, I’m posting link to flash banner code because of numerous requests of link to my scripting style. :)

billboard flash banner

billboard flash banner

here is the zip file of source files