How to use the same script for several buttons

Hello

I have just started using flash if any help would be great!

I create a blockbuster game, I have a grid of 20 buttons and I need (individually) to turn blue on red and click double click. I managed to do it with the first using this code;

--------------------------------------------

var click: Boolean = false;

BN1.addEventListener (MouseEvent.CLICK, bn1click);

function bn1click(event:MouseEvent):void {}

clicked = true;

var newColorTransform:ColorTransform = bn1.transform.colorTransform;

{if (clicked)}

newColorTransform.color = 0 x 064258;

}

BN1. Transform.ColorTransform = newColorTransform;

}

/////////////

BN1.doubleClickEnabled = true;

var doubleclicked:Boolean = false;

BN1.addEventListener (MouseEvent.DOUBLE_CLICK, bn1dclick);

function bn1dclick(event:MouseEvent):void {}

DoubleClicked = true;

var newColorTransform:ColorTransform = bn1.transform.colorTransform;

{if (clicked)}

newColorTransform.color = 0xac1e23;

}

BN1. Transform.ColorTransform = newColorTransform;

}

--------------------------------------------

Now, I'll have trouble doing the same thing to work for the rest of the buttons, they are each named bn2, bn3 etc. They need to work individually and stay blue/red when clicked. I tried to list them as addEventListener orders but not with not a lot of success!

Any help would be greatly appreciated, thank you!

Tomo

To do this is to use arrays to follow the buttons and their properties.

var buttonList:Array = new Array (bn1, bn2, bn3);

var clickedList:Array = new Array();

var doubleClickedList:Array = new Array();

Then use a loop for to assign functions and properties for each button:

var thisMany:int = buttonList.length; This will give you the number of items in the buttonList array

for (var i: int = 0; i

buttonList [i] .addEventListener (MouseEvent.CLICK, btnClick); assign the function click on each button

buttonList [i] .addEventListener (MouseEvent.DOUBLE_CLICK, btnDClick); assign the double-click function

clickedList.push (false);  Add a value of false for each key in this table

doubleClickedList.push (false);

buttonList [i] .doubleClickEnabled = true; Set the property of double-tap for each button

}

function btnClick(event:MouseEvent):void {}

var thisButton:int = buttonList.indexOf (event.target);  know which button has been clicked as an element in the table

clickedList [Ceboutonselectionnel] = true;  Change the value in the table

var newColorTransform:ColorTransform is buttonList [Ceboutonselectionnel].transform.colorTransform;.

{if (clickedList [thisButton])}

newColorTransform.color = 0 x 064258;

}

buttonList [Ceboutonselectionnel].transform.colorTransform = newColorTransform;

}

function btnDClick(event:MouseEvent):void {}

var thisButton:int = buttonList.indexOf (event.target);

doubleClickedList [Ceboutonselectionnel] = true;

var newColorTransform:ColorTransform is buttonList [Ceboutonselectionnel].transform.colorTransform;.

{if (doubleClickedList [thisButton])}

newColorTransform.color = 0xac1e23;

}

buttonList [Ceboutonselectionnel].transform.colorTransform = newColorTransform;

}

Now you can have any number of buttons, just add their instance names in the table above.

Tags: Adobe Animate

