Toggling the visibility of text
I need to figure out how to toggle the visibility of text in Canvas. I had it working with my old SWFs, but I haven’t been able to translate it to Canvas because I’m a JavaScript neonate. Before I can define what I need, I have to explain how my files are set up. They are stop action, animated lessons. They play until a point in the timeline is reached with a this.stop(); command. I call these stop points FreezeFrames. After the user studies a FreezeFrame , clicking the screen resumes playback until it reaches the next FreezeFrame . Now at each FreezeFrame explanatory text appears. What I need is a button that will toggle this text on and off. Each time the button is clicked it should also toggle itself between a Hide Text Button, which will turn it off, and a Text Button, which turns it back on. Note, these buttons need to work globally. If say the Text Button is clicked in one FreezeFrame , the text should remain on unless the Hide Text Button is clicked in a subsequent FreezeFrame.
Here’s how I set up my old ActionScript. I would be happy to show how I revised it for JavaScript, but that isn’t working so I’m not sure how helpful that would be. In the first frame of the file I define a variable I call togText as so.
var togTEXT:Boolean = true;
When a FreezeFrame is reached, the Hide Text Button is named BTN_hFrameName; the Text Button is BTN_tFrameName. BTN_tFrameName is placed in the layer above BTN_hFrameName. The text is placed in a movie clip called TX_FrameName. The following code is also written at the FreezeFrame.
TX_FrameName.visible = togTEXT;
BTN_tFrameName.visible = togTEXT;
BTN_hFrameName.visible = !togTEXT;
BTN_tFrameName.addEventListener(MouseEvent.CLICK, tFrameName);
function tFrameName(event:MouseEvent):void
{ togTEXT = !togTEXT;
TX_FrameName.visible = togTEXT;
BTN_tFrameName.visible = togTEXT;
BTN_hFrameName.visible = !togTEXT;
}
BTN_hFrameName.addEventListener(MouseEvent.CLICK, hFrameName);
function hFrameName(event:MouseEvent):void
{ togTEXT = !togTEXT;
TX_FrameName.visible = togTEXT;
BTN_tFrameName.visible = togTEXT;
BTN_hFrameName.visible = !togTEXT;
}
So that’s it. If anyone can tell me how to translate this ActionScript to JavaScript, or if anyone could give totally different JavaScript that will do what I need, I would greatly appreciate it.
