6 Replies Latest reply on Sep 14, 2007 3:40 PM by phej2

    Using variables to go to a section of a swf

      I have been working on a project that I finally realized could have been, and will be, easier if I used variables within my AS. So I came home this evening and started working on my idea and after several hours of it not working, working part way, and googling like mad I decided to try you all. I hope you can help.

      The site I'm working on I've actually split up into multiple swfs for easier maintenance and I'm using one container swf to load everything in. The problem I have is that there is a "past" section where the user can select a year and view everything about the company that happened in that year (containing text, links to photos, sometimes video, etc.).

      So the past section is loaded into level 1 and when the user clicks on a year I'm creating a variable called year given the value of that year (2007, 1984, etc). The year button also unloads the past section swf and loads another swf in level 1. I have some actionscript at the beginning of that swf that says

      if (year=2007) {
      } else if (year=2006) {

      For each year I'll have some links, more buttons, and/or video come in and there's also a button to go back to the past section. One of my problems is that it always goes to the frame labelled "2007". I did get it to go to 2006 once, but I was using two if statements instead of the if and else if. The second problem is that when the user clicks back to the past section I need to empty out the variable so that they can choose another year and pass that variable.

      Can anyone offer any advice, suggestions or examples?

        • 1. Using variables to go to a section of a swf
          michaeltowse Level 1
          You are using the assignment function by using a simple equals sign. Use two equals signs to make a comparison between variables.

          • 2. Using variables to go to a section of a swf
            I have been having a similar problem, and being quite new to Flash, I'm at a loss on how to fix it. My issue is with a template I purchased. This template has the main content pages nested a couple layers deep. I need to be able to send people to a specific URL that I'm hoping to get to load the movie and bring up the one specific clip and not the main start.

            I had tried using a dynamic text field to check if the variables I was passing in through the URL were making it in (with the correct code placed in the embed and object tags). I gave the var box of the dynamic text the name of the variable I was passing in: showPage.

            This is what was displayed in the text box instead:


            Can I glean any information as to how to get this one clip to be bookmarked? I have tried by passing in variables and also by setting a Named Anchor in the key frame that loads this clip. That code worked only as far as putting the NA in the url like it was supposed to, but the actual link when pasted back in the browser brought you back to the main start.
            • 3. Re: Using variables to go to a section of a swf
              Level 7
              I don't think you can actually use numbers as frame labels. If I label a
              frame "2007" and then do a gotoAndPlay("2007"); it doesn't work. So, I'd
              label them like "y2007", "y2004", etc. Then you can just do: gotoAndPlay("y"
              + year);

              Dave -
              Head Developer
              Adobe Community Expert

              • 4. Re: Using variables to go to a section of a swf
                phej2 Level 1
                michaeltowse, thanks for the reply. I tried that but it didn't seem to work, but I think that's because I didn't explain myself clearly.

                Right now I have a past.swf that has links to all the years. Each button assigns a value to 'year', unloads past.swf and loads year.swf where all the content for each year is. At the beginning of year.swf I have the actionscript that looks for the value of year and if it's 2007, goes to the frame labeled 2007, that content should then be displayed.

                The problems are that year.swf isn't properly determining the year and when the user click 'back to past' year.swf is unloaded andI need to delete the value within 'year' so that they can pick a new one.

                Thanks for your help thus far, I hope this is clearer.
                • 5. Re: Using variables to go to a section of a swf
                  phej2 Level 1
                  DMennenoh, thanks for that info, that could be the reason.

                  I used to do a lot of AS back with 5, MX and MX2004 but then switched focus and have since lost a lot of my AS knowledge, but I'm trying to build it back up - starting with AS 2 of course (AS 3 looks scary).
                  • 6. Re: Using variables to go to a section of a swf
                    phej2 Level 1
                    Ok, I've been playing with michael's code suggestion for a while now and am still having problems, perhaps you could help me figure this out.

                    Right now I have several buttons in past.swf (loaded into level 1 by my container swf). Each button has this AS:

                    on (release) {
                    year = "2006";
                    loadMovieNum("year.swf", 1);

                    In the first frame of year.swf I have this AS:

                    if (year=="2007") {
                    } else if (year=="2006") {
                    } else {

                    As it is now, it loads year.swf and hits the stop action in frame 1. If I remove the double ='s it always goes to the frame labelled "y2007" and I'm at a loss.