Friday 20 February 2015

INSTANCE NAME TRACE AS3

http://stackoverflow.com/questions/6636405/as3-get-movieclip-instance-name-onclick
var mc:MovieClip;
for (var i:int = 0; i<8; i++) {
    mc = this["holder"+i];
    mc.buttonMode = true;
    mc.mouseChildren = false;
    mc.addEventListener(MouseEvent.CLICK, clickHandler);
}

function clickHandler(e:MouseEvent):void {
    trace(e.target.name);
}
http://stackoverflow.com/questions/11996656/adding-variables-to-movieclip-in-flash-to-be-used-in-flash-builder
http://renren.io/questions/4964748/flash-as3-mouse-custom-cursor-nested-in-a-movieclip
FIND THIS WORD FOR MORE INFORMATION
Targeting movieclip from an AS3

Index of /stack-overflow/examples/box-match/


../
box-match.fla                                      29-Nov-2013 06:36                9306
box-match.html                                     29-Nov-2013 06:36                2036
box-match.swf                                      29-Nov-2013 06:36                1936


public function Constructor()
{
   var container:RectContainer = new RectContainer();
   this.addEvent(container);
   var i:int = 0;
   while(i<container.numChildren)
   {
        container.addEventListener(MouseEvent.CLICK, onClick);
        i++;
   }
}

private function onClick(e:MouseEvent):void
{
    var mc:MovieClip = e.target as MovieClip;

    if(mc.name == "myCircle1")
    {

    }
    else if(mc.name == "myCircle2")
    {

    }
    else if(mc.name == "myCircle3")
    {

    }

    trace(mc.name);
}






--------------------------------------------------------------------------------------------------------------------------
http://d.hatena.ne.jp/tsunet/20090618/1245356992
http://www.hatena.ne.jp/o/search/top?q=button+trace+in+as3
http://www.fumiononaka.com/Drafts/Flash_OOP_2/Flash_OOP_2-4.html
--------------------------------------------------------------------------------------------------------------------------

button.addEventListener(MouseEvent.MOUSE_DOWN, buttonPress);
button.addEventListener(MouseEvent.MOUSE_UP, buttonRelease);
button.addEventListener(MouseEvent.MOUSE_OVER, buttonOver);
button.addEventListener(MouseEvent.MOUSE_OUT, buttonOut);
function buttonPress(e:MouseEvent):void {
//the button is pressed, set a MOUSE_UP event on the button's parent stage
//to caputre the onReleaseOutside event.
button.parent.stage.addEventListener(MouseEvent.MOUSE_UP, buttonRelease);
}
function buttonRelease(e:MouseEvent):void {
//remove the parent stage event listener
button.parent.stage.removeEventListener(MouseEvent.MOUSE_UP, buttonRelease);
//if the events currentTarget doesn't equal the button we
//know the mouse was released outside.
if (e.currentTarget != button) {
trace('onReleasedOutside');
} else {
//the events currentTarget property equals the button instance therefore
//the mouse was released over the button.
trace('onRelease');
}
}
function buttonOver(e:MouseEvent):void {
if (e.buttonDown) {
//if the mouse button is selected when the cursor is
//over our button trigger the onDragOver functionality
trace('onDragOver');
} else {
//if the mouse button isn't selected trigger the standard
//onRollOver functionality
trace('onRollOver');
}
}
function buttonOut(e:MouseEvent):void {
if (e.buttonDown) {
//if the mouse button is selected when the cursor is
//moves off of our button trigger the onDragOut functionality
trace('onDragOut');
} else {
//if the mouse button isn't selected trigger the standard
//onRollOut functionality
trace('onRollOut');
}
}
--------------------------------------------------------------------------------------------------------------------------
button1.addEventListener(MouseEvent.CLICK, buttonClick);
button2.addEventListener(MouseEvent.CLICK, buttonClick);
function buttonClick(event:MouseEvent):void {
trace(event.target.name);
}

// ARRAY FORM
var ButtonArray = new Array(button1,button2);
for (var i:int = 0; i < ButtonArray.length; i++) {
ButtonArray[i].addEventListener(MouseEvent.CLICK,ButtonArrayFunction);
}
function ButtonArrayFunction(event:MouseEvent):void {
trace(event.target.name);
}

button3.addEventListener(MouseEvent.CLICK, buttonClick3);
function buttonClick3(event:MouseEvent):void {
trace(event.target.name);
}
button4.addEventListener(MouseEvent.CLICK, buttonClick4);
function buttonClick4(event:MouseEvent):void {
trace("button4");
}

---------------------------------------------------------------------------------------------------------------------
http://code.tutsplus.com/tutorials/as3-101-functions-basix--active-1040
http://code.tutsplus.com/tutorials/as3-101-variables-basix--active-798
http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html
http://code.tutsplus.com/tutorials/as3-101-oop-inheritance-setters-getters-basix--active-6104
https://www.youtube.com/watch?v=lTvuRIsG9yY
https://www.youtube.com/watch?v=IrafWKU3Z6U
http://www.danfergusdesign.com/classfiles/oldClasses/VCB331-richMedia1/exercises/arrays.php
----------------------------------------------------------------------------------------------------------------------

