A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: annoying problem with variables :(

  1. #1
    Flash Beginner
    Join Date
    May 2004
    Location
    Egypt
    Posts
    25

    annoying problem with variables :(

    hi all

    simply I created new flash document,
    .. created new movieclip named "ball" with instance name "ball" in the stage
    in the ball movieclip I put this code in the actionscript panel

    Code:
    var color = "red";
    I want to use this variable in the main stage

    i used

    Code:
    var ballcolor= ball.color;
    trace (ballcolor);
    but didn't work and the result is "undefined"

  2. #2
    Senile member! :)
    Join Date
    Dec 2001
    Location
    Saunaswamp (transl)
    Posts
    2,296
    Note that script is run from the main timeline and then outwards in the movieclip hierarchy. So if the code you have on the main timeline is on the first frame with the movieclip it would run before the script that's setting the variable.

    If you move it to the next frame, assuming that the movieclip is still on the timeline there it should find that ball.color is == "red".

    Another way that you could do this is to put the skript: var color = "red"; in an onClipEvent(load) handler on the movieclip instance. That will make that code run before the skript on the main timeline. But it would be an ugly solution I guess.

    /Mirandir

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