dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: if (this["item"+n] == "Hello") { << doesn't seem to work.

  1. #1
    Senior Member James Bending's Avatar
    Join Date
    May 2001
    Location
    Devon, England.
    Posts
    157
    Hello i posted this in the Flash 5 forum but it also applies for the Flash MX forum aswell because i used MX to create it so i thought you guys might be able to help


    on the first frame i set this variable


    n = 1;



    on the second frame i set this variable



    this["item"+n] = "hello";



    (this makes the variable, item1 = "hello")
    On the thirdframe i do this



    if (this["item"+n] == "Hello") {
    this["item"+n] = "Goodbye";
    }


    It works up to the third frame, it does not check if it item1 equals "hello" and so it doesn't change, i know that it is this piece of code on the third frame which doesn't work;

    if (this["item"+n] == "Hello") {


    If you can help me figure out why it doesn't work i will be a VERY happy man, i tried putting a post up before but no one seemed to reply, thanks again and thanks for your time,

    Jim


  2. #2
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    You're comparing "hello" with Hello!

    The following script works fine, and on one frame only!
    Also added several trace actions, so you can values in the output window, while testing this.

    stop();
    n = 1;

    this["item"+n] = "hello";
    trace(item1);
    trace(this["item" + n]);

    if (this["item"+n] == "hello") {
    this["item"+n] = "Goodbye";
    }
    trace(item1);

  3. #3
    Senior Member James Bending's Avatar
    Join Date
    May 2001
    Location
    Devon, England.
    Posts
    157
    Originally posted by oldnewbie
    You're comparing "hello" with Hello!

    The following script works fine, and on one frame only!
    Also added several trace actions, so you can values in the output window, while testing this.

    stop();
    n = 1;

    this["item"+n] = "hello";
    trace(item1);
    trace(this["item" + n]);

    if (this["item"+n] == "hello") {
    this["item"+n] = "Goodbye";
    }
    trace(item1);
    Thanks i'll try it, what is a trace though? Also do you know how i might go about doing it with an array rather than variables? Thanks alot for your time

    Jim

  4. #4
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Trace is an action that permits you to check some values while testing your movie. The result is outputed in the output window only while testing and will not appear, when you play the final .swf itself, even if you leave those trace actions in your scripts. Very useful!

    Don't quite get your second question?

  5. #5
    Senior Member James Bending's Avatar
    Join Date
    May 2001
    Location
    Devon, England.
    Posts
    157
    Don't quite get your second question? [/B]
    sorry forget the second question, i have a different one now, if i was to put the code;

    if (this["item"+n] == "hello") {
    this["item"+n] = "Goodbye";
    }
    trace(item1);

    in a movieclip on the second frame how would i go about that? because the If statement then doesn't work, which is my main problem. Thanks alot for your time!

    Jim


  6. #6
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    All of this would be much easier if you sent me your .fla so that I can understand what you're really trying to do here!
    Why for instance, are you not just using item1 as a variable name. Is this a global variable within the whole movie, or do you want it to only be local to this movie clip you have on frame 2? Etc..Etc...
    Don't just tell me your goal's not working... Tell me the purpose of all of this! I'm not sitting beside you!

  7. #7
    Senior Member James Bending's Avatar
    Join Date
    May 2001
    Location
    Devon, England.
    Posts
    157
    [QUOTE] Tell me the purpose of all of this! I'm not sitting beside you!
    /QUOTE]

    nevermind. All i wanted to try and find out was how to do this check;

    if (this["item"+n] == "Hello") {
    this["item"+n] = "Goodbye";
    }

    in a movieclip rather than on the root. You don't need to know the purpose to be able to explain it because its just simple enough to answer without having to go into details of an inventory system which keeps on checking if thier is a space avaiable, which by the way is my goal.

    However if you would like me to send you the .fla then email me at j_bending@hotmail.com

    Thanks for your time!

    James

  8. #8
    Member
    Join Date
    Apr 2002
    Location
    Nevada
    Posts
    57
    Here is the code for a Array implementation.

    var name = new Array();
    for(var i=0;i<10;i++) {
    this.name\[i\] = "Hello";
    trace("I: " + i + " - " + this.name\[i\]);
    if(this.name\[i\] == "Hello") {
    this.name\[i\] = "Goodbye";
    }
    trace("I: " + i + " - " + this.name\[i\]);
    }

    Hope this helps.

    I had to put \[ and \] because they don't render in the post? So read \[i\] without out the slashes in it.

  9. #9
    Senior Member James Bending's Avatar
    Join Date
    May 2001
    Location
    Devon, England.
    Posts
    157

    thanks


    Hope this helps.

    indeed it does thank you very much guys!

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