• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

224

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

Community Expert , 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
...

Votes

Translate

Translate
Community Expert ,
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

Votes

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?

Votes

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 Expert ,
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

Votes

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.

Votes

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 Expert ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

LATEST

Great! You're welcome!

Votes

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