Skip to main content
Arioman
Inspiring
July 13, 2013
Answered

connect KeyboardEvent to visible false/True button

  • July 13, 2013
  • 1 reply
  • 1202 views

i use simple script to Hide Prev Button in First Frame and Next Button in Last Frame

Prevbt_forproduct.visible = false;

nextbt_forProduct.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame);

function fl_ClickToGoToNextFrame(event:MouseEvent):void

{

    nextFrame();

     Prevbt_forproduct.visible = true;

     if(currentFrame == totalFrames){

     nextbt_forProduct.visible = false;

}

}

Prevbt_forproduct.addEventListener(MouseEvent.CLICK, fl_ClickToGoToPreviousFrame);

function fl_ClickToGoToPreviousFrame(event:MouseEvent):void

{

    prevFrame();

    nextbt_forProduct.visible = true;

    if(currentFrame == 1){

    Prevbt_forproduct.visible = false;

}

}

and i use Keyboard Function for Add Right and Left Key for Go to  Next and Prev Frame

import flash.display.Stage;

import flash.events.KeyboardEvent;

import flash.ui.Keyboard

stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);

function keyHandler(e:KeyboardEvent):void

{

switch(e.keyCode){

case Keyboard.RIGHT: nextFrame();break;

case Keyboard.LEFT:prevFrame();break;

}

}

now The Problem is , when i use Keyboard to Change between Frames the nextbt and Prevbt are not change , in other mean it does not matter how much i press Right or Left key the Prevbt Button Not apear ( frames changes well )

So how can i set a connection between these Scripts ?

thanks

This topic has been closed for replies.
Correct answer kglad

use:

Prevbt_forproduct.visible = false;

nextbt_forProduct.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame);

function fl_ClickToGoToNextFrame(event:MouseEvent):void
{
    nextFrame();
nextPrevF()
}
}


Prevbt_forproduct.addEventListener(MouseEvent.CLICK, fl_ClickToGoToPreviousFrame);

function fl_ClickToGoToPreviousFrame(event:MouseEvent):void
{
    prevFrame();
nextPrevF();
}
}

import flash.display.Stage;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard

stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);

function keyHandler(e:KeyboardEvent):void
{
switch(e.keyCode){
case Keyboard.RIGHT: nextFrame();break;
case Keyboard.LEFT:prevFrame();break;
}
nextPrevF();
}

function nextPrevF():void{

if(currentFrame!=totalFrames){
nextbt_forProduct.visible = true;
} else {
nextbt_forProduct.visible=false;
}
    if(currentFrame == 1){
    Prevbt_forproduct.visible = false;
} else {

  Prevbt_forproduct.visible = true;

}
}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 13, 2013

use:

Prevbt_forproduct.visible = false;

nextbt_forProduct.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame);

function fl_ClickToGoToNextFrame(event:MouseEvent):void
{
    nextFrame();
nextPrevF()
}
}


Prevbt_forproduct.addEventListener(MouseEvent.CLICK, fl_ClickToGoToPreviousFrame);

function fl_ClickToGoToPreviousFrame(event:MouseEvent):void
{
    prevFrame();
nextPrevF();
}
}

import flash.display.Stage;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard

stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);

function keyHandler(e:KeyboardEvent):void
{
switch(e.keyCode){
case Keyboard.RIGHT: nextFrame();break;
case Keyboard.LEFT:prevFrame();break;
}
nextPrevF();
}

function nextPrevF():void{

if(currentFrame!=totalFrames){
nextbt_forProduct.visible = true;
} else {
nextbt_forProduct.visible=false;
}
    if(currentFrame == 1){
    Prevbt_forproduct.visible = false;
} else {

  Prevbt_forproduct.visible = true;

}
}
Arioman
AriomanAuthor
Inspiring
July 13, 2013

thanks so much , i dont know what can i say or how say my thanks to you dear Kglad .

kglad
Community Expert
Community Expert
July 13, 2013

you're welcome.