Copy link to clipboard
Copied
Hey, I am new to adobe animate.. how to hide object/image one by one by clicking the same button multiple times?
Two approaches would be using array access (bracket notation) or storing the pencils in a vector or array.
Array access (bracket notation):
import flash.display.MovieClip;
import flash.events.MouseEvent;
var counter:int = 10;
minusbtn.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void
{
MovieClip(root)["pencil" + counter--].visible = false;
if (counter == 0)
e.currentTarget.removeEventListener(e.type, arguments.callee);
});
Vector / Array:
import flash.displa
...
Copy link to clipboard
Copied
Hi.
HTML5 Canvas
var root = this;
var button = root.yourButton;
var container = root.yourContainer; // symbol that contains all objects that need to be hidden
var counter = container.children.length;
button.on("click", function(e)
{
container.children[--counter].visible = false;
if (counter === 0)
e.remove();
});
AS3
import flash.display.SimpleButton;
import flash.display.MovieClip;
import flash.events.MouseEvent;
var button:SimpleButton = yourButton;
var container:MovieClip = yourContainer; // symbol that contains all objects that need to be hidden
var counter:int = container.numChildren;
button.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void
{
container.getChildAt(--counter).visible = false;
if (counter == 0)
e.currentTarget.removeEventListener(e.type, arguments.callee);
});
I hope it helps.
Regards,
JC
Copy link to clipboard
Copied
I have button with instance name "minusbtn" and ten movieclip I named "pencil1"...until "pencil10"..how do I apply to AS3 code you give?
Copy link to clipboard
Copied
Two approaches would be using array access (bracket notation) or storing the pencils in a vector or array.
Array access (bracket notation):
import flash.display.MovieClip;
import flash.events.MouseEvent;
var counter:int = 10;
minusbtn.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void
{
MovieClip(root)["pencil" + counter--].visible = false;
if (counter == 0)
e.currentTarget.removeEventListener(e.type, arguments.callee);
});
Vector / Array:
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.MouseEvent;
var pencils:Vector.<DisplayObject> = new <DisplayObject>
[
pencil1,
pencil2,
pencil3,
pencil4,
pencil5,
pencil6,
pencil7,
pencil8,
pencil9,
pencil10
];
minusbtn.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void
{
pencils.pop().visible = false;
if (pencils.length == 0)
e.currentTarget.removeEventListener(e.type, arguments.callee);
});
Regards,
JC
Copy link to clipboard
Copied
Thank you so much sir!
I dont expect to get an instance answer.
It works.
Copy link to clipboard
Copied
Great! You're welcome!