-
1. Re: Right Click > Arrange at runtime in code? in Flash CS4 (AS3)
waterdad568 Mar 17, 2010 8:27 PM (in response to Me2LoveIt2)You could use eventListeners for the mouse event to fire a function to do almost anything you want with an object.
-
2. Re: Right Click > Arrange at runtime in code? in Flash CS4 (AS3)
Harry Kunz Mar 18, 2010 3:03 AM (in response to Me2LoveIt2)You can use addChild/removeChild:
var mc1:Clip1 = new Clip1();
var mc2:Clip2 = new Clip2();
var mc3:Clip3 = new Clip3();
addChild(mc1);
addChild(mc2);
addChild(mc3);
bringToFront(mc1); //brings mc1 to front
function bringToFront(mc:MovieClip):void
{
removeChild(mc);
addChild(mc)
}
Or you can use swapChildrenAt:
function bringToFront(mc:MovieClip):void
{
var nChildren:Number = 3; //There might be a method to retrieve that
swapChildrenAt(getChildIndex(mc), nChildren - 1);
}
-
3. Re: Right Click > Arrange at runtime in code? in Flash CS4 (AS3)
Ned Murphy Mar 18, 2010 4:40 AM (in response to Me2LoveIt2)In case it is important to you, there is no right click event you can listen for in Flash.
-
4. Re: Right Click > Arrange at runtime in code? in Flash CS4 (AS3)
Jesse Nicholson Mar 18, 2010 10:10 AM (in response to Me2LoveIt2)What you can do if you want right click is create a new ContextMenu and ContextMenuItem. You'll have to add a mouse click listener to each of your stage items though so you can track the last one clicked;
import flash.events.ContextMenuEvent;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
var lastItem:MovieClip;
var i:int;for(i = 0; i < stage.numChildren; ++i){
stage.getChildAt(i).addEventListener(MouseEvent.MOUSE_DOWN, itemClicked);
}
function itemClicked(e:MouseEvent):void
{
lastItem = e.currentTarget as MovieClip;
}
var rightClickMenu:ContextMenu = new ContextMenu();
rightClickMenu.hideBuiltInItems();
rightClickMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, rightClickMenuClicked);
var bringToFront:ContextMenuItem = new ContextMenuItem("Bring To Front");
rightClickMenu.customItems = [bringToFront];
stage.showDefaultContextMenu = false;
stage.contextMenu = rightClickMenu;
function rightClickMenuClicked(e:ContextMenuEvent):void
{
switch (e.mouseTarget.label)
{
case "Bring To Front":
if(lastItem != null){
lastItem.parent.addChild(lastItem);
}
break;
}
}
NOTE: You do not need to first remove the child to add it again. By adding an existing child you're simply resetting it to the top depth. -
5. Re: Right Click > Arrange at runtime in code? in Flash CS4 (AS3)
Jesse Nicholson Mar 18, 2010 10:12 AM (in response to Ned Murphy)Unless of course it's an AIR application, in which case you can access the right mouse button .




