Search code examples
flashactionscript-3flash-cs4

Assigning links to buttons - All on same layer


I have a fla/swf file, with 6 buttons on it all with their own hover effects and such, however they're all on the same layer. So assigning a link to each one through actionscript is confusing as I've only done it if they were on different layers.

Any advice as to how to achieve this? (Using Flash cs4)


Solution

  • In general it does not make any difference if they are on the same layer or not. You have to assign a instance name to every button(e.g. "button01" and "button02" and then you can differentiate between them like:

    function init():void {
        button01.addEventListener(MouseEvent.MOUSE_CLICK,onActionPerformed,false,0,true);
        button01.addEventListener(MouseEvent.MOUSE_CLICK,onActionPerformed,false,0,true);
    }
    
    function onActionPerformed(e:MouseEvent):void {
        switch(e.currentTarget) {
           case button01: navigateToUrl(/*put your link in here*/); break;
           case button02: navigateToUrl(/*Put another link in here*/); break;
        }
    }