A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [AS3] proper use of square bracket?

  1. #1
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693

    [AS3] proper use of square bracket?

    Code:
    var tipByTxt:Dictionary = new Dictionary();
    tipByTxt[Game.txtpName] = "some text";
    Game.txtTip.text = tipByTxt[Game[e.currentTarget.name]];//This doesnt work.
    trace(e.currentTarget.name);
    trace(Game);
    trace(tipByTxt[Game.txtpName]);
    trace(Game[e.currentTarget.name]);
    /* Traces the following:
    txtpName
    [object MainTimeline]
    some text
    undefined
    */
    Can anyone explain how to get the line that doesn't work to work? I don't really know how to describe this problem but I think its pretty self-explaining what syntax I'm having a problem with... The undefined is what I don't understand...
    mmm signature

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    is Game:? actually a array or Dictionary Object?
    when tracing it says
    [object MainTimeline]
    so what is it actually? Because I think there is your error because its not some array or dictionary and therefore can't accessed with the square brackets

    just googled for these:
    http://www.gskinner.com/blog/archive...ictionary.html
    http://www.kirupa.com/forum/showthre...223798&page=19
    I haven't worked with the dictionary myself yet because i usually solve things like that with 2 arrays one holding the index and the other one the data.

  3. #3
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    Game is... a movieclip... Its actually the main stage of the game pretty much... I don't think the problem lies in dictionary my problem is that

    Game.txtpName != Game[e.currentTarget.name]
    however,
    txtpName == e.currentTarget.name

    I just can't figure out why Game.txtpName != Game[e.currentTarget.name]

    hmm after careful thought it might not be Game.txtpName != Game[e.currentTarget.name], I'm not sure how to check if they are the same, if I trace both of those i get undefined but
    tipByText[Game.txtpName] != tipByText[Game[e.currentTarget.name]]
    Last edited by ChaseNYC; 10-04-2008 at 07:59 PM.
    mmm signature

  4. #4
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    my point was if
    PHP Code:
    Game[e.currentTarget.name
    is undefined

    then
    PHP Code:
    tipByTxt[Game[e.currentTarget.name]] 
    aka
    PHP Code:
    tipByTxt[undefined
    wont work at all

    hmm reading gain I think what you want is simply:
    PHP Code:
    Game.txtTip.text tipByTxte.currentTarget.name ]; 
    because e.currentTarget.name is some string and perhaps a key to you, try it

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