Drag+Drop then Resize Symbol (MX)
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Drag+Drop then Resize Symbol (MX)

  1. #1
    Junior Member
    Join Date
    Jan 2005
    Posts
    21

    Drag+Drop then Resize Symbol (MX)

    I'm sure this is simple but my brain is on strike after a week of hell design issues!

    Anyway, I'm dragging a symbol that has been reduced in size, I'm dropping that symbol and I then want the symbol to resize itself, basically return to it's 100% h+w.

    The dragging and dropping is no probs and I'm sure the resize would be setting some sort of symbol property value or something but will someone please explain coding this...

    Cheers

  2. #2
    I am not an expert
    Join Date
    Aug 2005
    Posts
    175
    on(press){
    this.w = this._width;
    this.h = this._height;
    startDrag(this,true)
    this._width = this._width - 50
    this._height = this._height - 50
    }
    on(release){
    stopDrag();
    this._width = this.w;
    this._height = this.h;
    }

  3. #3
    Junior Member
    Join Date
    Jan 2005
    Posts
    21
    truly a masterpiece!

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    16

    help....

    I have applied this to my own project and is works up to a point. This is what I put on my MC

    on(press){
    this.w = this._width;
    this.h = this._height;

    startDrag(this,true)
    this._width = this.w;
    this._height = this.h;
    }

    on(release){
    stopDrag();
    this._width = this._width + 50
    this._height = this._height + 50
    }

    Now what I need help with: I need to drag the item again to another location without resizing it to another 100 per cent which makes it grow bigger. What actionscript code will work to make the item return to it's smaller size when it is dragged or to keep it from resizing anymore? Sure appreciate any help anyone can give me.

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808

    Too vague

    Didn't understand your problem - please elaborate
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  6. #6
    Junior Member
    Join Date
    Oct 2011
    Posts
    16

    further explanation

    what I mean is, after doing the first drag and drop, this MC then resizes to 100% and fits the item B. However, when I pick up the MC again from that location, drag it and drop it onto item B again, it resizes to 100% again. The more it is dragged and dropped, it always resizes to 100% which means the item gets bigger and bigger which no longer fits the item B.

    what I can't figure out, is how to stop the MC from getting bigger and bigger.

    thanks for your reply and I hope you understand what I am trying to do. Think of a piece of clothing that is removed from a doll and again put back on the doll. I have many other outfits that I want to do the same thing. It's a paper doll game.

  7. #7
    Junior Member
    Join Date
    Oct 2011
    Posts
    16

    further details

    I'm doing a paper doll project when means the item dragged onto the doll will be dragged and dropped again if the player so desires. Only when I did this, as soon as I dropped the item onto the doll a second time, it got bigger in size and did not fit.

    I need to have the code resize one time only for the item. I thought about using if/else, but cannot figure how that should be written.

    Hopefully you will have another way.

    Thanks for any help you can give me.

  8. #8
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Actionscript Code:
    onClipEvent(load){
        this.w = this._width;
        this.h = this._height;
        this.w2 = this._width + 50;
        this.h2 = this._height + 50;
    }

    on(press){
        startDrag(this, true);
    }

    on(release){
        if(this._width < this.w2){
            this._width = this.w2;
            this._height = this.h2;
        }
        stopDrag();
    }
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  9. #9
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    awesome!!!

  10. #10
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    I have another drag and drop question. Is there a code that will allow me to drag a movie clip to the top and while doing so it gets smaller and stays smaller after dropping?

    And then, when dragging the same movie clip back to the bottom, it returns to the original size?

    I want the effect of someone walking away and to appear further in the distance, then to appear back to normal as the someone walks towards me.

    Thanks for any help. :-)

  11. #11
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Could you please provide a bit more details, and if possible, a drawing of what you want, 'cause I'm not 100% sure, lol :P
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  12. #12
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    What I am looking to do, is like the other project. Only this time the movie clip will get smaller as it is moved to another location. When the same movie clip is brought back to the orignial location, it will become it's normal size again.

    I'm not sure a drag and drop would work, as the movie clip should get smaller and smaller as it is moved to another location and dropped. Then when it is moved again, it will become bigger and bigger again to it's original size and dropped.

    Thx.

  13. #13
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Oh, got it. Make a rectangle, which covers your wardrobe, or where you want when the clothes are dropped, to be bigger again, and convert it to a movieclip. Give it an instance name of wardrobe, and change its Alpha to 0%, or use this code on your frame to make it invisible:

    Actionscript Code:
    wardrobe._alpha = 0;

    Just put this wardrobe rectangle in a new layer below everything, to make things easier for you. Next, use this code instead on your movieclip clothes:

    Actionscript Code:
    onClipEvent(load){
        this.w = this._width;
        this.h = this._height;
        this.w2 = this._width - 50;
        this.h2 = this._height - 50;
    }

    on(press){
        startDrag(this, true);
    }

    on(release){
        if(_root.wardrobe.hitTest(this._x, this._y, true)){
            this._width = this.w;
            this._height = this.h;
        } else {
            this._width = this.w2;
            this._height = this.h2;
        }
        stopDrag();
    }

    Hope this works
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  14. #14
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    Hey, that worked great :-). Thx.

    Another item I am working on is rotation of a movie clip. This works for rotation:

    onClipEvent(mouseDown)
    {
    // see if user clicked on this image
    bounds = this.getBounds(_root);

    // see if the user clicked inside himself
    if ((_root._xmouse <= bounds.xMax) &&
    (_root._xmouse >= bounds.xMin) &&
    (_root._ymouse <= bounds.yMax) &&
    (_root._ymouse >= bounds.yMin))
    {
    // rotate himself
    if (_root.himselfRotate)
    {
    _root.himself._rotation = 30;
    _root.himselfRotate = false;
    }
    else
    {
    _root.himself._rotation = -30;
    _root.himselfRotate = true;
    }
    }
    }

    However, I want to use this same kind of code to flip the movie clip "himself" horizontally instead of at an 30, 90, or 180 degree angle. Is there a way to do this?

  15. #15
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Looks like you only know of onClipEvent events!

    The idea of using getBounds to only hit inside the movieclip's bounds, was not a bad idea, but why do it when there's a much better an easier way??

    The Rotation Shape, which I presume is in the movieclip of that code you've provided, copy it, paste it on the Main Stage, click on it or select it, press F8 - now, you'll see a box with 3 alternatives:

    MovieClip - used to create an own timeline for an object
    Button - used to create a button
    Graphic - used to hold a graphic inside a "box", to make things easier

    Select Button, and press OK. Now, give the button an instance name of, rotate_right, copy the button and paste it, use Free Transform Tool (T), to mirror the rotation button, and give it an instance name of rotate_left - Next, use this code on your frame:

    Actionscript Code:
    rotate_left.onPress = function(){
        himself._rotation += 30;
    }

    rotate_right.onPress = function(){
        himself._rotation -= 30;
    }

    What this code does, is that it either rotates himself movieclip LEFT or RIGHT by 30 degrees depending on the button you press, when you PRESS that button. Since this is on the Main Stage, where the himself movieclip is as well, we don't need to use _root or other kind of scopes to refer to it, since the buttons and the movieclip are on the same level. You could also use the same code for movieclip, like, not turn the rotation buttons into buttons, but just have them be movieclip, because onPress also works for movieclips, but the reason I turned it into a button, is because of your getBounds code. It seems like you want them to be able to click on the whole bounds of the movieclip, regardless of the rotation button graphic. To do this with buttons, double-click the buttons, to enter them, find the HIT frame (4th frame, named HIT), select it, press F7 to make a new Keyframe, and draw a rectangle in there - this is going to be the area where the user can click on your button, regardless of its shape, and what you draw on HIT Frame, won't display on your button

    Hope this helps

    PS: Read my recent tutorial on HERE (check the - BUTTONS - part) - what I do there, is a more easy way to give buttons clickable properties, but you have to put the code ON the button, like you did with your code, you put it ON the movieclip, so I thought that method would work better for you, the method I used, is the same, just to put on Frames!
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  16. #16
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    Yes, I see what you mean. I now have two buttons on my stage, one is rotate_right and the other is rotate_left. I have put the code you gave me on the frame. I also have himself, which is a movie clip on the stage. However, when I click on the rotate_left button, himself moves at a 30 degree angle. It did not flip to a mirror image of itself. Did I do something wrong here?

  17. #17
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Oh, you want to mirror the himself movieclip?

    In that case, use this code:

    Actionscript Code:
    xScale = himself._xscale;

    rotate_left.onPress = function(){
        himself._xscale = -xScale;
    }

    rotate_right.onPress = function(){
        himself._xscale = xScale;
    }

    We simply invert his X Scale
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  18. #18
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    That makes sense and it works. Thx for giving me more info. :-)

  19. #19
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    Here I am again. You certainly are good at this flash actionscript stuff. Now I am trying to drag a movie clip(called zeke) from Scene1 to Scene2. I made an alpha movie clip and placed it at the far right of my first scene and gave it an instant name of 'wall'. On the movie clip called zeke I have put this code:

    on(press){
    startDrag("");
    if(_root.wall.hitTest(this.gotoAndPlay("Scene 2", 1)));

    }

    on(release){
    stopDrag();
    }

    With this code I haven't gotten any errors popping up, but when I drag zeke over the movie clip "wall", nothing happens. I am missing some necessary code. Any help for me on this? :-)

    Thx

  20. #20
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    I was thinking. Perhaps I need to use onRollOver function. ???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com