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

Undo Button for Coloring Game

Explorer ,
Jun 30, 2017 Jun 30, 2017

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");

}

}

flash cat.PNG

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

TOPICS
ActionScript
2.3K
Translate
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 , Jul 11, 2017 Jul 11, 2017

from your movieclip button use:

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

Translate
Community Expert ,
Jun 30, 2017 Jun 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.

Translate
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
Explorer ,
Jul 11, 2017 Jul 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)

Translate
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 ,
Jul 11, 2017 Jul 11, 2017

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

Translate
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
Explorer ,
Jul 11, 2017 Jul 11, 2017

when should I push? on release function when I paint? but it didn't work, they're not added to the array.

I have this on the timeline:

sticks = ["first"];

I added this line on the fill area/stick:

sticks.push(stick1);

or

sticks.push("stick1");

but the trace(sticks) only show first, nothing added.

Translate
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 ,
Jul 11, 2017 Jul 11, 2017

where's the trace?

Translate
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
Explorer ,
Jul 11, 2017 Jul 11, 2017

I put the trace in the fill area, it shows undefined.

on the timeline, it shows first only

I even make a button to trace, but also it shows first only.

Translate
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 ,
Jul 11, 2017 Jul 11, 2017

your button is probably a movieclip button and you don't understand that the scope of your onrelease is not the same as the timeline where you defined sticks.

Translate
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
Explorer ,
Jul 11, 2017 Jul 11, 2017

yes, my button is inside the movie clip

based on many tutorials about coloring, the fill area is a button inside a movie clip

so, what should I do sir? please help me

Translate
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 ,
Jul 11, 2017 Jul 11, 2017

use trace(this) in you movieclip button and the timeline where sticks is defined to see the path from one to the other.

Translate
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
Explorer ,
Jul 11, 2017 Jul 11, 2017

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

Translate
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 ,
Jul 11, 2017 Jul 11, 2017

from your movieclip button use:

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

Translate
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
Explorer ,
Jul 11, 2017 Jul 11, 2017

wow! thank you so much Sir, it works really well for the array, both for the fill area and the paint.

and I hope the following is the last error in this discussion.

I've made an undo button and put this:

on(release){

     lostStick = sticks.pop();

     lostCol = fillcol.pop();

     var lost = new Color(lostStick);

     lost.setRGB(0xC28640);

     var hight = new height(_root.lostCol);

     hight.height(42);

}

the color did change to brown (0xC28640), but the height of the paint didn't change to 42.

I also tried this on the undo button without .pop (I directly change the white btn) and it works

on(release){

     lostStick = sticks.pop();

     //lostCol = fillcol.pop();

     var lost = new Color(lostStick);

     lost.setRGB(0xC28640);

     white._y=343.4; //white is the white paint button

     white._height=42;

}

but when I combined with .pop, like this, it didn't works.

on(release){

     lostStick = sticks.pop();

     lostCol = fillcol.pop();

     var lost = new Color(lostStick);

     lost.setRGB(0xC28640);

     lostCol._y=343.4; //white is the white paint button

     lostCol._height=42;

}

The following traces are in a button, it shows everything right

trace(sticks);

trace(fillcol);

trace(lostStick);

trace(lostCol);

I don't know where I get it wrong, I've also tried using _root and _parent for the .push and .pop but still can't get it right.

Translate
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 ,
Jul 11, 2017 Jul 11, 2017

what's it look like after applying a few colors?

Translate
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
Explorer ,
Jul 11, 2017 Jul 11, 2017

It looks something like this Sir, every time the stick was painted, the height of the paint decrease

cat berkurang.PNG

Translate
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 ,
Jul 11, 2017 Jul 11, 2017

then you can just pop() the last array element (that contains the segment of stick that was painted). you don't need to know what color it was painted.

recolor the last painted stick segment brown and that will 'undo' to previous paint.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
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
Explorer ,
Jul 11, 2017 Jul 11, 2017

I think I need to know the colour since I want it to increase back to its previous height, but logically we can't put the paint back to its bucket. Thank you so much Sir, so happy to have you here

Translate
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 ,
Jul 11, 2017 Jul 11, 2017

then yes, you'll need both the stick segment and the color or bucket.  use a 2d array:

var paintA = [];

on(release){

.

.

.

paintA.push([sticksegment,color])

}

Translate
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
Explorer ,
Jul 11, 2017 Jul 11, 2017

Is the name "color" in 2d push array you give, should be the same as the instance name of the paint_mc?

The figure below shows a paint_mc with instance name white_paint that height will decrease.

I did the push them into the array, with the same instance name and with different name.

But I still can't get the height increase back, actually I'm still so curious about it.

How is the script to state that the .pop() height will be "some high"

mc white.PNG

Translate
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 ,
Jul 12, 2017 Jul 12, 2017

you have to code that.  presumably when you use a paint bucket, it decreases by a certain amount. when you undo, you'll increase by that same amount.

Translate
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
Explorer ,
Jul 13, 2017 Jul 13, 2017

yap, I did the code as when I use the paint. everything works really well, thank you so much Sir

Translate
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 ,
Jul 13, 2017 Jul 13, 2017
LATEST

you're welcome.

Translate
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
Guest
Jul 13, 2017 Jul 13, 2017

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

Translate
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