A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Need help with If Else Statement

  1. #1
    Junior Member
    Join Date
    Oct 2006
    Posts
    26

    Question Need help with If Else Statement

    Hi, I need some help finishing up my flash project. I have been trying for the last 2 days to write and if else statement that will do the following:

    - if they click on the _root.m<>1 it will go to adobe.com if they click on _root.m<>2 they will go to yahoo.com.

    -I have 6 _root.m 's

    Code:
    on (release) {
    	if (_root.m<>1) {
    getURL("http://www.adobe.com","_self");
    	}
    	else if (_root.m<>2) {
    		getURL("http://www.google.com","_self");
    }
    }

    When I test it the url and it opens 2 windows no matter what one is clicked!?!
    Can you please help.

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    What are the _root.m? If it is a variable, then you want to check it against the integer. In that case, try something like this.
    PHP Code:
    on(release)
    {
        if(
    _root.== 1)
        {
            
    getURL("http://www.adobe.com""_self");
        }
        else if(
    _root.== 2)
        {
            
    getURL("http://www.google.com""_self");
        }

    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Junior Member
    Join Date
    Oct 2006
    Posts
    26
    Hi Samac,

    I tried your code and it only works if I change the == to <> ex. _root.m<>1. I'm not sure if it is a variable or not. But it only goes to the adobe website when any of the buttons are clicked, the second one doesnt work. Would you mind taking a look at my code? I am working mainly with the Button1 MC and the pictures_mc. My file is a little to big to attach so I put it out on our server here.. You can find the code I am working on if you click on the Button1 MC and it has the following:

    Code:
    on (rollOver) {
    	_root.cont.cont["b"+p].gotoAndPlay("s1");
    	if (_root.m<>1) {
    		_root.b = p;
    	}
    	if (_root.mov<>1 and _root.m<>1) {
    		_parent.names.gotoAndPlay("s1");
    	}
    }
    on (releaseOutside, rollOut) {
    	_root.cont.cont["b"+p].gotoAndPlay("s2");
    	if (_root.m<>1) {
    		_root.b = 7;
    		//_parent.names.gotoAndPlay("s1");
    	}
    }
    on(release)
    {
        if(_root.m<>1)
        {
            getURL("http://www.adobe.com", "_self");
        }
        else if(_root.m<>2)
        {
            getURL("http://www.google.com", "_self");
        }
    }
    Thank you.

  4. #4
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    I am confused as to what _root.m is.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  5. #5
    Junior Member
    Join Date
    Oct 2006
    Posts
    26
    the original code i replaced was and it had the _root.m in it so I just continued to use it. I tried replacing it with "p" because it is in the Buttons1 MC also and it worked. (
    Code:
    stop();
    //p=3
    area.gotoAndStop(p);
    pic.gotoAndStop(p);
    pic2.gotoAndStop(p);
    )

    Code:
    on (release) {
    	if (_root.m<>1) {
    		//_root["b"+_root.b].gotoAndPlay("s2");
    		//_root.cont.gotoAndPlay("s1");
    		_root.b = p;
    		_root.cont.cont.gotoAndPlay("diss");
    		_root.scroller.gotoAndStop("s0");
    	}
    }

  6. #6
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Fro what you are describing, it sounds more like a variable on the main timeline. Do you know how m is being updated. Instead of using <> you can use !=.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  7. #7
    Junior Member
    Join Date
    Oct 2006
    Posts
    26
    ok, i want to put this statement in my buttons1 mc, but I want to call a different frame from a different movie clip to ex. instead of using if(_root.m<>1) can i use frame 3 from movie clip PicturesMC. So when a user clicks on the image from PicturesMC frame 3 they go to a url, and when they click on frame 2 they go to a different URL. How would I reference it instead of using: if(_root.m<>1) ? Can you walk me through this?

  8. #8
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Make a global variable, and for each frame change it to the URL you want. When the user clicks, the URL path is already set.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  9. #9
    Junior Member
    Join Date
    Oct 2006
    Posts
    26
    Could I just use an instance name (MYInstanceName) I gave to that clip and then reference the frame (1,2,3,4,5,6) inside it? Im not 100% sure on how to make a global variable. I am thinking the code would look something like this with my instance name, is this correct?

    Code:
    on(release)
    {
        if (MYInstanceName = 1)
        {
            getURL("http://www.adobe.com", "_self");
        }
        else if (MYInstanceName = 2)
        {
            getURL("http://www.google.com", "_self");
        }
    	else if (MYInstanceName = 3)
        {
            getURL("http://www.yahoo.com", "_self");
        }
    	else if (MYInstanceName = 4)
        {
            getURL("http://www.ask.com", "_self");
        }
    	else if (MYInstanceName = 5)
        {
            getURL("http://www.amazon.com", "_self");
        }
    	else if (MYInstanceName = 6)
        {
            getURL("http://www.feeco.com", "_self");
        }
    }

  10. #10
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    That looks good, except when comparing you need to use == (double equal signs) using a single will assign the information on the right to the object on the left. You can also use a switch statement. It would look like this
    PHP Code:
    on(release)
    {
        switch(
    MYInstanceName)
        {
            case 
    1:
                
    getURL("http://www.adobe.com""_self");
                break;
            case 
    2:
                
    getURL("http://www.google.com""_self");
                break;
            case 
    3:
                
    getURL("http://www.yahoo.com""_self");
                break;
            case 
    4:
                
    getURL("http://www.ask.com""_self");
                break;
            case 
    5:
                
    getURL("http://www.amazon.com""_self");
                break;
            case 
    6:
                
    getURL("http://www.feeco.com""_self");
                break;
        }

    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  11. #11
    Junior Member
    Join Date
    Oct 2006
    Posts
    26
    ok, here is what i did. for some reason it is not working:


    Code:
    on(release)
    {
        if (pictures_mc == 1)
        {
            getURL("http://www.adobe.com", "_self");
        }
        else if (pictures_mc == 2)
        {
            getURL("http://www.google.com", "_self");
        }
    	else if (pictures_mc == 3)
        {
            getURL("http://www.yahoo.com", "_self");
        }
    	else if (pictures_mc == 4)
        {
            getURL("http://www.ask.com", "_self");
        }
    	else if (pictures_mc == 5)
        {
            getURL("http://www.amazon.com", "_self");
        }
    	else if (pictures_mc == 6)
        {
            getURL("http://www.feeco.com", "_self");
        }
    }



  12. #12
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Because you want to evaluate if the picture_mc is at a specific frame, so it would look like this:
    PHP Code:
     ...
      if (
    pictures_mc._currentframe == 1)
        {
            
    getURL("http://www.adobe.com""_self");
        }
        else if (
    pictures_mc._currentframe == 2)
        {
            
    getURL("http://www.google.com""_self");
        }
        ... 
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  13. #13
    Junior Member
    Join Date
    Oct 2006
    Posts
    26
    thank you for your help. I just cant get it to work. I have all of the correct code, but it just won't open the pages. I tried putting in an = and the <> and it will only open the pages then but it is only for the first link.

  14. #14
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Can you post your file?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  15. #15
    Junior Member
    Join Date
    Oct 2006
    Posts
    26
    It was a little bit to big to post but I put it on our server here to download.

  16. #16
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Well you can do the following: Within the PAGES mov >> PAGE-SLASH movieclip, I added the following code for each button.

    PHP Code:
    b1.onRelease = function()
    {
        
    trace("Button was pressed.");
    }

    b2.onRelease = function()
    {
        
    trace("");
    }

    b3.onRelease = function()
    {
        
    trace("");
    }

    b4.onRelease = function()
    {
        
    trace("");
    }

    b5.onRelease = function()
    {
        
    trace("");
    }

    b6.onRelease = function()
    {
        
    trace("");

    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

Tags for this 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