change struct values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nibbus
    New Member
    • Nov 2007
    • 18

    change struct values

    Hello all the coders!

    I´m trying to attrib a value to x and y, what am I doing wrong?

    Code:
    this.start = { x:"hello1", y:"hello2" }
    when printing this.start.x it gives me " runtime error: 'this.start.x' is null or not an object". (IE7)

    finally, It might be handy to attrib those values through other vars, but I think I could do that if I managed to work that x and y.

    thanks in advance for any kind of help
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    I do not think structs are supported in JavaScript. You could do this as an array, or as an object though



    Code:
    // Object example
    this.start = {  var x = "hello1";  var y = "hello2"; }
    
    //Array Example
    this.start['x'] = 'hello1';
    this.start['y'] = 'hello2';

    Comment

    • Nibbus
      New Member
      • Nov 2007
      • 18

      #3
      thanks for your answer pronerd, but I still can´t work it out... even by object as you sugested (the array should work by I really wanted not to be by array).

      the code I posted works in FF, that´s why I wanted to follow the same approach for IE7...

      Comment

      • pronerd
        Recognized Expert Contributor
        • Nov 2006
        • 392

        #4
        Originally posted by Nibbus
        I still can´t work it out..
        Can't work what out? Are you getting an error? If so what does it say?

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5388

          #5
          hmmm ...

          i think:

          [CODE=javascript]this.start = { var x = "hello1"; var y = "hello2"; }
          [/CODE]
          should be:

          [CODE=javascript]this.start = { x: "hello1", y: "hello2" };[/CODE]
          kind regards

          Comment

          Working...