dcsimg
A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: variables? gotoAndPlay

  1. #1
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273
    hey,

    i have a flash site that im trying to make. i have the homepage for the flash thing done. i have a menu, on the top of the movie, but its inside a movie clip, then inside a motion tween. what i want to do, is when another one of the buttons is clicked on, other then home of course, it will tell _root.Play so the main timeline will start playing, and the stuff for the homepage will fade out and junk, anyway, after that, i want to set up a variable in a frame action somethin like,

    gotoAndPlay (variable gotten from button in menu);

    is this possible to do. can i set up, in the main timeline the action gotoAndPlay (x) and then just tell the button _root.x = 12 or somethin. please help!

  2. #2
    Senior Member
    Join Date
    Jun 2001
    Posts
    2,943
    Inside your movie clip, and on the relevant button (assuming, for example, you want to play the main timeline from frame 1) use:
    Code:
    on(release){
    _root.gotoAndPlay(1);
    }
    Obviously, you can go and play from anywhere you want.

    If you wanted to control another clip's timeline (let's say it was on the main stage and had an instance name of 'clip2'), you would use:
    Code:
    on(release){
    _root.clip2.gotoAndPlay(1);
    }
    Or if clip2 was inside the current clip:
    Code:
    on(release){
    clip2.gotoAndPlay(1);
    }
    There are all kinds of obvious combinations that can result from this.

    Just remember that _root means 'the main timeline' and you can point anywhere you want.

  3. #3
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273

    yeah?

    ok,

    i know how to do that, i dont think my question was understood. what i want to do is set up a variable in the maintime line. once the button i clicked, and the maintimeline plays lets say 10 frames, in that tenth frame, i would put,
    Code:
    gotoAndPlay (x  <--a variable) ;
    im saying, can you set up a variable like this? then once one of the buttons is pushed, change the variable "x" to whatever i want, so it can link to the scene relevant to the button?


  4. #4
    Senior Member
    Join Date
    Jun 2001
    Posts
    2,943
    Yes.

    I'm not sure I've grasped exactly what you are trying to do, but if you have a variable in the main timeline and you have set it to 0 (say, var = 0 in frame 1), then you can change it using _root.var = newvalue anywhere you want.

    It depends on how you've built your movie, but as long as the variable isn't overwritten by anything else, you can change it ready for when the play head next passes over any action that needs it.

    Sorry if I misunderstood (or if I still am).

  5. #5
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273

    getting closer

    ok,

    were getting closer to solving this thing but since i have no idea how to set up the "var" action (variable). i was wondering if you could help me out on setting that up. ok, i want the action in frame 10. i understand how you were saying to change it, and that makes perfect sense, but i need help to set up the variable. would i put
    Code:
    new var = "scene";
    
    gotoAndPlay ("scene");
    or what? and then, when i put the action
    Code:
    _root.var = newvalue anywhere you want
    on the button, do i replace "newvalue anywhere etc." with a number? like the number of the scene? and would i replace var, in that action with the name of my new variable? mabye i need to do this step by step. sorry, ive NEVER done variables before.

  6. #6
    Senior Member
    Join Date
    Jun 2001
    Posts
    2,943
    Let's imagine a scenario:

    You have a button inside a movie clip. On the main timeline, you have an action that loads a clip into a conatiner. Under normal circumstances, it loads 'clip1.swf', but if the user has pressed that button, it loads 'clip2.swf' instead.

    This seems to be the kind of thing you are after.

    OK. In frame 1 of the timeline you want a variable that will be used to load 'clip1.swf':
    Code:
    filetoload = "clip1.swf";
    At some point in the movie - say, frame 10 - you load the clip into a container:
    Code:
    loadMovie(filetoload, container);
    Now, the play head passes over frame 10 repeatedly because of the way you designed your movie - but it never goes back to frame 1 unless you tell it to specifically.

    So, on the button inside your other clip you have:
    Code:
    on(release){
    _root.filetoload = "clip2.swf";
    }
    If you run this, and click the button, the next time the playhead passes frame 10, filetoload will now contain 'clip2.swf' instead of 'clip1.swf'.

    I think that addresses what you were asking - just a case of applying it to your specific movie.

  7. #7
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273

    Yes!!!!!!

    wow,

    you are definetly the man. thank you so much for the help. it took me a while to figure out what you were saying and how you were to do it. thank you for taking the time to help me. this will make it much easier for me to do. thanks again, and if you ever need a favor, just let me know, or e-mail me. c-ya.


    Jake

  8. #8
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273

    wait!!!

    ok,

    well the variable thing worked, but now the thing to change the variable wont work. in frame one i put
    Code:
    button = "load up, 1";
    and then in frame 10 i put
    Code:
    gotoAndPlay (button);
    once i had that done, on the buttons action, i put
    Code:
    on (release) {
        _root.button = "home, 1";
        _root.play();
        }
    when i click the button, it plays the maintime line, but it dosent seem to change the variable. it just takes it back the scene "load up". i dont get it?

  9. #9
    Senior Member
    Join Date
    Jun 2001
    Posts
    2,943
    I assume that 'load up, 1' is a frame label? It shouldn't matter, but I'd go for a simpler naming system. However...

    In your button code, try _root.gotoAndPlay(2) (or a specific frame number/label relevant to your movie.

    Make sure that the playhead passes through frame 10 and doesn't just get dropped on top of it.

    See if that works.

  10. #10
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273

    not working

    for some reason, the button cant tell the maintimeline to do much, i tried to tell it to tell the main time line to gotoAndPlay ("profiles" ,1) but it dosent work. it cant get through or somethin. it wont do anything. and profiles, is the name of a scene not a frame label. i moved the action onto frame 9 so that it would play through it if that was the problem but that didnt seem to affect much. i dont understand. i figured out that the variable in fact DIDNT work, i only thought it did, because it took me to the next scene. long story. ill upload the .fla and you can download it if you like, i think that might be easier. then you would know what i want. do you have a AIM or AOL screen name we can talk about this on? im confused

  11. #11

    Here's the clincher (I think)

    You can't hold two separate values in one variable, AND your variable "button" looks like a target to the "gotoAndPlay()" action.

    Your variable "button" can hold the name of the scene, and another one is going to have to hold the frame # if it won't always be the same.

    And just for saftey's sake let's try encapsulating your variable in these little guys [ ] so the gotoAndPlay() doesn't mistake it for a missing target and end up ignoring it.

    SO your frame 1 will look like this:
    Code:
    button = "SceneName"
    AND your frame 10 will look like this:
    Code:
    gotoAndPlay([_root.button],1)
    P.S.
    As Sualdam sudgests: keep your variable names and values simple. You souldn't be putting spaces and commas in variable names (of course) and only put them in the value if the're enclsed in quotes (of course). But a variable value enclosed in quotes has no REAL value in relation to controling the movie, it only can equal it's value in characters, if you get my drift.

    Ta

  12. #12
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273
    ok,

    well i tried putting the little [] things around it, and it said, that the Scene must be quoted string. this might mean somethin to you guys. i tried to just set up the variable, and not change it with the button, so i just set up on the first frame;
    Code:
    button = "Scene Name"
    and on the 10th frame i put

    Code:
    gotoAndPlay([_root.jumpto], 1);
    when i tested the movie, it came up with that quoted string error thing. i think were back to square one here. mabye a variable cant be used in a gotoAndPlay action? im not sure.

  13. #13
    Senior Member
    Join Date
    Jun 2001
    Posts
    2,943
    Bluedot, if you e-mail me I'll send you a demo file (well, three of them) that shows how to do it.

    You can do it, and exactly like I said - so don't worry.

    And as mani_sf mentioned, be careful with spaces in labels - if you accidentally type in an extra space, how would you know? It would be a nightmare to debug - even if it were allowed.

  14. #14
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273

    correction

    in the last post, i told you the action on my 10th frame wrong, it is,
    Code:
    gotoAndPlay([_root.button], 1);
    sorry

  15. #15
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273
    sualdam,

    did you get my e-mail or no?

  16. #16
    Senior Member
    Join Date
    Jun 2001
    Posts
    2,943
    Yes, and I sent the files - about 30 minutes ago.

  17. #17
    :: rolla :: bluedot's Avatar
    Join Date
    Mar 2001
    Location
    home
    Posts
    273

    i figured somethin out

    ok,

    this is what i got so far. i can make variables in my movie now. i can make them work for the gotoAndPlay when i put them in the code, BUT ONLY IF I USE THE VARIABLE AS THE FRAMES AND NOT AS THE SCENE. flash wont let you use an expression to state the frames. therefore your code has to be
    [code]
    gotoAndPlay (var1);
    where var1 is the variable that equals the frame you want
    [\code]

    ok, so i have that much, now, that works fine for linking to scenes ahed of the scene you are currently in, but not for scenes before. if my scene ends in 10 frames, and i put in the var1 = 11 , then instead of going to the 11th frame, it just goes to the first frame of the next scene, and so on. is there a way to only refer to frames, and not to scene whatsoever? if so please let me know.

    p.s. i think i got this thing now, this is 5 minutes after i wrote the above, instead of having different scenes for each different button, i just seperated each buttons contents by 10 frames, enabling me to take advantage of my new-found stuff (the above). thanks for all the help guys, i might need some more later, but for now, i think i got it.

    THANK YOU!!!!!!

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