Copy link to clipboard
Copied
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
from your movieclip button use:
_parent.sticks to reference your sticks array that's on the main timeline.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
yes, push the color and region painted into the array.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
where's the trace?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
use trace(this) in you movieclip button and the timeline where sticks is defined to see the path from one to the other.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
from your movieclip button use:
_parent.sticks to reference your sticks array that's on the main timeline.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
what's it look like after applying a few colors?
Copy link to clipboard
Copied
It looks something like this Sir, every time the stick was painted, the height of the paint decrease
Copy link to clipboard
Copied
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.)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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])
}
Copy link to clipboard
Copied
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"
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
yap, I did the code as when I use the paint. everything works really well, thank you so much Sir
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Memento pattern is used for situations like this. A quick Google search yielded an article which explains how it is implemented.