Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Results 1 to 8 of 8
  1. #1

    Default 2 IF/ELSE statements on 1 action - possible?

    Below is my script that isn't quite working as imagined.

    trace tells me the variable comp is being increased (by 25) every time the user hits the mark, but the second IF just gets ignored. Once comp hits 100 I want play to continue down the timeline.

    I've tried moving the second IF up into the curly brackets of the first - creating what I would call a nested IF but no joy. Things just got worse - snapback to original position stopped working.

    Thanks in advance

    on (press) {
    startDrag(this);
    this.swapDepths(100);
    }
    on (release) {
    stopDrag();
    if (this._droptarget=="/Target3") {
    setProperty(this, _x, 68.0);
    setProperty(this, _y, 295.7);
    var comp = comp + 25
    } else {
    setProperty(this, _x, 20.1);
    setProperty(this, _y, 32.1);
    }
    {
    if (comp >= 100) {
    play();
    } else {
    gotoAndPlay(2);
    }
    trace(comp);
    }
    }

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    First off, I dont see anywhere in your code sample where your incrementing the variable "count" besides the on press event. Second, using setProperty is a flash 4 method and can be addressed with dot notation.....

    setProperty(this, _y, 32.1);

    in dot notation would look like....

    this._y=32.1;

    What is the original value of your count variable and how are you incrementing it? In the code sample you posted, variable "count" is only increased on a press event. A nested if statement is one that resides inside of another if statement. The code sample you posted uses seperate if statements inside the on press event handler. Maybe a more precise description of what your trying to achieve would help.

    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  4. #3

    Default

    The original value of my count variable (var comp) is set to 0 when the .swf loads on my page - set var comp = 0, an action on frame one of the timeline. I have verified that with a trace.

    I have four moveable items that I want the user to place in the right order. My idea is that if the user moves say item one into it's correct target, var comp gets incremented by 25 on the release event handler. As the user moves items 2, 3 and 4 into their correct targets var comp will increase by 25 on each correct placement. Once all four are on their correct targets, var comp will be 100 and then the second IF statement finds that to be true and play() moves things down the timeline for some postive feedback (a text message)

    My variable comp is working - being incremented by 25 - when an item hits it's target. The second IF statement just gets ignored. Through trace I watch comp go to 25, 50, 75, 100, 125, and beyond and the second IF never executes.

    I know my sample code is not a nested IF statement. Through the help and other sources I tried nesting, but things just got worse. Two seperate IF statements make sense to me, but I haven't been able to figure it out in Flash.

    So my goal is
    set var = 0 //working
    IF item hits it's target set var = var + 25 //working
    IF var = 100 //meaning all 4 items have been place on their targets
    play() //move on down the timeline

    The second IF is not executing.

  5. #4
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    I think I understand what your trying to achieve now. I normally prefer frame code, but this might be an instance where object code might just be easier. Create a demo movie with two movieclips. Name the drop target clip "t1". You dont need an instance name for the draggable movieclip, but it is a good habit to get into. On the clip you want to be draggable, paste this code....

    Code:
    onClipEvent (load) {
    	myX = this._x;
    	myY = this._y;
    }
    onClipEvent (enterFrame) {
    	this.onPress = function() {
    		startDrag(this);
    	}
    	this.onRelease = this.onReleaseOutside=function () {
    		if (this.hitTest(_root.t1)) {
    			_x = _root.t1._x;
    			_y = _root.t1._y;
    			_root.score += 25;
    			stopDrag();
    			_root.nextFrame();
    		} else {
    			this._x = myX;
    			this._y = myY;
    			stopDrag();
    		}
    	}
    }
    This will position the draggable clip on release, if it is in contact with the "t1" clip, it will snap to that position. If it is not in contact with "t1" when the clip is released, it will snap back to it's original position. Now, I just incremented the score when the hitTest returns true and sent it to the next frame of the movie, but you can handle this however works best for you.

    hope it helps
    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  6. #5

    Default

    My code - much older and probably less efficient - is working to place clips on their targets or snap back to original positions. It also works to the point of incrementing my variable by 25 when the correct target is hit.

    What's not working is the test of that variable via a second IF statement.
    How do I test that variable onRelease to see if it equals 100?
    A second IF statement? A nested IF statement?

    Let's say items 1, 2 and 3 are in place. The variable has incremented to 75. The user clicks on item 4, releases item 4 on it's target, the variable is incremented to 100 and then a test (IF statement) of that variable value, confirms 100 and then moves _root.nextFrame()

    I don't want to move to the next frame until all 4 items are in the proper order (variable = 100)

  7. #6

    Default

    My code - much older and probably less efficient - is working to place clips on their targets or snap back to original positions. It also works to the point of incrementing my variable by 25 when the correct target is hit.

    What's not working is the test of that variable via a second IF statement.
    How do I test that variable onRelease to see if it equals 100?
    A second IF statement? A nested IF statement?

    Let's say items 1, 2 and 3 are in place. The variable has incremented to 75. The user clicks on item 4, releases item 4 on it's target, the variable is incremented to 100 and then a test (IF statement) of that variable value, confirms 100 and then moves _root.nextFrame()

    I don't want to move to the next frame until all 4 items are in the proper order (variable = 100)

    Thanks for the help

  8. #7
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    You could just use an onEnterFrame event to globally monitor the score variable.....

    this.onEnterFrame=function(){
    if(_root.score==100){
    _root.nextFrame();
    delete this.onEnterFrame;
    }
    }


    If at any point _root.score = 100, the timeline will automatically be sent to the nextFrame. Checking the variable in a global sense would be easier than checking it onRelease of each movieclip.
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  9. #8

    Default

    Thanks for the help.

    I'll try and rebuild this little module from the ground up with the input that I have received from the forum.

    In an effort to meet my deadline, I'll go with a quick fix that I found.
    I used
    _root.nextFrame()
    instead of gotoAndPlay()
    and viola, the second IF statement on my onRelease worked as imagined.

    Thanks again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. action scripting help please
    By designerindex in forum Newbies
    Replies: 1
    Last Post: 06-21-2005, 07:55 PM
  2. if statements help
    By Ginrikki in forum Flash Scripting
    Replies: 1
    Last Post: 04-06-2005, 11:32 PM
  3. If else statements that don't work
    By KingKong in forum Flash Scripting
    Replies: 1
    Last Post: 12-26-2004, 10:12 PM
  4. IF, THEN, =, statements
    By KingKong in forum Flash Scripting
    Replies: 3
    Last Post: 12-26-2004, 09:51 PM
  5. conditional statements help?
    By krylon in forum Flash Scripting
    Replies: 1
    Last Post: 09-07-2004, 06:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial