How to Toggle A Movieclip to appear on a Button's Mousehover HTML Canvas - actionscript-3

I am using Animate CC 2017 and Canvas as my document. I have an animated button and a Movieclip. I want to know How to Toggle the Movieclip to appear on my Animated button's mousehover.
Button Instance Name is : button_1
Clip Instance name is : injector
I have only one keyframe on my animated screen.
Below is the code what I am doing
var frequency = 3;
stage.enableMouseOver(frequency);
this.button_1.addEventListener("mouseover", fl_MouseOverHandler);
function fl_MouseOverHandler()
{
if (injector.alpha == 0)
{
injector.alpha = 1;
}
else
{
injector.alpha = 0
}
}
So this condition is not working but alert working fine.

Did you check for javascript errors in the console?
If not, I suspect it's because 'injector' is not in scope. Try this:
var frequency = 3;
stage.enableMouseOver(frequency);
this.button_1.addEventListener("mouseover", fl_MouseOverHandler);
var ref = this;
function fl_MouseOverHandler()
{
if (ref.injector.alpha == 0)
{
ref.injector.alpha = 1;
}
else
{
ref.injector.alpha = 0
}
}

Related

Flash reverse timeline

Worked with flash cs6 and as3.
I wanted to make menu like this link. When mouse_over on the menu, the blue rectangle moves to the right; and when mouse_up, the animation reversed.
I made the blue rectangle in a movieclip menuBlueHome. There, I made the rectangle moves from left to right (from frame 1 to 10). At frame 10, I made action script:
stop();
I was still working with home menu when I faced this problem. When I hover the home menu, the blue rectangle moves to the right and reversed straightaway before mouse_up. Here is the code outside the mc:
var menuBlueHome: MovieClip;
menuBlueHome.stop();
var direct: String;
btnHome.addEventListener(MouseEvent.MOUSE_OVER,onOverHome);
btnHome.addEventListener(MouseEvent.MOUSE_OUT,onLeaveHome);
btnHome.addEventListener(MouseEvent.CLICK,onClickHome);
function onOverHome(e:MouseEvent):void{
androidHome.visible = true;
menuBlueHome.play();
}
function onLeaveHome(e:MouseEvent):void{
androidHome.visible = false;
addEventListener(Event.ENTER_FRAME,onFrameHome);
}
function onClickHome(e:MouseEvent):void{
gotoAndStop(1);
}
function onFrameHome(event:Event):void {
if(menuBlueHome.currentFrame > 9) {
direct = "backward";
}
var backAmount:Number = menuBlueHome.currentFrame -1;
if(direct == "backward") {
menuBlueHome.gotoAndStop(backAmount);
}
}
Did I make something wrong with the code? Thanks for your help.
Try with this code:
function onLeaveHome(e:MouseEvent):void{
androidHome.visible = false;
menuBlueHome.removeEventListener(Event.ENTER_FRAME, onFrameHome);
menuBlueHome.addEventListener(Event.ENTER_FRAME, onFrameHome);
}
function onFrameHome(event:Event):void {
var backAmount:Number = menuBlueHome.currentFrame - 1;
menuBlueHome.gotoAndStop(backAmount);
if(backAmount == 1) menuBlueHome.removeEventListener(Event.ENTER_FRAME, onFrameHome);
}
Here you have and example.
But, I recommend you to do your code more dynamic, here you have another example.

scrollable activity in as3 is not working perfect for android air

i want to make a scrollable index of particular math book for android version where i will be able to scroll a movie clip consists of 56 child movieclips(there are chapter 1 to chapter 56 child clips has made "buttons_all" parentclip) and when i will choose a child movie clip it will go to selected label or chapter(suppose if i click chapter 1 movie clip it will gotoAndPlay("chapter 1")).i had made the parent movieclip scrollable and added eventlistener to each child movie clip..but when i want to scroll it is doing two things,first it scrolls then go to that "chapter" that i clicked to start scrolling whether i want to go this chapter or not.to solve that i added a timer event to create an interval to stop selecting chapter immediately before i want to select a specific chapter..but it is working partially.i want to add this interval to every button.because i dont have a scrollbar here for up and down..please help me to solve this..here is my part of code
var pat1:MovieClip = scrolling_manu.buttons_all.part1;
var listTimer:Timer; // timer for all events
var tapDelayTime:Number = 0;
var maxTapDelayTime:Number = 20; // change this to increase or descrease tap sensitivity
var tapEnabled:Boolean = false;
init();
function init()
{
//removeEventListener(Event.ADDED_TO_STAGE, init);
pat1.addEventListener(TouchEvent.TOUCH_BEGIN, onmouseDown );
//trace("hit");
pat1.addEventListener(TouchEvent.TOUCH_END, onmouseUp );
listTimer = new Timer( 33 );
listTimer.addEventListener( TimerEvent.TIMER, onListTimer);
listTimer.start();
}
function onmouseDown( e:TouchEvent ):void
{
handleItemPress()
}
function onmouseUp( e:TouchEvent ):void
{
onTapDisabled();
//listTimer.stop();
}
function onListTimer(e:Event):void
{
// test for touch or tap event
if(tapEnabled)
onTapDelay();
}
function onTapDisabled():void
{
tapEnabled = false;
tapDelayTime = 0;
}
function onTapDelay():void
{
tapDelayTime++;
if(tapDelayTime > maxTapDelayTime )
{
//tapItem.selectItem();
tapDelayTime = 0;
tapEnabled = false;
trace("hit");
pat1.gotoAndPlay("over1");
pat1.addEventListener(TouchEvent.TOUCH_END, onmouseUp );
}
}
function handleItemPress()
{
tapDelayTime = 0;
tapEnabled = true;
trace("hit");
}
Firstly, I recommend you to convert all vector images to raster. It's very hard for processor to animate vector images.
Delete all code after drop_me function.
Write this:
scrolling_manu.buttons_all.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
scrolling_manu.buttons_all.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
var touchedPart:MovieClip;
var posY:int;
function onTouchBegin(event:TouchEvent):void
{
touchedPart = event.target as MovieClip;
posY = scrolling_manu.buttons_all.y;
}
function onTouchEnd(event:TouchEvent):void
{
// if list was been moved, that isn't a tap.
if (posY == scrolling_manu.buttons_all.y)
{
trace("part tapped", touchedPart.name);
touchedPart.gotoAndPlay("over1");
}
}

Path glow effect in the mouse over event in actionscript 3

I'm building a board game in action script 3 Adobe flash. In that if i mouseover on a particular pawn, it has to show the number of steps which can be moved by that pawn with respect to dice value with path glow effect.
Here in my code path will glow after i move the pawn with respect to dice number.
opawn1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_3);
function fl_ClickToGoToAndStopAtFrame_3(event: Mouse): void {
var filterarray: Array=new Array();
opawn1.filters=[glow];
var gfilter: GlowFilter=new GlowFilter();
filterarray.push(gfilter);
current_pawn = arrayPawn[0];
checkSize(opawn1);
if (o_move == 0) {
o_move = 1;
convert_to_movieclip(s1);
}
temp = get_number_of_moves(odirectmove, checkorange, 0, current_pawn);
odirectmove = false;
for(var i=0;i<temp+1;i++)
{
s1[i].filters=filterarray;
}
Here I used mouse click event, Its not working if i change it as mouseover.
Please let me know the above code is correct or not.
How to achieve this?
As #otololua said, the type of your fl_ClickToGoToAndStopAtFrame_3 event parameter should be MouseEvent and not Mouse, then you can change MouseEvent.CLICK by MouseEvent.MOUSE_OVER like this :
opawn1.addEventListener(MouseEvent.MOUSE_OVER, opawn1_on_MouseOver);
function opawn1_on_MouseOver(event:MouseEvent): void {
var glow_filter: GlowFilter = new GlowFilter();
var filters_array: Array = [glow_filter];
your_target_object.filters = filters_array
// ...
}
And if you need that effect be visible only when the mouse is over, you can remove it using MouseEvent.MOUSE_OUT like this :
opawn1.addEventListener(MouseEvent.MOUSE_OUT, opawn1_on_MouseOut);
function opawn1_on_MouseOut(event:MouseEvent): void {
your_target_object.filters = null;
// ...
}
Hope that can help you.

Hide button after click two times or more on as3

i am new on as3.
i want to ask how to hide button after click two times or more on as3.
the code below i got from code snippets, but the button hide after one click.
BTNhint.addEventListener(MouseEvent.CLICK, fl_ClickToHide);
function fl_ClickToHide(event:MouseEvent):void
{
BTNhint.visible = false;
}
You have just to count the button clicks and then after two clicks you can hide your button :
var click_counter:int = 0;
BTNhint.addEventListener(MouseEvent.CLICK, fl_ClickToHide);
function fl_ClickToHide(event:MouseEvent):void
{
click_counter ++; // you can write it : click_counter = click_counter + 1;
if(click_counter >= 2){ // you can write it : if(click_counter > 1)
BTNhint.visible = false;
}
}
You can use a constant (LIM) to determine how many times your button must be clicked, compare it to a variable (c) that is counting your clicks, and use your MouseEvent's target property to target your button itself when you want it to disappear:
var c:int = 0;
const LIM:int = 2;
BTNhint.addEventListener(MouseEvent.CLICK, hideMe);
function hideMe(event:MouseEvent):void
{
if(++c >= LIM) event.target.visible = false;
}

Issue with MOUSE_MOVE and MOUSE_OUT applied to stage

I'm having an issue with MOUSE_OUT being called while it shouldn't. What I'm doing is quite simple: two images are shown when I move the mouse across the stage, and when the mouse leaves the stage they are hidden.
The problem is, that whenever the mouse hits the border of any movieclip on the stage, the MOUSE_OUT function gets called, hiding the two images. This means that whenever I move the mouse
My code (only the relevant parts are shown):
public class Slider extends MovieClip {
var img1:Img1 = new Img1;
var img2:Img2 = new Img2;
var img1_hover:Img1_hover = new Img1_hover;
var img2_hover:Img2_hover = new Img2_hover;
public function Slider() {
img1.alpha = 0;
img2.alpha = 0;
stage.addEventListener(MouseEvent.MOUSE_MOVE, showArrows);
}
function showArrows(e:MouseEvent) {
img1.alpha = 1;
img2.alpha = 1;
stage.addEventListener(MouseEvent.MOUSE_OUT, hideArrows);
}
function hideArrows(e:MouseEvent) {
img1.alpha = 0;
img2.alpha = 0;
}
}
Flash throws no errors. I am using a separate .as file (just one) and have no code inside of the action panel in the .fla.
Where there's stage.addEventListener, I also tried this., root. and nothing instead of stage.
You want to use the MOUSE_LEAVE event instead http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#event:mouseLeave
Alternatively, in the hideArrows function you can check the target of the event:
function hideArrows(e:MouseEvent) {
If(e.target == stage){
img1.alpha = 0;
img2.alpha = 0;
}
}