A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Simple variable issue

  1. #1

    Simple variable issue

    This is a simple task, but it is not working for me, thus I am forced to inquire...

    -On the main timeline I can place an instance of a movie and name that instance "square"
    -On the first frame of the timeline in square I can declare a variable named "cat" and assign it the value of "13"

    var cat = 13;

    -On the first frame of the main timeline (with the square movie instance present) I can place this code...

    trace(square.cat);

    And yet it will still output "undefined"

    What am I doing wrong?

    Thank you for your time. Best Wishes to you all,
    Eric

  2. #2
    Senior Member
    Join Date
    Jan 2005
    Posts
    117
    well Eric,on the first frame if the timeline u gotta put just
    cat = 13;
    and then
    trace(cat);

    you might need an onEnterFrame handler, but check it out to see if it works

  3. #3
    Thank you for your reply.
    I understand that that would work (declaring the variable on the main timeline as well), but isn't it possible to call upon and refernce variables from the main timeline that are declared NOT on the main timeline, but instead in a movie clip instance that is placed ont he main timeline through dot syntax?

  4. #4
    Senior Member pwned's Avatar
    Join Date
    Apr 2003
    Location
    Peoria Il
    Posts
    212
    It's not calling the variable correctly because it's attempting to access it before the movieClip that you have the variable in has been initialized

  5. #5
    Quote Originally Posted by pwned
    It's not calling the variable correctly because it's attempting to access it before the movieClip that you have the variable in has been initialized
    I thought for sure that this was it, but even when placing the "square" movie clip from frame one to frame 10 and placing the actionscript on frame 10, it still outputs and undefined variable. What has to be done to make sure the movie has initialized the movie clip first?

  6. #6
    Senior Member pwned's Avatar
    Join Date
    Apr 2003
    Location
    Peoria Il
    Posts
    212
    just humor me
    if you write
    code:

    this.onEnterFrame=function(){
    trace(square.cat)'
    }


  7. #7
    Quote Originally Posted by pwned
    just humor me
    if you write
    code:

    this.onEnterFrame=function(){
    trace(square.cat)'
    }

    Thank you, it worked. I was just confused, as Colin Moock's book didn't mention needing to do that, and just said use movieInstanceName.variable to call the variable. Though I would like to mention that Moock absolutely rules, and this book is great.
    So I still don't understand the logic per se of why onEnterFrame was necessary, it did indeed work, so I'll use it from now on. It helped to add
    delete this.onEnterFrame;
    so that it didn't repeate the variable endlessly.

  8. #8
    Senior Member pwned's Avatar
    Join Date
    Apr 2003
    Location
    Peoria Il
    Posts
    212
    you dont need to write onEnterFrame.. its just that your movieClip was being initiated after your variable call to 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