A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [F8] Weird "if" statement bug.

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    29

    [F8] Weird "if" statement bug.

    Hello -

    I'm working on a flash piece using this code:

    Code:
    on (release) {
    	doorsSelected = "2";
    	if (dimensionsWidth<="60" && project == "closetdoors") {
    		gotoAndStop("project");
    		loadMovie(project+doorsSelected+"narrow.swf", "mcProject");
    	} else if (dimensionsWidth>"60" && project == "closetdoors") {
    		gotoAndStop("project");
    		loadMovie(project+doorsSelected+"wide.swf", "mcProject");
    	} else {
    		projectSelected();
    	}
    	trace(dimensionsWidth);
    }

    So a value of 60 or lower plays the "narrow" swf, 61 or higher plays the "wide" swf. It works fine until the value for "dimensionsWidth" is a 3-digit number, then it goes to the "narrow" swf when it should be going to the "wide" swf. If I type in 120, the output gives me 120.

    Any ideas?

    Thanks.

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    is dimensionsWidth supposed to be a numeric value? If so, remove the quote marks from around the value as in:

    dimensionsWidth<=60
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Junior Member
    Join Date
    Jan 2008
    Posts
    29
    Same issue. Thanks, though. Any other ideas?

  4. #4
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Where is dimensionsWidth set and can you post the updated code.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  5. #5
    Junior Member
    Join Date
    Jan 2008
    Posts
    29
    Code:
    on (release) {
    	doorsSelected = "2";
    	if (dimensionsWidth<=60 && project == "closetdoors"
    		)
    	{
    		gotoAndStop("project");
    		loadMovie(project+doorsSelected+"narrow.swf", "mcProject");
    	} else if (dimensionsWidth>=60 &&  project == "closetdoors"
    			   ) {
    		gotoAndStop("project");
    		loadMovie(project+doorsSelected+"wide.swf", "mcProject");
    	} else {
    		projectSelected();
    	}
    	trace(dimensionsWidth);
    }

    "dimensionsWidth" is a dynamic text field in a previous frame. The trace shows the correct output.

  6. #6
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    try using parseInt(dimensionsWidth)

    on (release) {
    doorsSelected = "2";
    dimensionsWidth = parseInt(dimensionsWidth)
    if (dimensionsWidth<=60 && project == "closetdoors"
    )
    {
    gotoAndStop("project");
    loadMovie(project+doorsSelected+"narrow.swf", "mcProject");
    } else if (dimensionsWidth>=60 && project == "closetdoors"
    ) {
    gotoAndStop("project");
    loadMovie(project+doorsSelected+"wide.swf", "mcProject");
    } else {
    projectSelected();
    }
    trace(dimensionsWidth);
    }
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  7. #7
    Junior Member
    Join Date
    Jan 2008
    Posts
    29
    Awesome, that worked! Thanks!

    What does that mean? Parse Integer? Was Flash not always recognizing it as a number?

    This was my final code:

    Code:
    on (release) {
    	doorsSelected = "2";
    	dimensionsWidth = parseInt(dimensionsWidth)
    	if (dimensionsWidth<60 && project == "wallslidedoors") {
    		gotoAndStop("project");
    		loadMovie(project+doorsSelected+"narrow.swf", "mcProject");
    	} else if (project == "wallslidedoors") {
    		gotoAndStop("project");
    		loadMovie(project+doorsSelected+"wide.swf", "mcProject");
    	} else {
    		projectSelected();
    	}
    }

  8. #8
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Because you are getting the value from a text field, the value is by default a string. Yes it means parse integer (convert string to number). So basically what used to be happening is you were comparing if one string was longer than another, hence a 3 digit string was always greater than a a two digit string and the greater than clause would run.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


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