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

Please help me convert from AS3 to javascript

New Here ,
Oct 22, 2020 Oct 22, 2020

Copy link to clipboard

Copied

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");

               }

}

Views

222

Translate

Translate

Report

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
Community Expert ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Advisor ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

Hi Joseph,

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

Votes

Translate

Translate

Report

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
New Here ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

Actually, I have. I can't find anything about replacing the lines

import flash.display.MovieClip;

import flash.events.KeyboardEvent;

import flash.text.TextField;

Votes

Translate

Translate

Report

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
LEGEND ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

You don't replace those lines. CreateJS doesn't have to import any libraries, everything is loaded by default.

Votes

Translate

Translate

Report

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
New Here ,
Oct 25, 2020 Oct 25, 2020

Copy link to clipboard

Copied

Thanks. I couldn't find anything on that anywhere. I struggle with the coding because I'm a artist, not a programmer type. I learned AS2 long ago and it worked for me, but since then it's a struggle. I can't find anything about the onfocus bit either. My script just isn't working. Thanks.

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
New Here ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

How can I send you a .fla example?

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
New Here ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

I'm not sure how to use a file sharing service as they are blocked by our company (I'm on our intranet). Is there an email address where I could send the .fla? I made an example file that is only 40kb.

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

Certainly.

 

Please send to joaocesar.design@gmail.com.

Votes

Translate

Translate

Report

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
New Here ,
Oct 29, 2020 Oct 29, 2020

Copy link to clipboard

Copied

LATEST

I found a glitch in the code. Theoretically, I should be able to click on a movie clip and press keys to change from color to color without having to click the movie clip again. However, I cannot go from Brown (End key) to Gray (Delete Key). It happens in your v2 file too.

Votes

Translate

Translate

Report

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