A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [cs3]

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    5

    [cs3]

    Hej!

    I have a puzzle with 3 pieces that snap in flash. The pieces namnes are 1, 2 och 3. and the place where they drop are "drop1" etc...

    The snap-code is inside the drop-pieces, code for the "drop1":

    CODE:

    on (press) {
    startDrag("/1");
    }
    on (press, release) {
    if (_droptarget eq "/drop1") {
    setProperty("/1", _x, "128.8");
    setProperty("/1", _y, "218.5");
    stopDrag();
    }
    }
    on (release) {
    stopDrag();
    }


    I now want to show a movieclip, congrats, when you have managed to solve the puzzle.


    This code is inside the root frame:


    _root.congrats._visible = false;


    if (1._x == 128,8 && 1._y == 218,5)
    {
    _root.congrats._visible = true;

    }



    it doesn't work, what should I write?

  2. #2
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    there are a couple problems, and by this code, I'm not really sure what some of these are but:

    1. Variables should not start with numbers (1._x) < - if a variable, is invalid
    2. You have commas where I believe there should be decimals: 128,8, 218,5
    3. Also, just for because I am picky, I would use whole numbers whenever possible, EXAMPLE: for 128.8, I would use just 128, or round up to 129.
    4. use trace() to check and make sure you values are matching.

    actually, now that I look back, I am seeing that the name is /1, I was seeing it as slash notation. It's just me, but I would refrain from using a special charachter as the begining in naming variables

    anyway, I hope this helps

    IMS

  3. #3
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    you dont have to use setProprty, you can simply do:

    movieClipName._x = 100;
    movieClipName._y = 50;

    this:
    if (1._x == 128,8 && 1._y == 218,5)
    might have to be this: 'add the / before 1
    if (/1._x == 128,8 && 1._y == 218,5)


    IMS

  4. #4
    Junior Member
    Join Date
    Feb 2009
    Posts
    5

    Some changes

    Hi!

    I have made some changes now.

    I have 3 movie clips.

    1) drop1 (changed position to yx 0.0)
    2) d1
    3) congrats

    d1 --> shall drop into drop 1.

    This is the code now inside of both drop1 and d1:

    on (press) {
    startDrag("/d1");
    }
    on (press, release) {
    if (_droptarget eq "/drop1") {
    setProperty("/d1", _x, "0.0");
    setProperty("/d1", _y, "0.0");
    stopDrag();
    }
    }
    on (release) {
    stopDrag();
    }


    The drop function works. I tried to change it setProperty to:
    movieClipName._x = 0.0;
    movieClipName._y = 0.0;
    But I didn't get it to work.

    Code in rootframe: (for congrats movieclip to show when d1 is in the position 0.0)

    congrats._visible = false;

    if (d1._x == 0.0 && d1._y == 0.0)
    {
    congrats._visible = true;
    }



    Congrats is invisible in the start, but I want it to be visible when d1 is in x 0.0 and y 0.0...

    Regards //Sara

  5. #5
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    I made a quick file for you. It is done in the most simplest form. all of the code is on the main timeline. Note: all items on the stage have an instance name that is reffered to in the actionscript.

    hope this helps.

    IMS
    Attached Files Attached Files

  6. #6
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    if you want to set the green circle to a specific place on the stage if it is dropped correctly, the code would look like this:
    PHP Code:
    obj_1_mc.onRelease rc_mc.onReleaseOutside=function () {
        
    stopDrag();
        if (
    this.hitTest(drop_1_mc)) {
            
    trace('good')
            
    obj_1_mc._x 50;
            
    obj_1_mc._y 50;
            
    congrats_mc._visible true;
            }    

    I didn't think of this before, but your "if" statement will run as soon as you publish your file. that's why it doesn't work, because it is running before you even get the chance to drag and drop.

    IMS

  7. #7
    Junior Member
    Join Date
    Feb 2009
    Posts
    5

    snap function?

    Hi!

    Thank you IMS!

    But the snapfunction doesn't seem to work. Because I want it to stop drag when you have put it in the right position. It doesn't do that now, although it seems like it should?



    //Sara

  8. #8
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    So, you want the user to drag the item, and when it goes over the correct area, for it to automatically just stop dragging?


    IMS

  9. #9
    Junior Member
    Join Date
    Feb 2009
    Posts
    5
    Quote Originally Posted by IMS View Post
    So, you want the user to drag the item, and when it goes over the correct area, for it to automatically just stop dragging?
    IMS

    Correct!
    I want it to snap in place over the object, at the exact same position.



    //sara

  10. #10
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    paste this code over the old code:

    PHP Code:
    // set congratulation message
    congrats_mc._visible false;



    //instance name of green circle
    //This is what we want to drag.
    // using "this" in front of drag 
    // is basically saying "drag "this" 
    // object which is the green ball.
    obj_1_mc.onPress = function() {
        
    this.startDrag(); 
    }



    //this code will check to see if the 
    //green ball was dropped in the target area
    //drop_1_mc is the instance name of the target area
    obj_1_mc.onRelease rc_mc.onReleaseOutside=function () {
        
    stopDrag();
        if (
    this.hitTest(drop_1_mc)) {
            
    stopDrag();
            
    this._x 602.0;
            
    this._y 317.0;
            
    congrats_mc._visible true;
        }


    IMS

  11. #11
    Junior Member
    Join Date
    Feb 2009
    Posts
    5
    Quote Originally Posted by IMS View Post
    paste this code over the old code...

    IMS
    Hi!

    I have done that now and it works, it snaps :-)
    But it doesn't stop drag, even though the code says it should?

    if (this.hitTest(drop_1_mc)) {
    stopDrag();

    And I'm just curious about one thing, what does "rc_mc" mean?

    obj_1_mc.onRelease = rc_mc.onReleaseOutside=function ()




    ///Sara

  12. #12
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    Oops
    should be:
    PHP Code:
    obj_1_mc.onRelease obj_1_mc.onReleaseOutside=function () { 
        
    stopDrag(); 
        if (
    this.hitTest(drop_1_mc)) { 
            
    stopDrag(); 
            
    this._x 602.0
            
    this._y 317.0
            
    congrats_mc._visible true
        } 

    there is no code that I know of that will allow you to drag, and it will automatically stop dragging, without you actually "dropping" the object (releasing the mouse button) If you put the stopdrag in the on press function - it will still drag until you release the button, but then strange things happen.

    IMS

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