A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: string comparsion problem

Hybrid View

  1. #1
    Junior Member
    Join Date
    Jul 2004
    Posts
    5

    string comparsion problem

    Hello there,

    I got here a string comparing problem (or I think it is). I try to random generate a number and, say I will drag that number over some other instances, when that number match a instance's name, it will shows "correct"
    Now, I got a object instance called a07.

    on (release) {
    display = substring((Math.random()), 1, 3);
    }

    Occasionally, display will equal 0.7
    Now, with the following coding,

    hello = "0." + substring(this._droptarget, 4,1);
    // where this.droptarget is the instance a07
    if (hello == display) {
    _root.green_box.gotoAndStop(2); //Let's say it do stuff A
    } else {
    _root.green_box.gotoAndStop(3); //Let's sat it do stuff B
    _root.a07.gotoAndStop(3);
    }

    hello should equal 0.7 as well. However, everytime I drag the number over a07, it will do the else part rather than the if part. I must have misunderstand something about the string class...


    Could anyone help me here? Thank you very much.

    Kelly

  2. #2
    Run for your life! Phlook's Avatar
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    679
    try using some tracing, ex

    code:

    hello = "0." + substring(this._droptarget, 4,1);
    trace(hello);
    // where this.droptarget is the instance a07
    if (hello == display) {
    trace("yes it equals display");
    _root.green_box.gotoAndStop(2); //Let's say it do stuff A
    } else {
    _root.green_box.gotoAndStop(3); //Let's sat it do stuff B
    _root.a07.gotoAndStop(3);
    trace("oh no, it doesnt equal display");
    }



    see if it's actually running that or if theres some problem
    oh, and use the [/as] [as] tags for code (i put them in wrong order so they dont work

  3. #3
    Junior Member
    Join Date
    Jul 2004
    Posts
    5

    gobal variable???

    Hello there,

    Thanks for the advice. I tried the trace line, and it ends up the display has NOTHING in it...empty string..... but it appear on screen all right. I have look at my display variable, which is a single line dynamic text. I wonder if this is the problem, something like local variable which can't be use outside the function. I was looking at the ActionScript manual, whcih said you can use either setVariables action or (=) assignment to set a gobal variable, which I already did
    code:
    on (release) {
    display = substring((Math.random()), 1, 3);
    }



    Am I doing something wrong?

    Kelly

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