A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: makin calender.. variable scope problem

  1. #1
    Senior Member
    Join Date
    Aug 2002
    Location
    Ireland
    Posts
    194

    makin calender.. variable scope problem

    I'm makin an events calender for my brothers clan website (will release open-source soon)..
    I've been working on it for the last few days (over 130 lines of code) and I am almost complete, but I have came across a problem..
    When the user highlights a date on the calender that has an event, I want a textbox at the bottom of the page display info about the event..
    I am using the following code and all the arrays, variable, movieclips etc. are setup:

    for (k=0; k<_root.eventsArray.length; k++) {
    eval(_root.eventNumbers[k]).onRollOver = function() {
    calenderBase.eventDescription = _root.eventsArray[k];
    };
    eval(_root.eventNumbers[k]).onRollOut = function() {
    calenderBase.eventDescription = "";
    };
    }

    When the user highlights a date, instead of the textbox displayin the description, it displays "undefined"..
    I think that the problem is that on the 3rd line of code, the script cannot find the k variable because if I add 'trace(_root.eventsArray[k])' it traces the description..
    How do I fix this problem?
    Thanks
    -Declan

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    If you attach the event text to the object that you are assigning the rollovers to, then you can read it directly without needing K.

    Code:
    for (k=0; k<_root.eventsArray.length; k++) 
    {
      var ev = eval(_root.eventNumbers[k]);
    
      // make a copy here, where you can still read K
      ev.eventCpy = _root.eventsArray[k];
    
      ev.onRollOver = function() 
        { // inside the function you can't read k, but you can read eventCpy
          calenderBase.eventDescription = this.eventCpy;
        };
    
      ev.onRollOut = function() 
        {
          calenderBase.eventDescription = "";
        };
    }
    - Jim

  3. #3
    Senior Member
    Join Date
    Aug 2002
    Location
    Ireland
    Posts
    194
    thanks jim..
    ill try that out now, and ill tell ya how i get on tomorrow (i dont get online that much )

  4. #4
    Senior Member
    Join Date
    Aug 2002
    Location
    Ireland
    Posts
    194

    yippee

    nice, just got it goin.
    thanks jbum.
    im attaching the fla, still a few (small) errors, ill try to fix them now
    Last edited by lgs; 03-06-2004 at 03:04 PM.

  5. #5
    Senior Member
    Join Date
    Aug 2002
    Location
    Ireland
    Posts
    194

    sorry

    well, somthin happened my attachment, so dont download it..
    ya can get it here: www.themovievault.com/calender1.fla
    Last edited by lgs; 03-08-2004 at 05:38 PM.

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