Trying to create movable window with a close button

  • ivanjs
  • Born
  • Born
  • ivanjs
  • Posts: 1

Post 3+ Months Ago

I'm creating a flash-based computer interface, and one of the items is a transparent window with a close button in the upper right.

I create the window as a movieclip, and the button is placed inside the movie clip in the title bar of the window.

The movie clip has this code:
Code: [ Select ]
on(press)
{
    this.startDrag();
//   also tried startDrag(); without the 'this'
}

on(release, releaseOutside)
{
    stopDrag();
}
  1. on(press)
  2. {
  3.     this.startDrag();
  4. //   also tried startDrag(); without the 'this'
  5. }
  6. on(release, releaseOutside)
  7. {
  8.     stopDrag();
  9. }

so users can move the window around, and they should be able to click the close button to make the window go away.

The startDrag/stopDrag script works great. I can move the window around everywhere. But the button never triggers any of its states, and it of course doesn't work either.

Is this a level problem? I know I've put buttons in movie clips before and it should work, but the button just sits there, no rollover state or anything.

Using Flash MX.
John
http://homepage.mac.com/johnselvia/
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

When you put a button inside a movieclip symbol acting as a button, the buttons inside will not register.

So I can only assume in your case, the actions in your post are put on the movieclip symbol acting as the window, and not on a button or movieclip symbol inside that movieclip symbol. Am I correct?

If so, I recommend creating a button or clip inside the window clip to use as an individual dragging handle. Then assign the actions for dragging to that clip (although you may have to use _parent.startDrag() just so you are targeting the right clip... depends on if you use a button or movieclip symbol though)

This way all your individual buttons can be contained within the window clip and still register.
  • cmontana
  • Novice
  • Novice
  • User avatar
  • Posts: 18

Post 3+ Months Ago

The problem seems to be that you are treating the entire draggable window as a button, like lostinbetta pointed out. Just use a drag button at the top of the window.

I like to name instances of my move clips (in this case "window") and use something like:

on (press) {
setProperty("_root.window", _visible, "0");
}

Download http://imaginaire.ws/flash/dragwindow.fla and see what I mean.

Also make sure your closing button is used as a button, not a movie clip.
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

setProperty is Flash 4 syntax, starting with Flash 5 dot syntax was implemented into ActionScript.
Code: [ Select ]
on (press) {
_root.window._visible = 0;
}
  1. on (press) {
  2. _root.window._visible = 0;
  3. }
That would be the up to date method of writing your above code.

Also good strategy using _visible to make the window disappear, many people try using _alpha=0 to make their window disappear, not know that on 16bit color monitors, clips with an _alpha setting of 0 are still slightly visible.

Last but not least... I highly recommend relative addressing using _parent (previous timeline in hiearchy) and this (current timeline) rather than static addressing using _root. Makes the movie more portable.
Code: [ Select ]
on (press) {
    _parent.startDrag();
}
on (release, releaseOutside) {
    stopDrag();
}
  1. on (press) {
  2.     _parent.startDrag();
  3. }
  4. on (release, releaseOutside) {
  5.     stopDrag();
  6. }
Code: [ Select ]
on (press) {
    _parent._visible = 0;
}
  1. on (press) {
  2.     _parent._visible = 0;
  3. }
NOTE: 0 is the same value as false, some people use "_visible = false;" and others use" _visible = 0;", they are the same :)

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 23 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.