Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Looping through stage children in Flash Professional CC 2014 with JavaScript

New Here ,
Feb 14, 2017 Feb 14, 2017

So I'm just starting to make the move from swf output to HTML. I know AS3 as well as JavaScript, but I can't wrap my head around how to effectively use JavaScript in the context of a Flash document.

I'm making an interactive piece where users need to click on keys on a virtual keyboard (represented as a png of a keyboard with clickable buttons placed over each key). Each of these buttons is essentially the same, but they each need a unique identifier ('esc', 'ctrl', 'f1', etc.). Additionally, I would like to be able to assign event listeners to each of these buttons easily.

I started with AS3 and swf output, but for compatibility reasons, I had to switch to HTML5 output.

To better explain what I'm asking, here is a sample of my original code, and of my converted code.

Original AS3:

//Add event listeners to each button on the stage (I have a movieClip named buttons that contains all buttons)

function SetEventListeners(){

  for(var i:int = 0; i < buttons.numChildren; i++){

       var button = buttons.getChildAt(i);

       button.buttonMode = true;

       button.addEventListener(MouseEvent.CLICK, ClickButton);

  }

}

//Called by each button being clicked. Performs appropriate action based on which button was clicked.

function ClickButton(e:MouseEvent){

     var button = e.target;

     switch(button.name){

          case "esc":

          //doSomething

          break;

          case "f1":

          //doSomethingElse

          break;

          default:

          //doSomeDefaultStuff

          break;

     }

}

New JavaScript:

this.esc.addEventListener("click", ClickEsc);

this.f1.addEventListener("click", ClickF1);

function ClickEsc(){

     //doSomething

{

function ClickF1(){

     //doSomethingElse

{

As you can see, my JS is going to be extremely bloated and unmaintainable if I take this approach (I'll have to set up a separate function to handle each simulated 'keypress'.

Here are my questions:

  1. How can I add event listeners to each button without explicitly doing so as in the JS example above?
  2. How can I determine which button was clicked if each button is assigned the same function to execute when clicked (i.e. how can I pass the button's name to the called function)?
  3. Is there some resource for learning JS with Flash? My googling has not yielded good results.
TOPICS
Exchange extensions
879
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 14, 2017 Apr 14, 2017
LATEST

Hi Jake,
   You can get resource here.

http://help.adobe.com/en_US/flash/cs/extend/flash_cs5_extending.pdf

But since I work on JSFL, i must say there are lot of things broken, and things don't work as they are supposed to work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines