Problems with if-else statements in dynamic text

Ask a Question related to Macromedia Flash Actionscript, Design and Development.

  1. #1

    Default Problems with if-else statements in dynamic text

    Hi,

    I'm new to Flash and ActionScript and have never previously done programming. However, I have a technical degree and experience and have a clear idea of what I'm trying to get out of ActionScript.

    I've been trying for some period of time to make an if-else statement work with dynamic text. As far as can be determined, only two code blocks will work. Any numeric values will work in the two code blocks, but anything in the third or subsequent blocks returns the default, labeled "error."

    I'm running Flash MX. According to Colin Moock's "ActionScript, the Definitive Guide," p. 134, I should be able to use an unlimited number of code blocks.

    Appended below is the code. I tried to attach the *.fla file, but the forum said it was an unrecognized format! That's pretty bad if Macromedia's forum doesnt recognize the company's own file format! BTW, I had a bunch of problems getting on and using this forum.

    BTW, among other things, I tried using double equal signs in the conditional -- no dice. Also, I included some other attempts -- switch statement and an an array push. Both gave identical results. Anyway, I'd be grateful if anyone could tell me how to fix this or at least why it won't work.

    thanks, jay


    /*For any given number for "value," the text will only properly display in the movie
    if the number is within the first and second code blocks. Any number value within
    the other code blocks returns as "error." It seems ridiculous that a conditional should
    only work for two code blocks.*/
    var value = 1.4

    if (0.1 > value > 0) {
    Info = "first";
    } else if (1.5 > value > 0.1) {
    Info = "second";
    } else if (1.7 > value > 1.5) {
    Info = "third";
    } else if (3.0 > value > 1.7) {
    Info = "fourth";
    } else if (3.3 > value > 3.0) {
    Info = "fifth";
    } else if (4.6 > value > 3.3) {
    Info = "sixth";
    } else if (4.8 > value > 4.6) {
    Info = "seventh";
    } else if (6.2 > value > 4.8) {
    Info = "eighth";
    } else if (6.2 > value > 4.8) {
    Info = "ninth";
    } else {
    Info = "error";
    }

    /*
    Info = new Array();
    Info.push(["first"]);
    Info.push(["second"]);
    Info.push(["third"]);
    Info.push(["fourth"]);
    Info.push(["fifth"]);
    Info.push(["sixth"]);
    Info.push(["seventh"]);
    Info.push(["eighth"]);
    Info.push(["ninth"]);
    Info.push(["error"]);

    if (0.1 > value > 0) {
    Info = Info[0];
    } else if (1.5 > value > 0.1) {
    Info = Info[1];
    } else if (1.7 > value > 1.5) {
    Info = Info[2];
    } else if (3.0 > value > 1.7) {
    Info = Info[3];
    } else if (3.3 > value > 3.0) {
    Info = Info[4];
    } else if (4.6 > value > 3.3) {
    Info = Info[5];
    } else if (4.8 > value > 4.6) {
    Info = Info[6];
    } else if (6.2 > value > 4.8) {
    Info = Info[7];
    }else if (value > 6.2) {
    Info = Info[8];
    } else {
    Info = Info[9];
    }

    */

    /*
    switch (value) {
    case "(0.1 > value > 0)":
    Info = "first";
    break;
    case "(1.47 > value > 0.1)":
    Info = "second";
    break;
    case "(1.68 > value > 1.47)":
    Info = "third";
    break;
    case "(3.03 > value > 1.68)":
    Info = "fourth";
    break;
    case "(3.25 > value > 3.03)":
    Info = "fifth";
    break;
    case "(4.60 > value > 3.25)":
    Info = "sixth";
    break;
    case "(4.82 > value > 4.60)":
    Info = "seventh";
    break;
    case "(6.17 > value > 4.82)":
    Info = "eighth";
    break;
    case "(value > 6.17)":
    Info = "ninth";
    break;
    default:
    Info = "error";
    }
    */
    trace (value);
    trace (Info);


    jayfromcleveland webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. Problems with displaying dynamic Arabic text
      We have a problem with a navigation system we are building which has to be able to display dynamic Arabic text. We are pulling in the Arabic text...
    2. Anti-aliased dynamic text problems
      Hey all, my dynamicly loaded text wont anti-alias characters like "é" and "ü", they just dissappear from the text. I tried embedding font...
    3. Dynamic Text Problems with nested SWFs
      I created a SWF that uses uses dynamic text to show song IDs for an MP3 player It works great by itself, but when I load this SWF as a movie into...
    4. load external text to dynamic text field in levels
      Dear Sir I found the Tech Noe Index #16238 is useful in creating dynamically loaded text from external text file. However, the method mentioned...
    5. Dynamic text box within dynamic movie clip
      I'm having a similar problem. On mine I noticed that although the text doesn't show and the border doesn't show, the cursor changes appropriately...
  3. #2

    Default Re: Problems with if-else statements in dynamic text

    you cannot use 0.1 > value > 0 etc ... it nonsense


    Jeckyl Guest

  4. #3

    Default Re: Problems with if-else statements in dynamic text

    What do you mean "it nonsense" (sic)? It's a range of values, a perfectly acceptable mathematical expression, and a valid condition for a "true/false" determination. So how would you from select multiple values? Next time, why not write a helpful reply?


    jayfromcleveland webforumsuser@macromedia.com Guest

  5. #4

    Default Re: Problems with if-else statements in dynamic text

    Flash works using the variable and then the value. So you can do the following:

    if (myvar != 6 && myvar > 5) {
    gotoAndPlay("label1");
    }

    but you can't do:

    if (6 != myvar) {
    gotoAndPlay("nochanceinhell");
    }


    hope this helps

    Dom


    domconlon webforumsuser@macromedia.com Guest

  6. #5

    Default Re: Problems with if-else statements in dynamic text

    Hi Dom, I see, so if I set this up as a compound conditional, Flash will know what to do since the variable will be presented first. I'll give that a try. Thanks! -jay


    jayfromcleveland webforumsuser@macromedia.com Guest

  7. #6

    Default Re: Problems with if-else statements in dynamic text

    its not really valid for a programming languages.

    you can only do one comparison at a time.

    mathematically you may write

    a < b < c

    to mean b is between a and c

    in a programming language like AS, you would write

    a < b && b < c

    (ie a is less than b and b is less then c).

    what you wrote is syntactically correct, but it doesn't do anything like
    what you think it is doing !!!


    Jeckyl Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139