Skip to main content
Inspiring
June 30, 2017
Answered

Undo Button for Coloring Game

  • June 30, 2017
  • 2 replies
  • 2569 views

I have a coloring game with the following script on the color swatches (paint icons on the picture):

on (release) {

_root.fillColor = 0x000000;

var efeksoundcelup:Sound = new Sound()

efeksoundcelup.attachSound("celup");

efeksoundcelup.start();

_root.brush.gotoAndStop(2);

}

and the following code for the fill area (part of stick icon in the picture)

for every time I fill the the fill area, no other color could fill that area, and the swatches (paint) height reduce.

on (release) {

if(_root.catputih._height != 0 && _parent.warna1 == false && _root.fillColor == 0xE9E9E9)

{

iColor = new Color(this);

iColor.setRGB(_root.fillColor);

_root.catputih._y=343.4 + 42-(_root.catputih._height - 42*0.25);

_root.catputih._height=_root.catputih._height - 42*0.25;

trace("wah iya");

var efeksoundcat:Sound = new Sound();

efeksoundcat.attachSound("ngecat");

efeksoundcat.start();

_parent.warna1 = true;

}

else if(_parent.warna1 == true)

{

var efeksoundcat:Sound = new Sound();

efeksoundcat.attachSound("blup");

efeksoundcat.start();

//warna1 = true;

trace("2 udah ada");

}

}

and the question is:

how is the script for an undo button? what I want is, every time the undo button clicked, the previous fill color disappear and the height of that color increase.

thank you,

Ratna

This topic has been closed for replies.
Correct answer kglad

the trace in the movieclip button shows _level0.s1 // s1 is the instance name of my stick movieclip

the trace in the timeline shows _level0


from your movieclip button use:

_parent.sticks to reference your sticks array that's on the main timeline.

2 replies

July 13, 2017

Memento pattern is used for situations like this. A quick Google search yielded an article which explains how it is implemented.

kglad
Community Expert
Community Expert
June 30, 2017

use an array to track 'this' from line 4 and _root.fillColor from line 5

you would then typically repaint the last array element using the background color, but with your background you would apply pop() to your array to remove the last element and reapply all the colorings anew.

Inspiring
July 11, 2017

Thanks for your input Sir. So I have tried making an array for the "this" or sticks and the paint or _root.fillColor as you suggest.

var sticks :Array = ["stick1", "stick2", "stick3", "stick4"]

var rootcol :Array = ["_root.white", "_root.black", "_root.green", "_root.blue", "_root.yellow", "_root.orange", "_root.red", "_root.brown"];

is it correct to state the array at the first? because the painting process is random, user can paint any stick with no order required.

or should I use push every time the stick is painted? (but It didn't work, it's not added to the array)

kglad
Community Expert
Community Expert
July 11, 2017

yes, push the color and region painted into the array.