button1_mc.addEventListener(MouseEvent.CLICK, onButton1Click);
button2_mc.addEventListener(MouseEvent.CLICK, onButton2Click);
button3_mc.addEventListener(MouseEvent.CLICK, onButton3Click);
button4_mc.addEventListener(MouseEvent.CLICK, onButton4Click);
button5_mc.addEventListener(MouseEvent.CLICK, onButton5Click);
function onButton1Click(event:MouseEvent):void {
    trace("button 1");
}
function onButton2Click(event:MouseEvent):void {
    trace("button 2");
}
function onButton3Click(event:MouseEvent):void {
    trace("button 3");
}
function onButton4Click(event:MouseEvent):void {
    trace("button 4");
}
function onButton5Click(event:MouseEvent):void {
    trace("button 5");
}



button.addEventListener(MouseEvent.CLICK, onButtonClick);
button2.addEventListener(MouseEvent.CLICK, onButtonClick);
// ...
private function onButtonClick(e:MouseEvent):void {
    switch (e.target) {
        case button:
        trace("Button 1 was clicked");
        break;
    case button2:
        trace("Button 2 was clicked");
        break;
    }
}



-------------------------------------------------------------------------------------------------------------------------
http://help.adobe.com/en_US/ActionScript/3.0_UsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7fac.html
http://help.adobe.com/en_US/ActionScript/3.0_UsingComponentsAS3/flash_as3_components_help.pdf
--------------------------------------------------------------------------------------------------------------------------
Note: If an icon is larger than the button, it extends beyond the button’s borders.
To designate a button as the default push button in an application (the button that receives the click event when a user presses Enter), setFocusManager.defaultButton . For example, the following code sets the default button to be a Button instance called submitButton .
FocusManager.defaultButton = submitButton;
When you add the Button component to an application, you can make it accessible to a screen reader by adding the following lines of ActionScript code:
import fl.accessibility.ButtonAccImpl; 
 
ButtonAccImpl.enableAccessibility();
You enable accessibility for a component only once, regardless of how many instances you create.

Button component parameters

You can set the following authoring parameters in the Property inspector (Window > Properties > Properties) or in the Component inspector (Window > Component Inspector) for each Button instance: emphasized label labelPlacement selected , and toggle . Each of these parameters has a corresponding ActionScript property of the same name. When you assign a value to these parameters you are setting the initial state of the property in the application. Setting the property in ActionScript overrides the value you set in the parameter. For information on the possible values for these parameters, see the Button class in theActionScript 3.0 Language and Components Reference .

Create an application with the Button component

The following procedure explains how to add a Button component to an application while authoring. In this example, the Button changes the state of a ColorPickercomponent when you click it.
  1. Create a new Flash (ActionScript 3.0) document.
  2. Drag a Button component from the Components panel to the Stage and enter the following values for it in the Property inspector:
    • Enter the instance name aButton .
    • Enter Show for the label parameter.
  3. Add a ColorPicker to the Stage and give it an instance name of aCp .
  4. Open the Actions panel, select Frame 1 in the main Timeline, and enter the following ActionScript code:
    aCp.visible = false; 
     
    aButton.addEventListener(MouseEvent.CLICK, clickHandler); 
     
    function clickHandler(event:MouseEvent):void { 
         
        switch(event.currentTarget.label) { 
            case "Show": 
                aCp.visible = true; 
                aButton.label = "Disable"; 
                break; 
            case "Disable": 
                aCp.enabled = false; 
                aButton.label = "Enable"; 
                break; 
            case "Enable": 
                aCp.enabled = true; 
                aButton.label = "Hide"; 
                break; 
            case "Hide": 
                aCp.visible = false; 
                aButton.label = "Show"; 
                break; 
        } 
    }
    
    The second line of code registers the function clickHandler() as the event handler function for the MouseEvent.CLICK event. The event occurs when a user clicks the Button, causing the clickHandler() function to take one of the following actions depending on the Button’s value:
    • Show makes the ColorPicker visible and changes the Button’s label to Disable.
    • Disable disables the ColorPicker and changes the Button’s label to Enable.
    • Enable enables the ColorPicker and changes the Button’s label to Hide.
    • Hide makes the ColorPicker invisible and changes the Button’s label to Show.
  5. Select Control > Test Movie to run the application.

Create an application with the Button component

