#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13

    setting and recognizing variables internally


    I hope I explain this coherently... a little new to Flash.

    I have a movie, within that movie I have a frame action that says

    if(var=="1"){
    gotoNextFrame();
    }

    in another movie that is a child of that movie, I set var="1" based on a rollOver. Problem is that it doesn't seem that var is getting picked up back in the parent movie. I tried _root.var="1" and _parent.var="1" to no avail.

    are variables scoped to the movie that sets them? Is there a way to make a variable global?

    I think there is something pretty basic here that I am missing.

    any advice is appreciated.
  2. #2
  3. macho member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    207
    Rep Power
    12
    I think you are just missing the variable declaration on the root timeline and also the 'var' variable name is restricted - it is used by flash.

    just place this on the 1st frame of the your _root timeline:

    var testVar;

    this declares the variable for later use.

    when you want to alter this variable/flag value. Do this anywhere in your movie.

    _root.testVar = "1";

    this will alter the value.
    then anywhere in your movie:

    if (_root.testVar == "1")
    {
    // do something
    }
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    ok tried that and it still doesn't accomplish the desired effect.

    I am declaring the var testVar; in the first frame of the root timeline, and the if condition is also in the first frame of the root timeline.

    testVar gets updated to "1" based on a user rollover in a nested movie one level down. When that happens I want the root timeline to move to the nextframe. I think maybe I need something like a tellTarget definition or something to put the focus back on the root timeline?

    thanks for the help
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    think I figured it out...

    tellTarget is deprecated, so I used the with() statement like this:

    var testVar; - declared on the root timeline

    then in the nested movie one level down:

    with (_parent) {
    testVar = "1";
    gotoAndStop("frameLabel");
    }

    this worked
  8. #5
  9. No Profile Picture
    flash junkie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    CO, USA
    Posts
    172
    Rep Power
    12
    by the way, puttin "_global" in front of your variables will make them global

    so

    _global.myvar;

    will define the variable, and then from then on, we don't refer to it with the _global, but just by it's name (in my case, myvar). although in this case, it sounds like you just needed to target the right timeline (_parent).

    cheers,

    bret
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    here's a new question sort of on topic with this thread:

    If I set a variable at the root level of the main movie, how do I reference that variable from a external movie that is brought in using the loadMovie() function?

    I have tried _parent._root.varName, _parent.scene.varName, etc... havn't been able to pick it up in the loaded swf.

    is this even possible?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    ok, figured this one out as well:

    _level0.varName
  14. #8
  15. No Profile Picture
    flash junkie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    CO, USA
    Posts
    172
    Rep Power
    12
    sure it's possible, it just depends on how you loaded the movie in. Let's say that you created a variable on your _root (or _level0 - same thing) timeline. so i say in the actions of my _root:

    //
    //
    myRootVar = "something";

    this.createEmptyMovieClip("loader_mc",1);
    loader_mc.loadMovie("myexternal.swf");
    //
    //

    This would mean that i loaded my external .swf into the movieclip "loader_mc" that is located on the _root timeline. of course, i'm not sure how or where you are loading in the external movie, but bear with me. Try putting this in the timeline of the external movie:

    trace(this);


    If you run the external movie on it's own, you will see "_level0" in your output. But try running your main movie; when the external movie loads into the loader_mc it's going to trace:

    _level0.loader_mc

    This means that in order to get to the _root to acces our root variable, all we have to do is go up one level (this code lies in our external movie):

    trace(_parent.myRootVar);

    now, this will trace the value of the root variable when it's loaded into your main movie. If you run the external movie on it's own, you'll get nothing, because the variable doesn't exist unless you declare it (obviously) and the only pace we've declared it is in our main movie.

    So, you had the right idea, instead of saying "_parent._root.myVar" you would only need to reference the _parent clip "_parent.varName". This is assuming that you are only one level from the _root timeline. If you have loaded the movie into a second or third level, you would just preceed your variable with that many more "_parent."s...:

    _root.createEmptyMovieClip("loader_mc",1);
    loader_mc.createEmptyMovieClip("secondLoader_mc",2);
    loader_mc.secondLoader_mc.loadMovie("external.swf");

    in order to access the _root from the external clip, you would need to say:

    _parent._parent.myVar

    or you could just take the direct path and say:

    _root.myVar
    or
    _level0.myVar

    i hope that helps.

    cheers,

    bret
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    bret,

    that was very helpful, thanks for your time. Hopefully you can assist me one more time...

    I have a movie clip that is nested several levels down. In that clip is a button with the following action:

    on (release) {
    _root.myVar="1";
    _root.gotoAndPlay("myNewScene", 1);
    }

    the desired effect is when the button is clicked we go back out to the main timeline and jump to the scene "myNewScene". However nothing happens at all. Am I referring to the wrong _root? The movie clip with the button is nested 3 clips deep into the main timeline.

    _root.myVar gets updated just fine, but I don't understand why it isn't going to the specified scene.

    thanks fer the help
  18. #10
  19. No Profile Picture
    flash junkie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    CO, USA
    Posts
    172
    Rep Power
    12
    sure, the reason is that you don't need to specify a timeline when you are telling flash to go to a scene. your code should look like:

    on (release) {
    _root.myVar="1";
    gotoAndPlay("myNewScene", 1);
    }

    And that should work...

    hope that helps

    bret
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    yeah, I tried that and it doesn't seem to work, it just replays the current movie that the button is in, within the main timeline of the current scene.

    Is there a way, when you test the movie, to have it display the path to a specific movie? So say I wanted to have it show me the path to the instance of the movie clip that held my buttons, which would be something like:

    main_movie >first_nested_movie >third_nested_movie >button

    thanks again for your time
  22. #12
  23. No Profile Picture
    flash junkie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    CO, USA
    Posts
    172
    Rep Power
    12
    hey, you could trace the path in the external movie by just putting :

    trace(this);

    in the timeline of your movie (the third nested movie). If all of your files are in the same folder, when you run your main file (test it in flash) the tracing will still be effective, and it will trace the path to the loaded movie.

    i wonder why that didn't work with the scene's though.. i tried it out even before i posted here. make sure that you have the scene name spelled right i guess...

    cheers,

    bret
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    it must have something to do with the way I have the movie clips set up...

    Never was able to jump to the new scene by specifying the scene name, but by giving the first frame of the new scene a frame label, I was able to specify that and jump to it.

    thanks for the tip on trace()
  26. #14
  27. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    1
    Rep Power
    0

    If I may...


    This is my first post, and it relates closely to the other posts in this thread. I

    I am having problem getting a variable to work when clicking on a button link to "Meet Marcus". Here's what I am doing.

    1) In my main timeline I am initialising a 'goThere' global variable:

    _global.goThere="here";

    This is in a frame script on frame 1. (There are only 3 frames in the main timeline, which sits parked on frame 3.)

    2) On a button in a loaded movie (loaded to level 10), I am setting the 'goThere' variable to "Marcus" like this:

    goThere = "Marcus";
    trace("goThere=" + goThere);
    trace(this);


    Traced output:
    goThere=Marcus
    _level10.btnMeetMarcus


    2) My button script loads another movie into level 10, replacing the current movie, and tries to pick up this variable, like this:

    trace(goThere);
    trace(this);

    Here's my traced output:
    goThere=here
    _level10


    As you can see, I am losing my variable which is returning to its default value. I have no idea why.

    If you can help, you'd make my day.

    Thanks
    Geoff

IMN logo majestic logo threadwatch logo seochat tools logo