A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Simpler question about startdrag() usage

  1. #1
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    Simpler question about startdrag() usage

    i need this:

    i need to have it so that only after you click and hold on a movieclip for more then 500 ms then it will begin a drag sequence.

    my current code (doesnt work)

    Code:
    on (press) {
    	if (timegot == false) {
    		timepress = getTimer();
    		timegot = true;
    	}
    	if (getTimer()-timepress>=500) {
    		_root["cell"+xl+yl].startDrag([[left, top, right, bottom]]);
    	}
    }
    on (release) {
    	_root["cell"+xl+yl].stopDrag();
    Where "celkl"+xl+yl is the movieclip located closest to the spot you click and hold on the button (invisible) which is 1 layer above the movie clips... (i tested this and this part of it works- its the only drag after 500 ms and keep dragging till i let go part that doesnt)
    maximum width 300 no more maximum hieght 40 no more not interchangable

  2. #2
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    asdf

    BUMP! LISTEN TO ME! ANSWER MY QUESTION! (in the mean time, i work on a custom avatar)
    maximum width 300 no more maximum hieght 40 no more not interchangable

  3. #3
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    asdf

    Wtf - Plz Reply!!
    maximum width 300 no more maximum hieght 40 no more not interchangable

  4. #4
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    why did you name the symbol that? And you're gonna have to exercise a little patients, you are not the only one on this forum. Now what is it you're trying to do?
    Last edited by EQFlash; 12-16-2005 at 11:42 PM.
    If you don't think you're going to like the answer, then don't ask the question.

  5. #5
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    asdf

    alright so i will have to explain... here goes:

    "cell"+xl+yl entails:

    I have a grid (23 x 19) - At the end of every turn, every point on that grid filled with grey "duplicates" and fills the points around it with grey as defined by a certain function which i wont reveal here cuz its the main point of the game play.

    Now heres the thing- the cells arent filled with grey- theyre filled with movieclips that look like a living cell... now, i'll have to remove, and add, and remove, etc as the program goes on, so i need to give the movie clip a dynamic name for each time i create it.

    so, the line of code that made "cell"+xl+yl was done at a time that xl and yl where set to the place where i wanted the movie clip to be placed

    *phew* alright now you get it- so the movie clip in grid coordinate (9,3) would be called (as an instance name) "cell93" this makes it easy to call back.

    Alright! now quesiton #2:

    AS FAR AS PATIENCE GOES, I JUST HAD 6 HOURS TO DEVOTE TO PROGRAMMING AND I GOT NOTHING DONE BECAUSE I WAS STUCK ON THIS PROBLEM AND I REALLY COULDNT THINK OF ANYTHING TO DO DURING THESE 6 HOURS AND NOW THERE UP AND MY CODE ON THE PUZZLE GAME ISNT NE LONGER *takes in a deep breath, and takes a sip of water* sigh oh well neway on to point #3:

    wut i'm trying to do: this is very obvious:

    I have a "blanket" button which is on the highest layer (its above everything else) it covers the grid, and is clickable (as button suggests) and, well, its like A BLANKET to the grid and all the "cells" on it. now, whenever you click on this "blanket", it takes you mousex and mousey coordinates, finds wut movieclip you are coinciding over (if your at a point over grid (9,3), then it will select the movie clip "cell93"). Now, if yoiu just click and let go- then it puts the cell-you-chose's name in a variable, and a program goes on with something to do to that. Now, if you hold down and drag, then the clip you are over will be attached to your mouse, and you will be able to drag and drop it to another unoccupied spot on the grid.

    So, since there has to be a different program for just "clicking" on a movie clip, and "dragging" it, i propose that if you are still "pressing" the clip after .5 sec, then you are probably getting ready to drag it. so, then it locks, and you can move the mouse, it will follow, and you can let go (release) and it will drop. (the drop I can program myself- for some reason its just not getting the "pickup") HELP NOW! you people suck now i have to go to bed... and program this tomorrow... sigh oh well if one of you answer my question by tomorrow morning i will have renewed faith in one of these forums... someday i'll be the one answering noobs questions but today thats your job... I left a detailed enough post for most of you to get wut i'm trying to do (thats being sarcastic- my fingers are SORE- this post is TOO LONG!!!) neway i know you all know how to do this, so please tell me wut you would propose to change the above code to in order to make this work... not asking for an example file as well, but since youve got till morning might as well. Good night, cuz it might be all you have left (wow...) lol n3w4y by3z0rz!!!
    maximum width 300 no more maximum hieght 40 no more not interchangable

  6. #6
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    asdf

    wtf... ITS MORNING NOW- YOU HAD ALL NIGHT and NOONE posted... maow... this is soooo depressing... l4t3rz!!! please post NOW!
    maximum width 300 no more maximum hieght 40 no more not interchangable

  7. #7
    Senior Member
    Join Date
    Oct 2003
    Posts
    1,354
    Good Morning..

    Put a movieClip on the stage and name it myBtn. Make it hunter green with a dark blue border.

    Then try this out. (500 ms is pretty quick, I used 1000)

    Code:
    myBtn._alpha = 30;
    myBtn.onEnterFrame = function() {
    	this.timeDifference = (getTimer()-this.timePress);
    	if (this.myPress == 1 && this.timeDifference>1000) {
    		this.startDrag();
    		this._alpha = 100;
    	}
    	trace(this.myPress);
    };
    myBtn.onPress = function() {
    	this.myPress = 1;
    	this._alpha = 60;
    	this.timePress = getTimer();
    };
    myBtn.onRelease = function() {
    	this.myPress = 0;
    	this._alpha = 30;
    	this.stopDrag();
    };
    myBtn.onReleaseOutside = function() {
    	this.myPress = 0;
    	this._alpha = 30;
    	this.stopDrag();
    };
    // Turn off if mouse is pressed and draged out
    // Leave on if we are already dragging
    myBtn.onDragOut = function() {
    	if (this.timeDifference<1000) {
    		this.myPress = 0;
    		this._alpha = 30;
    		this.stopDrag();
    	}
    };
    The problem with your script is that the onPress action only runs once, on the press, not all the time. You need a way to constantly check what is going on. Thats why an onEnterFrame fucntion is so useful.

  8. #8
    Senior Member
    Join Date
    Oct 2003
    Posts
    1,354
    woops.. forgot to say why I was doing it on the time line..

    Put 4 movieClips on the stage, name them myBtn1, myBtn2, myBtn3 & myBtn4

    Make them all various color combinations of hunter green, burn't orange and dark blue.

    then try this out..
    Code:
    for (i=1; i<5; i++) {
    	_root["myBtn"+i]._alpha = 30;
    	_root["myBtn"+i].onEnterFrame = function() {
    		this.timeDifference = (getTimer()-this.timePress);
    		if (this.myPress == 1 && this.timeDifference>1000) {
    			this.startDrag();
    			this._alpha = 100;
    		}
    		trace(this.myPress);
    	};
    	_root["myBtn"+i].onPress = function() {
    		this.myPress = 1;
    		this._alpha = 60;
    		this.timePress = getTimer();
    	};
    	_root["myBtn"+i].onRelease = function() {
    		this.myPress = 0;
    		this._alpha = 30;
    		this.stopDrag();
    	};
    	_root["myBtn"+i].onReleaseOutside = function() {
    		this.myPress = 0;
    		this._alpha = 30;
    		this.stopDrag();
    	};
    	// Turn off if mouse is pressed and draged out
    	// Leave on if we are already dragging
    	_root["myBtn"+i].onDragOut = function() {
    		if (this.timeDifference<1000) {
    			this.myPress = 0;
    			this._alpha = 30;
    			this.stopDrag();
    		}
    	};
    }
    This way, you arn't going to have to hand script all those buttons..

  9. #9
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    asdf

    JOY! merry christmas! thx now i can continue programming!!! yay!

    EDIT: just 17 more posts to go before i can use my rox awesomez0rz 4v4t4r!!! (lol 4v4t4r h4h4h4h4) lol...
    maximum width 300 no more maximum hieght 40 no more not interchangable

  10. #10
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    asdf... gah lol

    gah everything you post is always sooo complicated! you could just simplify it to this:
    (this goes on a movie clip)
    [code]
    on enterframe (
    if (_root.timestart != null){
    _root.timediff = getTimer() - _root.timestart
    if (_root.timediff >= 500){
    mc.startdrag()
    _root.dragchoice = true
    }
    }
    }
    Code:
    
    
    and this goes on a button:
    Code:
    on (press){
        _root.timestart = getTimer()
    }
    on (release){
        if (_root.timestart != null){
             if (getTimer() - timestart <= 500){
                _root.clickchoice = true;
             }
             if (getTimer() - timestart >= 500){
                stopDrag()
                // begin "lock to grid" functions here
             }
        } else {
           _root.clickchoice = true;
        }
    }
    at least... i think... oh well thats wut i got from your posts lol (16 posts left!!!0
    maximum width 300 no more maximum hieght 40 no more not interchangable

  11. #11
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    asdf

    INCORRECT! (gah jk) neway

    having 1 problem - the "on release" - its not stopping the drag... its syntaxed right, and i debugged it, it's hitting the step at the right time...

    i think there's a problem with that once its being dragged, its instance name changes (maybe???) Neway heres the "one line of code" if you wanna scruitinize it:

    Code:
    _root["cell"+x+y].stopDrag;
    syntaxor says its right... and looks right to me... does the start and stop drag have to be in similar locations??? (like when you start a drag, does it "start the drag" on the depth of the source of the code??? or does it let it keep its depth...)

    for example- if i executed start drag on a movie clip (layer 3 in time line, so depth = 3) and tried to stop it on a button (layer 2 in time line, so depth = 2), it would search for a movieclip in the temporary directorty of that depth? i might be crazy just correct me if i'm wrong but i think this is the problem...
    maximum width 300 no more maximum hieght 40 no more not interchangable

  12. #12
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    asdf,.. ignore this

    IGNORE ABOVE POST- I FOUND SYNTAX ERROR (lol i said it wasnt but it was)
    ANYWAY- NEW PROBLEM:

    ahh wut the heck i'll post it in a new thread...
    maximum width 300 no more maximum hieght 40 no more not interchangable

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