Skip to main content
Inspiring
January 8, 2007
Question

Resize a movieclip at runtime

  • January 8, 2007
  • 14 replies
  • 3341 views
I'd like users to be able to drag out a shape from the side of the stage (say a square) and then resize it on the stage. I think I've seen this Flash functionality somewhere on the web, but I can't figure out what the code would be for this. Can anyone help?

Thanks,

Michael;
This topic has been closed for replies.

14 replies

kglad
Community Expert
Community Expert
January 19, 2007
you're very welcome.
Inspiring
January 19, 2007
Well, as the young folks sometimes say, "You are the man!". That's it. It all works great. Thanks so much. I've learned a lot.

Michael
kglad
Community Expert
Community Expert
January 17, 2007
you're welcome.
Inspiring
January 18, 2007
Okay: one FINAL question (I promise!). Everything works great. But of course, I want to add in one tiny bit of complexity: I want to be able to drag every duplicated movieClip I bring onto the stage. I've attached the code that works fine (Ihave a movieclip button on the stage called newCircle_mc and a movieclip offstage called circle_mc).

This code will duplicate the circle, place it in the middle of the stage and allow me to drag only the last MC to be placed on the stage. It won't allow me to drag any previous MC that has already been placed on the stage and then dragged somewhere. How do I get Flash to let me drag any instance that has been duplicated? I tried a "for" statement, but that didn't work.

Michael
kglad
Community Expert
Community Expert
January 18, 2007
try:

kglad
Community Expert
Community Expert
January 17, 2007
who knows. all's well that ends well.
Inspiring
January 17, 2007
Indeed. Hey -thanks for sticking in there with me on this. It's going to help a lot and this whole bit about attaching code to the parent vs. using an onMouseDown was a very helpful lesson.

Thanks again!

Michael
kglad
Community Expert
Community Expert
January 17, 2007
ok. that looks the way i want it to appear.
Inspiring
January 17, 2007
Darn. You were right - my code didn't work. But I copied your code in and tried it and it also drags the circle_mc no matter where I click on the stage. I can't understand it, since your code makes a whole lot of sense to me. Have you tried this code out? I'll tinker with it some more, but I can't get it to work just right. Any thoughts?
kglad
Community Expert
Community Expert
January 17, 2007
i don't know if i posted that code or this forum mangled it. i'm not aware of the attach code ever mangling code, but i also can't imagine i could post such nonsense.

anyway, here's the corrected code (and i'll check that it's not mangled after posting it):

Inspiring
January 17, 2007
Wait a minute: I think I got it. This seems to work:

circle_mc.onMouseDown = function(){
circle_mc.startDrag();
}
circle_mc.onMouseUp = function(){
circle_mc.stopDrag();
}

Thanks again!!
kglad
Community Expert
Community Expert
January 17, 2007
you probably won't be happy with your code. you'll find that you're going to start dragging circle_mc no matter where you click on your swf. that's not usually the desired effect.

to start drag only when your circle_mc is clicked use:

Participant
October 2, 2009

Hi I am facing the same problem but I can't see the sample codes that you gave Michael?

Inspiring
January 17, 2007
Okay, last question: I created a quick movieclip of a circle ("circle_mc") on one layer and then wrote this script on the first frame of another layer:

onMouseDown = function(){
if (this.hitTest(circle_mc)){
trace ("I'm hit!");
}
}
Problem: I get an "I'm hi!" trace when the mouse clicks anywhere on the stage. What am I doing wrong?
kglad
Community Expert
Community Expert
January 17, 2007
you're welcome.
kglad
Community Expert
Community Expert
January 17, 2007
anyway you want. you could initiate a startDrag() when your swf loads. or when the swf has been running for 31 seconds. or anything else that flash is capable of handling.

but most commonly people want to initiate a startDrag() when the object to be dragged is clicked by the mouse.

in that situation, if you don't want to use an onPress mouse handler you can use an onMouseDown combined with a hitTest() to see if your movieclip has been clicked.
Inspiring
January 17, 2007
Interesting. Use an onMouseDown combined with a hitTest - never thought of that. Okay, thanks - I'll give it a try.
Appreciate the help!