The following procedure creates a toggle Button using ActionScript and displays the event type in the Output panel when you click the Button. The example creates the Button instance by invoking the class’s constructor and it adds it to the Stage by calling the addChild() method.
  1. Create a new Flash (ActionScript 3.0) document.
  2. Drag the Button component from the Components panel to the current document’s Library panel.
    This adds the component to the library, but doesn’t make it visible in the application.
  3. Open the Actions panel, select Frame 1 in the main Timeline and enter the following code to create a Button instance:
    import fl.controls.Button; 
     
    var aButton:Button = new Button(); 
    addChild(aButton); 
    aButton.label = "Click me"; 
    aButton.toggle =true;  
    aButton.move(50, 50);
    
    The move() method positions the button at location 50 (x coordinate), 50 (y coordinate) on the Stage.
  4. Now, add the following ActionScript to create an event listener and an event handler function:
    aButton.addEventListener(MouseEvent.CLICK, clickHandler); 
     
    function clickHandler(event:MouseEvent):void { 
        trace("Event type: " + event.type); 
    }
    
  5. Select Control > Test Movie.
    When you click the button, Flash displays the message, “Event type: click” in the Output panel.
------------------------------------------------------------------------------------------------------------------------
http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/A_702-From-ActionScript-2-To-ActionScript-3-0.html
------------------------------------------------------------------------------------------------------------------------
//AS3 myButton.buttonMode = true; //makes the cursor a hand, otherwise it shows the default arrow myButton.addEventListener(MouseEvent.MOUSE_DOWN, buttonPressed); function buttonPressed(event:MouseEvent):void { trace(event.currentTarget); //returns "[Object MovieClip]" trace(event.currentTarget.name); //returns "myButton" }

------------------------------------------------------------------------------------------
http://www.w3.org/TR/WCAG20-TECHS/flash#FLASH32
-----------------------------------------------------------------------------------------------------------------------


Example Code:
import fl.accessibility.ButtonAccImpl;
import fl.controls.Button;
import flash.accessibility. *
import flash.events.FocusEvent;
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;

ButtonAccImpl.enableAccessibility();
var states: Object = {
  "Alabama": "Alabama is a state located in the southeastern region of the \
    United States of America.",
  "California": "California is the most populous state in the United States",
  "New York": "New York is a state in the Mid-Atlantic and Northeastern \
    regions of the United States"
};

var buttons: Array =[];
var button: Button;
var accProps: AccessibilityProperties;
var count = 0;
for (var i in states) {
  button = new Button();
  button.label = i;
  button.addEventListener(MouseEvent.CLICK, clickHandler);
  button.addEventListener(MouseEvent.MOUSE_OVER, highlightHandler);
  button.addEventListener(MouseEvent.MOUSE_OUT, unHighlightHandler);
  button.addEventListener(FocusEvent.FOCUS_IN, highlightHandler);
  button.addEventListener(FocusEvent.FOCUS_OUT, unHighlightHandler);
  accProps = new AccessibilityProperties();
  accProps.description = states[i];
  button.accessibilityProperties = accProps;
  addChild(button);
  button.x = 30
  button.y = 30 + count * 30;
  buttons[i] = button;
  count++;
}

function highlightHandler(e) {
  descText.text = states[e.target.label];
}

function unHighlightHandler(e) {
  descText.text = "";
}


function clickHandler(e) {
  var url: URLRequest = new URLRequest("http://www.wikipedia.org/wiki/" + e.target.label);
  navigateToURL(url, "_self");
}

-----------------------------------------------------------------------------------------
http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html
---------------------------------------------------------------------------------------------------------------------

function boxClick(event:MouseEvent):void { trace("box click"); } function rootClick(event:MouseEvent):void { trace("root click"); } function stageClick(event:MouseEvent):void { trace("stage click"); } box.addEventListener(MouseEvent.CLICK, boxClick); root.addEventListener(MouseEvent.CLICK, rootClick); root.addEventListener(MouseEvent.CLICK, rootClick, true); stage.addEventListener(MouseEvent.CLICK, stageClick); stage.addEventListener(MouseEvent.CLICK, stageClick, true);

-----------------------------------------------------------------------------------
http://edutechwiki.unige.ch/en/ActionScript_3_event_handling_tutorial
----------------------------------------------------------------------------------------------------------------

btn_rainbow.addEventListener(MouseEvent.CLICK, clickHandler);
btn_tecfa.addEventListener(MouseEvent.CLICK, clickHandler);
btn_bosses.addEventListener(MouseEvent.CLICK, clickHandler);
btn_my_computers.addEventListener(MouseEvent.CLICK, clickHandler);
btn_credits.addEventListener(MouseEvent.CLICK, clickHandler);
The function itself looked like this:
function clickHandler(event:MouseEvent):void {
 switch (event.currentTarget.label)
 {
  case "Rainbow" :
   gotoAndStop(2);
   break;
  case "TECFA" :
   gotoAndStop(3);
   break;
  case "Bosses" :
   gotoAndStop(4);
   break;
  case "My computers" :
   gotoAndStop(5);
   break;
  case "Credits" :
   gotoAndStop(6);
   break;
 }
}




EmoticonEmoticon