Similar Questions

  • How can I use the same sound for several sounds?

    I need my program to play a lot of different mp3 files at different times.  I read that you cannot load different mp3 in the same variable sound files.  But there must be a way around this right?  Can I Unload mp3 files some how?  Or can I remove the sound variable and declare it again?  I don't want to have hundreds of sound variables then what should I do?  Thank you.

    create hundreds of sound variables.  just unnecessary loan for gc and that there should be no problem.

  • How to use the control quantity for several sliders in the basic settings window

    In a Webinar instructor (Chris Orwig) showed how to make multiple adjustments in the base Panel in the develop module.  Then, he showed how close the Basic module by clicking the small triangle at the top of the module.  The Basic module closed when it made a single control bar and the cursor appears instead. This move allowed the instructor set all previously defined parameters of basic module at the same time.  I tried to do.  But when I close the base module that no control bar and the slider appear.  Any suggestions why this is the case?

    I use Lightroom 5.4 and OS 10.9.2.

    Obviously, he wasn't in the base Panel, but in the adjustment brush:

    By clicking the triangle at the end of the red arrow, you get this:

    And there is your cursor effect.

    HAL

  • How to use the same services-config for servers the and remote.

    My flex project works very well using the bottom but when I download my flash on the server I do not work, all the files and related paths are the same execpt remote is a linux server.

    <? XML version = "1.0" encoding = "UTF-8"? >
    <>services-config
    < services >
    < id = 'amfphp-flashremoting-service' service
    Class = "Flex.Messaging.services.RemotingService"
    messageTypes = "flex.messaging.messages.RemotingMessage' >"

    < destination id = "amfphp" >
    <>channels
    < Ref channel = "my-amfphp" / >
    < / channels >
    Properties of <>
    < source > * < / source >
    < / properties >
    < / destination >
    < / service >
    < / services >
    <>channels
    < channel-definition id = "my-amfphp" class = "mx.messaging.channels.AMFChannel" >
    " < endpoint uri = ' http://localhost/domainn.org/AMFPHP/gateway.php "class="flex.messaging.endpoints.AMFEndpoint"/ > "
    < / channel-definition >
    < / channels >
    < / services-config >

    I think the problem is the line


    " < endpoint uri = ' http://localhost/domainn.org/AMFPHP/gateway.php "class="flex.messaging.endpoints.AMFEndpoint"/ > "

    but I don't know how to use the same services-config for servers the and remote.

    I'll back up a bit.

    Breakpoint URLS are defined as follows in the services - config.xml:

    https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure

    The meaning of each of the tokens is clearer when we see them as part of a complete url. If your context root is set to http://localhost , then I have no idea how your application runs in any environment.

    If you leave the server.name and server.port chips in your configuration file, then they will be replaced when executing according to the location from which your application is served. However, the context.root token is replaced at the time of the compilation based on the value that you specify in Flex Builder or when calling mxmlc.

    In order to reuse your file services - config.xml, you must use the same context-root on your development environment and to your deployment environment.

  • How to use the same user interface project for different HumanTask in GR 11, 1 material BPM

    When I set a user interaction activity in my process of material Oracle BPM 11 GR 1 and associate a human task with it. It generates a new project to contain all my forms. Anyone know if it is possible to use the same project for the different human task?

    After generating the UI for your first human task project, you can click with the right button on the project in JDeveloper and select 'New', click on the tab "Technologies all", then "JSF'-> ' ADF task based on human task workflow of." Then find the file your BPMN/composite project .task.

  • I made my largest site and how can keep the same size for all other sites?

    I did the 2 larger site and how to keep the same size for all pages when I re - open the web browser?

    You can use an extension to set a page zoom and the size of the default font on the web pages.

  • Try to use the same pattern for more than two channels (CSR configuration) with usb 6000

    Hello

    I am currently trying to implement a LabView code to get readings of voltage using 5 different places at the same time. I want to only use the first location in the ground and get 4 measurements of voltage between the ground and each of the other 4 channels. I use a USB 6000 which, for now, allows me to use the same pattern for only two channels. Is it possible to use the same pattern for 4 channels?

    Thank you

    Maria

    The images do not explain everything. You must explain what are the sensors. I think you totally wrong on how they should be linked. CSR, all sensors must be a common understanding and the outputs not individual channels as I have already explained. If you are unable to do this, you should probably not use CSR and you have the wrong data acquisition device. If you want a side of a sensor as a reference, you need differential connections.

  • Use the same script in different areas?

    Is it possible to use the same script in different areas?

    I had several scripts that will validate and modify the entries in the user on different areas. Since they do exactly the same thing, is it not possible to just get out the 'real' on a field script and refer to other fields to this script?

    Of course - we have a fragment of 'commonScriptObjects.xdp' that we all have

    our common methods of javascript in.  Then we add to the form and hide it.

    then use the following reference to point to the script object:

    GET A HANDLE TO THE SCRIPT OBJECT

    var commonScript =

    xfa.resolveNode ("commonScriptObjectsFrag.fragmentScript");

    CALL A JAVASCRIPT METHOD IN THE SCRIPT OBJECT

    commonScript.setupSearch ();

    Here's something else you can do to validate our mandatory fields.  We spend in

    the real to validate field and the name of the field as a text string:

    If (! commonScript.validateRequired (mainContentSubform.customerName,)

    False return 'Customer'));

    and the validateRequired method, which is in our commonScriptObject xdp

    file, looks like this:

    validate required fields

    function validateRequired (oField, fieldName) {}

    Console.println ("enter validateRequired");

    var commonScript =

    xfa.resolveNode ("commonScriptObjectsFrag.fragmentScript");

    If (commonScript.isNullValue (oField.rawValue))

    {

    xfa.host.messageBox ("Please fill out the '" + fieldName +)

    ("' field.", "Error", 3);

    xfa.host.setFocus (oField);

    Returns false;

    }

    Returns true;

    }

    Hope that helps,

    Elaine

    ocen12 [email protected]>

    29/07/2009 09:26

    Please respond to the

    [email protected]

    TO

    Amal [email protected]Schmitz >

    CC

    Object

    Use the same script in different areas?

    Is it possible to use the same script in different areas?

    I had several scripts that will validate and modify the entries in the user on

    different areas. Since they all do exactly the same thing, is not

    possible to just get out the 'real' on a field script and refer to the

    other areas of this script?

  • Is it possible to use the same password for two computers through quickbooks?

    We have two computers that are connected to each other through quickbooks and we must be able to get our e-mails from computers. Is this possible? We need to send invoices to the customers of a computer and the other is used for accounting and payroll.

    Original title: you can use the same password for two computers if they are already linked through quickbooks?

    Hi JayneB,

     

    (1) are you referring to the password of the user account?
    (2) who is the operating system installed on the computer?

     

    Method-

    I would like you to contact the Quickbooks support for assistance.

    Check out the link-

     

    QuickBooks support

     

    Hope this helps!

     

  • How to use the same point of view as read only in the ADF and editable

    Hello

    How to use the same point of view as read only in the ADF and editable? How can we succeed in TF?

    -James

    Hello

    Steven Davelaar wrote a presentation on this 'building highly reusable Taskflows.

    From slide 14, that's where your use case comes into play

    Frank

  • How to use the same mask, stencil, etc for several layers? Photoshop equivalent of the masked group?

    Hi I spent over half an hour for search manual, forums and the Internet and still can't find the answer. Help, please!

    For example, in a model with 5 or more layers, I want to use the same mask or stencil or what can hide layers 2,3 and 4 but areas layer 5 and all other possible layers below should not be affected.

    1. Before dialing the layers that you want to hide and apply a matte for the demo using the mask. Think to the Dial as an equivalent to the creation of a layer group.
    2. Use the effect on each layer you want to hide. It's easier to do if you apply mast set once and then create an animation preset to apply to the other layers. Just get mast set to do what you want it to do on the first layer, select Set Matte in ECW or in the timeline panel, and then go to the Animation > Save animation preset. Select then all other layers you want to apply the set matte to apply the preset.
    3. Put the mask at the bottom of the layers that you want to hide and turn on the switch to preserve transparency, then this group in composition with other layers of nesting.

    Here's another tip. You can set a custom color for all the layers you want to use the mast, then use the custom color for a group selection. This can make things easier down the line.

  • HP envy 14-2090eo: can I use the same drivers for windows 8 and 8.1

    When I check in drivers which operating systems there are drivers available for my Hp Envy 14-2090eo, it says Windows 8 (64-bit) and Windows 7 (64-bit), "and im currently using Windows 7 64 bit" but does that mean the drivers to support these 2 Windows 8 and 8.1 of Windows operating systems, said in a different way "» : are the same drivers for Windows 8 and Windows 8.1?

    Best regards from hpenvy1

    Hello:

    Your model has the AMD/Intel switchable graphics.

    It is unlikely that the W8 AMD graphics driver will work on W8.1.

    Normally, you can use some of the drivers W7/W8 on W8.1, but the graphics is very doubtful - not switchable graphics anyway.

    You can run the windows 8.1 upgrade wizard and see what it reports.

    http://Windows.Microsoft.com/en-us/Windows-8/Upgrade-Assistant-download-online-FAQ

  • How to use the different start for the resolution of specific device screen

    How to use different splash Screen for the resolution of specific device in Webworks for Smartphone.
    Please suggest me the solution.

    The BB10, you can use the element of the rim: splash:

    https://developer.BlackBerry.com/HTML5/documentation/rim_splash_element.html

  • If I use a web font in my Web site can I use the same font for documents printed such as company car

    I'm a graphic designer who intends to design a portfolio Web site in Adobe Muse. I intend to use TypeKit web fonts to design my Web site. On the Web site completioin, I have plan to design business cards and my CV to match the look of my site. I would use the same fonts I've used on the Web site. Is it possible to use web fonts for printing purposes? If this is not the case, what usually people do in this situation. The last thing I want to do is use a font that "similar" to those used on my site.

    Hi redsoxfan15b,

    (I think I can have answered your ticket of Support of Typekit earlier today, but I'll post here the same information to be certain).

    We have recently added a new feature to Typekit that can sync your desktop fonts and use them in print design. The announcement on our Web site has more details:

    http://blog.Typekit.com/2014/01/16/the-fonts-you-love-from-Typekit-now-on-your-desktop/

    Font sync is available on any portfolio Typekit, Performance or Business plan.  Here is a list of all available fonts to use the Office to:

    https://Typekit.com/fonts?licenses=desktop

    We continue to pay more of the library to use the desktop, but for now, you must confirm the police you want it available for both web and desktop.  And if there is a font you want to use is not available for desktop synchronization, you can also buy a license directly from the foundry.

    I hope this helps; Let me know if you have any other questions!  Best,

    -liz

  • Can we use the same package for main and begotten of concurrent programs.

    Hello

    I use a package.procedure1 for a simultaneous program. Can I use the same package.procedure2 of a pondu simultaneous program which was called from package.procedure1? If I say incompatible as the same program of 1, which will create problems by running the 2nd program because the package is same?

    Thank you
    HC

    I use a package.procedure1 for a simultaneous program. Can I use the same package.procedure2 of a pondu simultaneous program which was called from package.procedure1?

    Yes you can.

    If I say incompatible as the same program of 1, which will create problems by running the 2nd program because the package is same?

    When you second the 2nd program it will not work if the 1st program execution, and he has to wait until you have completed the 1st program.

    Don't know what code you use in the first and second procedures or even in the whole, but you can try this in a TEST instance first and check whether or not it works as expected.

    Thank you
    Hussein

Maybe you are looking for