Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

878885 Posts in 32944 Topics- by 24351 Members - Latest Member: AbraxisCode

May 22, 2013, 10:26:43 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)AS2 begginer question on buttons
Pages: [1]
Print
Author Topic: AS2 begginer question on buttons  (Read 366 times)
Mir@k
Level 1
*


Nothing becomes something


View Profile WWW
« on: December 10, 2011, 04:54:45 PM »

Let's say i'm making a dressup game (i know, the bottom of the worst). I have a button with a miniature version of a shirt, and when you click it, another button of the real sized shirt is then placed on top of the naked character. If you click on that shirt, it deletes itself.

How do i do this? I tried using MovieClipName.attachMovie() and MovieClipName.removeMovieClip(), but neither worked, is there something i'm missing? Or am i doing it wrong altogether?

EDIT: More info, this is the AS of the button i want to press so the suit appears:
Code:
on (press) {
scenarie.attachMovie("suit_white", "suit_white", 1);
suit_white._x=247;
suit_white._y=242;
}

scenarie is a movie clip that covers the entire frame.
suit_white is the name (and instance name) of the button that should appear in the coordinates specified, this button is not present on the stage (nor outside) but in the library.
I press the button and nothing happens.

Thanks in advance to anyone who might read this.

EDIT2:

Alright, so i got the first part working with the following code:
Code:
on (press) {
_root.attachMovie("suit_white", "suit_white", 6);
suit_white._x=247;
suit_white._y=242;
}
, now the object appears in the proper place and as many times as i want, but now i don't have any means of deleting it once its pressed, since i cannot add behaviors to the created button, so i tried to replace that button for a movieclip that contains said button with the following code:
Code:
on (press) {
this.removeMovieClip();
}
but it won't disappear once i click on it.

EDIT 3: Fuck everything i had done, i managed to make it work, only to discover that attachMovie only allows you to create ONE movieclip, so if i click on the shirt, and then on the pants, the shirt gets erased! Argghhh
« Last Edit: December 10, 2011, 06:14:30 PM by Mir@k » Logged

st33d
Guest
« Reply #1 on: December 11, 2011, 08:45:11 AM »

Attach at the depth movieclip.getNextHighestDepth(). If you try to attach something at the same depth, it deletes what was there previously.

Also, read the docs:

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001274.html

It might help to create some extra variables to help you track what is supposed to be on the stage. You can check what a clip's _parent is to find out where the hell it is. AS2's display system is very buggy and will happily not tell you when something has gone wrong (however it also allows you to develop stuff very rapidly because you're blissfully unaware of all errors that don't crash the project).
Logged
Mir@k
Level 1
*


Nothing becomes something


View Profile WWW
« Reply #2 on: December 15, 2011, 07:58:42 AM »

Post
Hi. Thank you for your help, and sorry for the late response.
I'm going to sound extremely dumb, but i didn't quite understand (english is my second lang).

I read the docs, and understand how getNextHighestDepth() works, but i can't quite figure out how to use it or where to put it.

I tried using the button code like this:
Code:
on (press) {
scenarie.getNextHighestDepth()
scenarie.attachMovie("cheez", "cheez", 6);
scenarie.cheez._x=222;
scenarie.scenarie.cheez._y=162;
}
But the objects will still delete themselves because of that 6 in attachmovie (that defines depth if i'm not retarded), so i tried placing it below attachmovie, but it still won't work.

I investigated some more, tried using this:
Code:
on (release) {
scenarie.attachMovie("cheez", "cheez", 6);
scenarie.swapDepths(chezz._parent.getNextHighestDepth());
scenarie.cheez._x=222;
scenarie.cheez._y=162;
}
But the result is still the same, the movieclip will appear in place, but when clicking any other object, it'll erase the previous one. Obviously i'm not using getNextHighestDepth() correctly, but i'm not about to give up yet. If you could assist me further i'd be most grateful.
Logged

st33d
Guest
« Reply #3 on: December 15, 2011, 08:46:02 AM »

Stop attaching stuff at "6". Anything you attach at that depth afterwards will just get deleted.

You use getNextHighestDepth() when you attach the movie. You use it to find a depth to attach to. Don't use swapDepths unless you're actually swapping with something - it's buggy.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic