Copy link to clipboard
Copied
Hello. I am new to Flash CC. I am trying my hand at a simple dress up doll game. I have made a doll base, with different skin types in their respective frames, and next and previous buttons to move from skin color to skin color. This is the code I am using for the next and previous buttons:
stop()
btn1prev.addEventListener(MouseEvent.CLICK, backward);
btn2next.addEventListener(MouseEvent.CLICK, forward);
function forward(event:MouseEvent) {
if (this.currentFrame == this.totalFrames) {
gotoAndStop(1);
}
else {
nextFrame();
}
}
function backward(event:MouseEvent) {
if (this.currentFrame == 1) {
gotoAndStop(this.totalFrames);
}
else
{
prevFrame();
}
}
Then I added 3 new layers, each with a different eye color on them (brown, blue, and green). I want these to be dragged and dropped onto the doll. I started with the brown and added this action to the layer:
browneyes.addEventListener(MouseEvent.MOUSE_DOWN, dragbrowneyes);
function dragbrowneyes(eyt:MouseEvent):void{
addChild(MovieClip(evt.currentTarget));//to place above other content
evt.currentTarget.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, dropbrowneyes);
}
function dropbrowneyes(evt:MouseEvent):void{
stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, dropbrowneyes);
}
When I try each of these codes on their own, they work fine. But when I try to use them both in the same file, none of them work. The eyes I cannot move and the skin types flash by instead of moving when I press the buttons.
Here is a video of me adding the drag and drop action then pressing Ctrl+Enter to play the game (so that you can see how the dragndrop does not work and neither do the buttons, skin types flash by) :
This shows up in the Compiled Errors :
Again, I'm new, so I don't really understand these actions. I just found them online.
Any and all help would be mucho appreciated. I am using Flash through the Creative Cloud on a PC (windows 7), it is updated, and I am using Action Script 3.
I will try to attach screen shots. Hopefully they show up ![]()
My Timeline : showing my layers and frames
My actions for the next and previous buttons
My whole screen : The actions window is minimized
*I also plan on adding multiple items of clothing later on that I would like to move to it's place whne clicked on. help for that would be appreciated as well
Copy link to clipboard
Copied
show the code you're trying to use when coding for the 3 eye colors.
Copy link to clipboard
Copied
I am trying to use the drag and drog code :
browneyes.addEventListener(MouseEvent.MOUSE_DOWN, dragbrowneyes);
function dragbrowneyes(eyt:MouseEvent):void{
addChild(MovieClip(evt.currentTarget));//to place above other content
evt.currentTarget.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, dropbrowneyes);
}
function dropbrowneyes(evt:MouseEvent):void{
stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, dropbrowneyes);
}
I just replace "browneyes" with blueeyes or greeneyes, depending on which layer I'm putting the code
Copy link to clipboard
Copied
put all your code in the same layer.
then copy and paste the code with two or more drag/drop functions that's causing a problem.
or just use:
browneyes.addEventListener(MouseEvent.MOUSE_DOWN, drageyes);
greeneyes.addEventListener(MouseEvent.MOUSE_DOWN, drageyes);
blueeyes.addEventListener(MouseEvent.MOUSE_DOWN, drageyes);
function drageyes(eyt:MouseEvent):void{
addChild(MovieClip(evt.currentTarget));//to place above other content
evt.currentTarget.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, dropeyes);
}
function dropeyes(evt:MouseEvent):void{
stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, dropeyes);
}
Copy link to clipboard
Copied
i tried putting the code all on the same layer and it still gAve me the same problem 😕
for the code you gave me, do i put that on the same layer as the other actions? or on the same layer as the eyes?
Copy link to clipboard
Copied
layers are irrelevant. they don't even exist in your published swf.
frames are relevant. that code needs to be placed in a frame that executes when all those 'eyes' exist and those 'eyes' must continue to exist when they're clicked.
Copy link to clipboard
Copied
please keep in mind that I am new to this, I don't quite understand all the lingo yet.
so since the layers will not exist, it is the frames that are important, I put all the eyes in the same frame, then add the code?
Copy link to clipboard
Copied
layers don't exist in your published swf so they're irrelevant for actionscript (because actionscript only executes in the published swf.
layers may be very important for the work you're doing on-stage in the flash pro program. layers are often (not just relevant but) important so you can layout your graphics the way you want and organize your project the way you want.
so they each eye movieclip will be in its own layer (if you're very organized). but you have to be careful about the keyframes they are used in and you have to be careful about which frames contain your code.
again, code needs to be placed in a frame that executes when all those 'eyes' exist (on stage) and those 'eyes' must continue to exist when they're clicked. ie, they've not been removed in any keyframe that plays before they're clicked/
Copy link to clipboard
Copied
aaaaaaah okay! makes sense, thank you!
Copy link to clipboard
Copied
to bring an object to the front, use addChild:
browneyes.addEventListener(MouseEvent.MOUSE_DOWN, drageyes);
greeneyes.addEventListener(MouseEvent.MOUSE_DOWN, drageyes);
blueeyes.addEventListener(MouseEvent.MOUSE_DOWN, drageyes);
function drageyes(eyt:MouseEvent):void{
addChild(MovieClip(evt.currentTarget));//to place above other content
evt.currentTarget.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, dropeyes);
}
function dropeyes(evt:MouseEvent):void{
stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, dropeyes);
}
Copy link to clipboard
Copied
okay, i went back to my eyes on all frames and saw that not all of them had the instance name i had assigned them, so i went through and gave the their respective names (browneyes, blueeyes, greeneyes). Now when i try the game the next and prev buttons work and so does my drag and drop code.
I put the code for the drag and drop underneath the code for the buttons, so they are working fine. the only problem is that if i drag the browneyes down then change the skin color, the eyes disappear until i come back around to the palest skin color (which is the first skin color). the green and blue eyes stay on top of the skin even if i press the next and prev buttons.
Also, and it does this for all three eye colors, when i drag an eye color down onto the body, then press through the skin colors to come back to the first skin color (palest) another set of eyes appears where it is before being dragged, so now i have two sets of the same eye color.
I'm still using this code for all the eyes, just changing the instance name where needed:
browneyes.addEventListener(MouseEvent.MOUSE_DOWN, dragbrowneyes);
function dragbrowneyes(evt:MouseEvent):void {
addChild(MovieClip(evt.currentTarget)); // to place above other content
evt.currentTarget.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, dropbrowneyes);
}
function dropbrowneyes(evt:MouseEvent):void {
stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, dropbrowneyes);
}
It says in the code "to place above other content" I understood that as the eyes will always be on top of everything else, am i understanding that wrong?
Copy link to clipboard
Copied
i clicked on the browneyes and went to Arrange > Bring to Front, and that seems to have fixed the problem of the eyes disappearing under the skin.
I am still getting the double sets of eyes tho. any ideas?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more