Hide object/image one by one

Community Beginner ,
Apr 19, 2022 Apr 19, 2022

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?

Views

89

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Apr 19, 2022 Apr 19, 2022
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...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 19, 2022 Apr 19, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 19, 2022 Apr 19, 2022

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 19, 2022 Apr 19, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Thank you so much sir!

I dont expect to get an instance answer.

It works.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

LATEST

Great! You're welcome!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines