Skip to main content
Participating Frequently
October 22, 2020
Question

Please help me convert from AS3 to javascript

  • October 22, 2020
  • 11 replies
  • 576 views

Hi folks, Can someone please help me convert this AS3 to javascript? I have an illustration with dozens of movie clips. When the user clicks on a movie clip, it becomes active and when they press certain keys on the keyboard, it plays a frame of the movie clip and changes color. A lot of this is redundant because there are 6 states/colors and I use some numbers, keyboard and key pad. I have this.stop(); at the end of each state in the movie clips, but the rest has me baffled. Also, I used the Flash Input Text Component, so the user could enter a number, but they no longer work with javascript. What can I use instead? Thanks.

 

import flash.display.MovieClip;

import flash.events.KeyboardEvent;

import flash.text.TextField;

 

var selectedMC:MovieClip;

 

stage.stageFocusRect = false;

 

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

{

               if (stage.getChildAt(i) is MovieClip)

               {

                              var tmpObj:MovieClip = MovieClip(stage.getChildAt(i));

               tmpObj.addEventListener(MouseEvent.CLICK, OnItemClicked);

                             

               if(tmpObj.hasOwnProperty("numChildren"))

                              {

                                             for(var j:int = 0; j < tmpObj.numChildren; j++)

                                             {

                                                            if (tmpObj.getChildAt(j) is MovieClip)

                                                            {

                                                                           var mc:MovieClip = MovieClip(tmpObj.getChildAt(j));

                                                            mc.addEventListener(MouseEvent.CLICK, OnItemClicked);

                                                                           //trace ("ADDED KEY CB to" + mc + mc.name);

                                                            }

                                             }

                              }

                }

}

 

function OnItemClicked(e:MouseEvent)

{

               if(e.currentTarget == bg)

               {

                              stage.focus = null

                              trace("OnItemClicked == bg");

                              return;

               }

              

               if(e.currentTarget == this)

               {

                              return;

               }

 

               if(e.currentTarget is InteractiveObject)

               {

                              stage.focus = InteractiveObject(e.currentTarget);

               }

              

               //trace("T" , e.target , e.target is MovieClip);

               if(e.currentTarget is MovieClip)

               {

                              selectedMC = MovieClip(e.currentTarget);

                              trace(selectedMC);

                              //trace("SELECTED ME" + selectedMC + selectedMC.name + e.currentTarget.name);

               }

}

 

stage.addEventListener(KeyboardEvent.KEY_DOWN, OnKeyPress);

 

function OnKeyPress(e:KeyboardEvent)

{

               //trace("KEY PRESSED", e.keyCode);

              

               if(!selectedMC)

               {

                              return;

               }

 

               if (e.keyCode == 40)

               {

                              selectedMC.gotoAndPlay ("black");

               }

               else if (e.keyCode == 39)

               {

                              selectedMC.gotoAndPlay ("red");

               }

               else if (e.keyCode == 38)

               {

                              selectedMC.gotoAndPlay ("blue");

               }                                                          

               else if (e.keyCode == 37)

               {

                              selectedMC.gotoAndPlay ("cyan");

               }

               else if (e.keyCode == 46)

               {

                              selectedMC.gotoAndPlay ("gray");

               }

               else if (e.keyCode == 32)

               {2

                              selectedMC.gotoAndPlay ("brown");

               }

               else if (e.keyCode == 48)

               {

                              selectedMC.gotoAndPlay ("empty");

               }

               else if (e.keyCode == 96)

               {

                              selectedMC.gotoAndPlay ("empty");

               }

               else if (e.keyCode == 49)

               {

                              selectedMC.gotoAndPlay ("20%");

               }

               else if (e.keyCode == 97)

               {

                              selectedMC.gotoAndPlay ("20%");

               }

               else if (e.keyCode == 50)

               {

                              selectedMC.gotoAndPlay ("40%");

               }

               else if (e.keyCode == 98)

               {

                              selectedMC.gotoAndPlay ("40%");

               }

               else if (e.keyCode == 51)

               {

                              selectedMC.gotoAndPlay ("60%");

               }

               else if (e.keyCode == 99)

               {

                              selectedMC.gotoAndPlay ("60%");

               }

               else if (e.keyCode == 52)

               {

                              selectedMC.gotoAndPlay ("80%");

               }

               else if (e.keyCode == 100)

               {

                              selectedMC.gotoAndPlay ("80%");

               }

               else if (e.keyCode == 53)

               {

                              selectedMC.gotoAndPlay ("full");

               }

               else if (e.keyCode == 101)

               {

                              selectedMC.gotoAndPlay ("full");

               }

}

    This topic is closed to new replies. Start a new post to keep the conversation going.

    11 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    October 26, 2020

    Hi.

     

    Can you provide a working example? I think it will be easier for us to help you if we know exactly what you want to do.

     

    Regards,

    JC

    Participating Frequently
    October 26, 2020

    How can I send you a .fla example?

    JoãoCésar17023019
    Community Expert
    Community Expert
    October 26, 2020

    You can upload the FLA to a file sharing service like Google Drive, OneDrive, Dropbox, WeTransfer or any other you choose and paste the link here.

    Joseph Labrecque
    Community Expert
    Community Expert
    October 23, 2020

    Hi. Have you checked the CreateJS docs? This should be pretty straightforward to convert - you'd just need to find equivalent functions: https://createjs.com/docs 
    Also - HTML5 Canvas has a Text Input component you can use for the user to enter text or numbers.

    Robert Mc Dowell
    Legend
    October 23, 2020

    Hi Joseph,

    do you know any demo of camera publish and audio/video streaming with createJS?