A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Dragging 2 things at once

  1. #1
    davidbyrne.net.au
    Join Date
    Dec 2000
    Location
    Perth, Australia
    Posts
    63

    Question Dragging 2 things at once

    Hey Guys,

    I have a annoying problem today,

    I have mad a custom cursor (like the pdf one) to appear when i click on something to drag it, problem is I can only do one startDrag function at a time. I have tried making another function that starts when it is pressed and still wont work.

    I am sure people have done this a million times.

    Any help?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I don't understand your question. You can only drag when you place the cursor over an object. Another object would not be dragged, which means only one at a time.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    davidbyrne.net.au
    Join Date
    Dec 2000
    Location
    Perth, Australia
    Posts
    63
    I have a cursor image (this is one thing I am dragging) and a image underneath it (that i am dragging at the same time) I want the cursor to change while I am dragging the image but to do that I need to make the cursor an image to be dragged aswell. understand? I hide the mouse and make one draggable object the replacement for that and the other one is the one underneath the cursor that is being moved.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    The only thing you can do is this, but when the mouse moves the image from the onPress status will disappear.
    PHP Code:
    Mouse.hide ();
    cursor_mc.onMouseMove = function ()
    {
        
    cursor_mc2._visible false;
        
    this._visible true;
        
    this._x _xmouse;
        
    this._y _ymouse;
        
    updateAfterEvent ();
    };
    cursor_mc2.onMouseDown = function ()
    {
        
    this._visible true;
        
    cursor_mc._visible false;
        
    this._x _xmouse;
        
    this._y _ymouse;
        
    updateAfterEvent ();
    }; 
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    davidbyrne.net.au
    Join Date
    Dec 2000
    Location
    Perth, Australia
    Posts
    63
    Ok let me do it this way.

    Imagine your playing a game, ok?
    now when you click on something you want to be able to drag it around with the cursor.

    So in this example I am saying you have a hand that you want to glows yellow when you go over a magic sword, so you click to pick it up in your hand and wave it around while your hand is still yellow and cursor is down. so the code is;

    Code:
    magic_sword.onRollOver = function ()
    {
        startDrag(hand_cursor);
        hand_cursor._x = _xmouse;
        hand_cursor._y = _ymouse;
        Mouse.hide ();
    };
    magic_sword.onPress = function() {
        startDrag(this);
    }; 
    magic_sword.onRelease = function() {
        stopDrag();
    }; ()
    Now as you probably know you can do this a number of ways but every way I do it I can only drag one thing around with the mouse position, where i want both moving around until I release the mouse and i drop the item.

    Dont panic I am not making a game with swords and stuff I am actaully making a navigation system.

    and before you say it, Yes, I have put the
    Code:
    startDrag(hand_cursor);
    into the on press functions but as you will see it stops it working.

    I really thought this would be so simple but cant find anything anywhere.

    Thanks for your help so far cancer.

    By the way is that your real pic? Damn?!

    - Budgi

  6. #6
    Member
    Join Date
    Feb 2005
    Posts
    35
    This worked for me and i hope it is what you meant. Basically is uses onEnterFrame to continually place the custom cursor at the position of the mouse. but its hidden. Until, that is, you rollover your item. then it makes the cursor visible and you can click and drag that item to your hearts content. until you roll out...which can't happen until you let go of your mouse.

    I hope that makes sense and i hope it works like you wanted.


    Code:
    customCursor._visible = false;
    customCursor.onEnterFrame = function() {
    	customCursor._x = _xmouse;
    	customCursor._y = _ymouse;
    };
    magicsword.onRollOver = function() {
    	startDrag(customCursor);
    	customCursor._x = _xmouse;
    	customCursor._y = _ymouse;
    	customCursor._visible = true;
    	Mouse.hide();
    };
    magicsword.onPress = function() {
    	startDrag(this);
    };
    magicsword.onRelease = function() {
    	stopDrag();
    };
    magicsword.onRollOut = function() {
    	customCursor._visible = false;
    	Mouse.show();
    };

  7. #7
    davidbyrne.net.au
    Join Date
    Dec 2000
    Location
    Perth, Australia
    Posts
    63
    Very close mate,

    only difference is I want the cursor to change when you click down to another one.

    So probably something like this:

    I have just added a movieclip called glowingHand
    Code:
    customCursor._visible = false;
    customCursor.onEnterFrame = function() {
    	customCursor._x = _xmouse;
    	customCursor._y = _ymouse;
    };
    magicsword.onRollOver = function() {
    	startDrag(customCursor);
    	customCursor._x = _xmouse;
    	customCursor._y = _ymouse;
    	customCursor._visible = true;
    	Mouse.hide();
    };
    magicsword.onPress = function() {
    	startDrag(this);
    	glowingHand._x = customCursor._x;
    	glowingHand._y = customCursor._y;
    	customCursor._visible = false;
    	glowingHand._visible = true;
    	startDrag(glowingHand);
    };
    magicsword.onRelease = function() {
    	stopDrag();
    	customCursor._visible = true;
    	glowingHand._visible = false;
    	customCursor._x = glowingHand._x; 
    	customCursor._y = glowingHand._y;
    };
    magicsword.onRollOut = function() {
    	customCursor._visible = false;
    	Mouse.show();
    };
    See how the "sword" doesnt move now?

  8. #8
    Member
    Join Date
    Feb 2005
    Posts
    35
    ok....remember how the first cursor worked with out startdrag? well we are going to do it the same way here. in the customCursor add another frame to it and call that frame: glowingHand. put the glowing hand cursor here.

    Now you add this to the onpress function

    Code:
    customCursor.gotoAndStop("glowingHand")
    and take out


    Code:
    glowingHand._x = customCursor._x;
    	glowingHand._y = customCursor._y;
    	customCursor._visible = false;
    	glowingHand._visible = true;
    	startDrag(glowingHand);
    does that make sense/work?

  9. #9
    davidbyrne.net.au
    Join Date
    Dec 2000
    Location
    Perth, Australia
    Posts
    63
    sweet dude!!!
    I just worked it out like you said, why the hell didnt I think of another frame!! GOSH!! Anyway all working now. All I have is on press gotoAndStop frame 2 deal and it works sweet. I have never named frames before so i am guessing i only need to put it in ("blah") format for the frame label to work?

    Anyway, thanks again. Now I have bigger issues to work on
    Like importing dynamic buttons into a movieclip inside a movieclip but I think I should save that for another thread.

  10. #10
    davidbyrne.net.au
    Join Date
    Dec 2000
    Location
    Perth, Australia
    Posts
    63
    thanks for your help too cancerinform
    Last edited by budgi; 02-06-2007 at 09:04 PM.

  11. #11
    Member
    Join Date
    Feb 2005
    Posts
    35
    Yep, that sounds right about the frame label...

    and no problem, glad i could help.

  12. #12
    davidbyrne.net.au
    Join Date
    Dec 2000
    Location
    Perth, Australia
    Posts
    63
    hmmm... ok I know i should post this in a new thread but anyway.
    I have a layer problem now. I have 3 layers

    layer 1
    layer 2
    layer 3

    and in the first frame of all of them i want to load onto a named layer.
    get what i mean

    so going back to the sword metaphor lets say i want to load sword into a movie clip on layer one and frame one

    and i want to put cup into layer two but frame one.

    Can that be done? At the moment I am loading them into blank movie clips but would like to just put them on a labelled frame.

  13. #13
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    use eventDispatcher to broadcast an event that the dragable image and and the scollbar listen for. or use asBroadcaster.

  14. #14
    Member
    Join Date
    Feb 2005
    Posts
    35
    I'm not sure if really understand what you mean....... and i have no idea what attackRabbit is getting at.


    But layers? I don't think you can interact with layers through actionscript i think that they are purely to make authoring easier. if it is a case of an object appearing on top of another on the stage you can load MC's onto different levels. is that what you mean?

  15. #15
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    budgi, so if im understanding your problem correctly you would like to load three images into a movieclip on three layers when the first frame actions are executed ? i would start by inserting a new symbol of type moiveclip, or dynamically create and attach a movieclip at run time in a for loop and use the this.getNextHighestDepth method to layer them. If you want your movie clip(s) on the time line , the place an instance of your empty movieclip on each frame and give each one a unique instance name like, myMC0, myMC1,myMC2, etc. Then on the first frame create an .as layer, use movieclip loaders to load your images ,swf, gifs, flvs , whatever. into then in the onLoadInit of the listener , toggle the visibilty of each movieclip on the time line, for example you could set the visibility of all three movieclips to false, then onloadInit, set a default clip as _visibile = true;

  16. #16
    davidbyrne.net.au
    Join Date
    Dec 2000
    Location
    Perth, Australia
    Posts
    63
    see i dont want to put any other movieclips on the stage because the things I am placing on the stage are buttons and want work at that level in. Its kinda too hard to explain and if I do tackle it I will start it in a new thread.

  17. #17
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    sounds treacherous with flash buttons. i could mistaken but im pretty sure flash considers any object of type button to be of a component class. theres really no good reason ever to make a symbol of type button when you can assign eventHandlers through as to a movieclip. but hey whatever rubs your goat.

  18. #18
    davidbyrne.net.au
    Join Date
    Dec 2000
    Location
    Perth, Australia
    Posts
    63
    too complicated to explain, if explained will be in another thread.

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