Skip to main content
rickhino
Inspiring
March 2, 2021
Answered

Trying to convert flash to javascript (part 2)

  • March 2, 2021
  • 1 reply
  • 2764 views

Okay here's part two:

I used to have this:


/*IndexNext1.addEventListener(MouseEvent.CLICK, IndxNext1);

function IndxNext1(event:MouseEvent):void
{
gotoAndPlay("Indx1");
}


Left Turn Stalk Behavior

leftStalk.addEventListener(MouseEvent.MOUSE_OVER, leftOver);

function leftOver(event:MouseEvent):void
{
this.leftStalk.gotoAndPlay("over");
}
leftStalk.addEventListener(MouseEvent.MOUSE_OUT, leftOut);

function leftOut(event:MouseEvent):void
{
this.leftStalk.gotoAndStop("stop");
}

leftStalk.addEventListener(MouseEvent.MOUSE_DOWN, leftClick);

function leftClick(event:MouseEvent):void
{
this.leftStalk.gotoAndStop("down");
}

leftStalk.addEventListener(MouseEvent.MOUSE_UP, leftUp);

function leftUp(event:MouseEvent):void
{
this.leftStalk.gotoAndPlay("over");
}

*/

 

And I tried replacing it with this.

 

this.leftStalk.addEventListener("mouseover", leftOver);

function leftOver()
{
this.leftStalk.gotoAndPlay('over');
}

 

this.leftStalk.addEventListener("mouseout", leftOut);

function leftOut()
{
this.leftStalk.gotoAndStop('stop');
}

 

this.leftStalk.addEventListener("onmousedown", leftClick.bind(this));

function leftClick()
{
this.leftStalk.gotoAndStop('down');
}


this.leftStalk.addEventListener("onmouseup", leftUp.bind(this));

function leftUp()
{
this.leftStalk.gotoAndPlay('over');
}

 

How much am I getting wrong?  LOL

 

Thanks in advance!

 

Rick

    This topic has been closed for replies.
    Correct answer kglad

    with as3, you don't need to explicitly reference the timeline that contains the objects and that you want to control.  with createjs, you need to explicitly reference those:  and with createjs and js, in general, there's no object typing:  and inside createjs functions, the timeline reference is lost.  one way to resolve that is to pass a reference to it using bind():

     

    this.IndexNext1.addEventListener("click", IndxNext1.bind(this));

    function IndxNext1(e)
    {
    this.gotoAndPlay("Indx1");
    }


    //Left Turn Stalk Behavior

    this.leftStalk.addEventListener("mouseover", leftOver.bind(this));

    function leftOver(e)
    {
    this.leftStalk.gotoAndPlay("over");
    }
    this.leftStalk.addEventListener("mouseout", leftOut.bind(this));

    function leftOut(e)
    {
    this.leftStalk.gotoAndStop("stop");
    }

    this.leftStalk.addEventListener("mousedown", leftClick.bind(this));

    function leftClick(e)
    {
    this.leftStalk.gotoAndStop("down");
    }

    this.leftStalk.addEventListener(""mouseup, leftUp.bind(this));

    function leftUp(e)
    {
    this.leftStalk.gotoAndPlay("over");
    }

     

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    March 2, 2021

    with as3, you don't need to explicitly reference the timeline that contains the objects and that you want to control.  with createjs, you need to explicitly reference those:  and with createjs and js, in general, there's no object typing:  and inside createjs functions, the timeline reference is lost.  one way to resolve that is to pass a reference to it using bind():

     

    this.IndexNext1.addEventListener("click", IndxNext1.bind(this));

    function IndxNext1(e)
    {
    this.gotoAndPlay("Indx1");
    }


    //Left Turn Stalk Behavior

    this.leftStalk.addEventListener("mouseover", leftOver.bind(this));

    function leftOver(e)
    {
    this.leftStalk.gotoAndPlay("over");
    }
    this.leftStalk.addEventListener("mouseout", leftOut.bind(this));

    function leftOut(e)
    {
    this.leftStalk.gotoAndStop("stop");
    }

    this.leftStalk.addEventListener("mousedown", leftClick.bind(this));

    function leftClick(e)
    {
    this.leftStalk.gotoAndStop("down");
    }

    this.leftStalk.addEventListener(""mouseup, leftUp.bind(this));

    function leftUp(e)
    {
    this.leftStalk.gotoAndPlay("over");
    }

     

    rickhino
    rickhinoAuthor
    Inspiring
    March 2, 2021

    WoW!

     

    Thanks for all the input.  I'm not sure I understand the "bind" concept and I'll have to go through your code slowly, but you have no idea how much I appreciate the help!

    Next problem is how to replace:

     

    Object(this.parent).GovernerLine.gotoAndPlay("On");

    LOL!

    Thanks Again!

    kglad
    Community Expert
    Community Expert
    March 2, 2021

    again, no object typing so Object() can't be used (and is unnecessary):

     

    this.parent.GovernerLine.gotoAndPlay("On");