SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing variables to Flash 5?

    When you mouseover a section in my nav, the color of the clip will change, let's say to orange. When you click, a new HTML page will load and the navigation would then default back to it's normal "off" state, with a color of "blue". Orange is the "on" color, blue is the "off" color. What I want to do is to make the orange color "sticky". Meaning that the navigation would stay orange even after a new page has loaded.

    This SHOULD be possible, but I'm not sure how I would go about doing it. I'm not using frames or it would be fairly easy. I'm thinking about putting a "nav=orange" on the end of each link on my site. I'm hoping that I can somehow pass that variable into Flash which would then know to "make orange the default color" for the selected page instead of the normal blue color. I would use this method for each different color that I wanted to make "sticky".

    Does that make sense at all? Can someone point me in the right direction, either with code or a link to code?

    Flux...hook me up!
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi creole, this is indeed possible, you just have to add the parameters to the OBJECT & EMBED Tags of your html page. in this example I'm passing a variable ARIABLE with valu VALUE to my swf:

    Code:
    <object id=intro width=600 height=450>
      <param name=movie value="intro.swf?VARIABLE="VALUE">
      <param name=quality value=high>
      <param name=bgcolor value=#666666>
      <embed src="intro.swf?VARIABLE="VALUE" quality=high  
            bgcolor=#666666 width=600 height=450
            type="application/x-shockwave-flash" 
            pluginspage="http://www....ion=ShockwaveFlash">
      </embed>
    </object>
    Only make sure you add the variable to BOTH tags (object & embed). The variable will be declared on the main timeline of (_level0)

    Now of course this is still quite static...you cannot change the value of the variable as it is hardcoded into the HTML file....that's why I like to use a server side script (php, ASP, ColdFusion) that enters the right variable/value combination when the page is being called:

    let the php fill in the supplied arguments in the right place:

    mypage.php?variablename='color'&value='green'

    hope this helps.
    Last edited by flux; Feb 4, 2002 at 03:38.

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Flux...

    that's great. This idea is one of the mockups I have for a client. I don't know if they'll go for this one or not but I wanted to ask ahead of time.

    I do have one question though...

    Couldn't I just say this in the query string:

    mypage.php?nav=green

    Then in the OBJECT and EMBED tags I would simpyl set it up like so:
    <object id=intro width=600 height=450>
    <param name=movie value="intro.swf?NAV="VALUE">
    <param name=quality value=high>
    <param name=bgcolor value=#666666>
    <embed src="intro.swf?NAV="VALUE"" quality=high
    bgcolor=#666666 width=600 height=450
    type="application/x-shockwave-flash"
    pluginspage="http://www....ion=ShockwaveFlash">
    </embed>
    </object>

    Or am I misunderstanding the way it works?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  4. #4
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by creole
    Flux...

    that's great. This idea is one of the mockups I have for a client. I don't know if they'll go for this one or not but I wanted to ask ahead of time.

    I do have one question though...

    Couldn't I just say this in the query string:

    mypage.php?nav=green

    Then in the OBJECT and EMBED tags I would simpyl set it up like so:
    <object id=intro width=600 height=450>
    <param name=movie value="intro.swf?NAV="VALUE">
    <param name=quality value=high>
    <param name=bgcolor value=#666666>
    <embed src="intro.swf?NAV="VALUE"" quality=high
    bgcolor=#666666 width=600 height=450
    type="application/x-shockwave-flash"
    pluginspage="http://www....ion=ShockwaveFlash">
    </embed>
    </object>

    Or am I misunderstanding the way it works?
    I don't think that's exactly how it should be...if you call mypage.php?color="green"

    you'll need this kind of code (not 100% about the syntax though):

    Code:
    ...
    <object id=intro width=600 height=450>
      <param name=movie value='intro.swf?NAV=<%php echo $color; %> >....
    so the php should output the passed parameter (in this case color) at the right place in the html code. so the actual html would look like this:

    Code:
    ...
    <object id=intro width=600 height=450>
      <param name=movie value='intro.swf?NAV=green>....

  5. #5
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That sounds like what I want. Basically, I would have 5 nav sections. Each nav section would have a color associated with the rollover. Each section of the nav would of course take you to a different section of the site which would use that color for accent purposes. I thought that it would be cool for Flash to keep that color when that section is chosen.

    So the query string would read:

    page.php?nav=news

    or

    page.php?nav=tour

    Flash would "know" that if nav=tour then make the default color of the MC orange. If nav=news then the default color would be green and so on.

    You understand what I mean?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  6. #6
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    perfectly...in flash imo the most beautiful way to do this is by making the background a movie clip symbol and attaching a Color Object to it...


    Code:
    onClipEvent (load) {
    
    //these are all the colors we're going to use
    
    color1=0x993366;  
    color2=0x333366;
    color3=0x996666;
    color4=0x999966;
    color5=0x003366;
    
    //defines a new color
    
    backgroundColor = new Color(this)
    
    //sets the color to color + parameter i (passed by script)
    
    backgroundColor.setRGB(eval("color"+ _root.i));
    
    }
    this code firstly defines a new Color Object and attaches it to the moveiclip:
    backgroundColor = new Color(this)

    then it sets the color of the movieclip equal to the value of the variable that is the combination "color"+_root.i

    backgroundColor.setRGB(eval("color"+ _root.i));

    _root.i is the variable "i" passed by the (php) script and defined on the main timeline (_root).

  7. #7
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the query string read:

    nav=green

    then "i" could be replaced with "nav" in your example above?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  8. #8
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK...

    I've got a better idea. Let's say that I break my navigation SWF into scenes (we'll say 2 for now). "Home" (the regular "off" state) and News. When you rollover the text that says "news" your SWF moves to the scene which contains "news" elements. When you roll off of "news" the nav reverts to "home".

    Would it be easier (than the above way) to tell the SWF to default to "news" if the variable is set in the query string? The code could look something like this:

    if (nav==news) {
    &nbsp;&nbsp;&nbsp;&nbsp;gotoAndPlay ("news");
    }

    That code would be in the very first frame in the "home" scene. Would that work, or something like it? Would it be easier than your other suggestion?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  9. #9
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by creole
    If the query string read:
    nav=green
    then "i" could be replaced with "nav" in your example above?
    no, you would need to pass e.g. i=1 (or i=2 or i=3...) to the swf, and then it would know it needs to make the background color+i = color1 (because i gets substituted with its value) = 0x993366

  10. #10
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by creole
    OK...

    I've got a better idea. Let's say that I break my navigation SWF into scenes (we'll say 2 for now). "Home" (the regular "off" state) and News. When you rollover the text that says "news" your SWF moves to the scene which contains "news" elements. When you roll off of "news" the nav reverts to "home".

    Would it be easier (than the above way) to tell the SWF to default to "news" if the variable is set in the query string? The code could look something like this:

    if (nav==news) {
    &nbsp;&nbsp;&nbsp;&nbsp;gotoAndPlay ("news");
    }

    That code would be in the very first frame in the "home" scene. Would that work, or something like it? Would it be easier than your other suggestion?
    it might be a bit easier, but it looks so much uglier...I never use scenes (except maybe for a preloader).

    if (nav==news) {
    &nbsp;&nbsp;&nbsp;&nbsp;gotoAndPlay ("news");
    }

    this code is good, but I wouldn't use it to jump form scene to scene. Why don't you make a ("background") movieclip with different labels (e.g. green, yellow, red, blue,...) and use the above code to jump to the right label (and thus display the right background color)?

    if (nav=="green") {
    &nbsp;&nbsp;&nbsp;&nbsp;_root.background.gotoAndStop ("green");
    if (nav=="red"){
    &nbsp;&nbsp&nbsp;&nbsp;_root.background.gotoAndStop ("red");
    if (nav=="yellow") {
    &nbsp;&nbsp;&nbsp;&nbsp;_root.background.gotoAndStop ("yellow");
    }

    with this code, you can pass "nav=green" to the swf as a parameter.

  11. #11
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll think about that. I like attractive code, but easier code is better for me. If I can have both then of course that would be the best.

    Let me see if I can explain better. Maybe there's a way of doing this that I'm not thinking of.

    Let's say my nav looks like this:
    Code:
    _____________________________________
    |  home    |  news      |   tour    |
    -------------------------------------
    The normal color of each item in the menu is a slightly transparent blue. When you roll over each item, the button itself turns a solid color and the whole menu turns a transparent shade of that color:

    home=green
    news=orange
    tour=red

    So when you mouse over home, the whole menu turns transparent green with the actual button being a solid color. I was planning on using scenes for each rollover state. I would have the default scene in which the whole menu would be "off" (transparent blue). Then a news scene in which the menu would be transparent orange with the news button filled in. So all my code would do would be to tell the "default" to be whatever scene was passed as the variable.

    So, do my questions make more sense? Is there a "better way"? Am I making this far too difficult? You're much more skilled at Flash than I am.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  12. #12
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Creole,

    You're lucky my boss is out for the day

    is this what you mean? this php needs to have a parameter baseColor=(hexadecimal colorvalue) passed to it. The first time lightblue (00ccff). when you rollover a button, the color is changed to a transparent version of the button color, and when you click, the page is reloaded and displays the color of the pressed button.

    I've added some color transition code, but don't worry about it

    here you can see it working... (rightclick Save As for the PHP-code)
    http://www.flux-design.com/creole/cr...seColor=00ccff

    here's the .fla
    http://www.flux-design.com/creole/colortrans.fla

    how it works
    1. the PHP script uses the parameter "baseColor=00ccff" to edit the Object and Embed tags of the html in such a way that another parameter (FirstHEX=00ccff) is passed to the SWF (do a view source in your browser to see this parameter).

    2. the background of the menu will use this parameter (FirstHEX=00ccff) to set its color.

    3. When you rollover a button, the color of the button is passed to the (semitransparent) menubackground. when the mouse rolls out of the button, the initial color (FirstHEX) is, again, passed to the menubackground

    4. when a button is clicked, the color of that button is passed to the Php as a parameter ?baseColor=(hexvalue)

    5. repeat step 1.

  13. #13
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the (stripped) PHP code

    Code:
    <OBJECT>
      <PARAM NAME=movie VALUE="colortrans.swf?FirstHEX=<?php echo $baseColor ?>">
      <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF>
      <EMBED src="colortrans.swf?FirstHEX=<?php echo $baseColor ?>" quality=high bgcolor=#FFFFFF  WIDTH=550 HEIGHT=400>
      </EMBED>
    </OBJECT>

  14. #14
    Yugo full of anvils bronze trophy hillsy's Avatar
    Join Date
    May 2001
    Location
    :noitacoL
    Posts
    1,859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW Creole - this is also very easy in ColdFusion if you're using that

    In CF you'd pass the baseColor variable in the URL string e.g. blahblahblah.cfm?baseColor=00CCFF

    Then you'd reference it in the <param> value using #URL.baseColor# - something like:

    Code:
    <cfoutput>
    <OBJECT>
      <PARAM NAME=movie VALUE="colortrans.swf?FirstHEX=#URL.baseColor#">
      <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF>
      <EMBED src="colortrans.swf?FirstHEX=#URL.baseColor#" quality=high bgcolor=#FFFFFF  WIDTH=550 HEIGHT=400>
      </EMBED>
    </OBJECT>
    </cfoutput>
    There are some good articles on CF/Flash on the Macromedia site...
    that's me!
    Now A Pom. And a Plone Nut
    Broccoli Martinez Airpark

  15. #15
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by flux
    Hi Creole,

    You're lucky my boss is out for the day

    is this what you mean? this php needs to have a parameter baseColor=(hexadecimal colorvalue) passed to it. The first time lightblue (00ccff). when you rollover a button, the color is changed to a transparent version of the button color, and when you click, the page is reloaded and displays the color of the pressed button.

    I've added some color transition code, but don't worry about it

    here you can see it working... (rightclick Save As for the PHP-code)
    http://www.flux-design.com/creole/cr...seColor=00ccff

    here's the .fla
    http://www.flux-design.com/creole/colortrans.fla

    how it works
    1. the PHP script uses the parameter "baseColor=00ccff" to edit the Object and Embed tags of the html in such a way that another parameter (FirstHEX=00ccff) is passed to the SWF (do a view source in your browser to see this parameter).

    2. the background of the menu will use this parameter (FirstHEX=00ccff) to set its color.

    3. When you rollover a button, the color of the button is passed to the (semitransparent) menubackground. when the mouse rolls out of the button, the initial color (FirstHEX) is, again, passed to the menubackground

    4. when a button is clicked, the color of that button is passed to the Php as a parameter ?baseColor=(hexvalue)

    5. repeat step 1.
    FLUX RULES
    That's almost EXACTLY what I wanted. The only thing that I had in my head is that not only does the transparent color "stick" but so does the solid color button.

    I was planning on doing this one myself, but since you've been SOOO kind, I'll gladly use this code.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  16. #16
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do have another question. This is a small item, but I'd like to pass a letter instead of a hex value.

    The menu will be set up using letters instead of the full name of the section like so:

    b = biography
    n = news
    t = tour

    In the code (I haven't looked at it yet but I will), can I put some sort of translation table like so:

    b = ff3300
    n = 33ccaa
    t = 0000ff

    I want that part of the query string to be very small like so:

    ?nav=b
    ?nav=n
    ?nav=t

    Where could I put that "translation" code? Would it go in the FLA or the PHP page?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  17. #17
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by creole
    Where could I put that "translation" code? Would it go in the FLA or the PHP page?
    It's up to you...it doesn't really matter, as long as it's done before the color is set...I personally would put it in the fla..I usually reserve the first frame of my movie for these initialisation variables. Then again, you might also consider it to put the code iun the PHP, so you can change colors without having to reopen the Flash file all the time...

  18. #18
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great...

    And thanks again for your help. It's people with your attitude that make SP successful.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  19. #19
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by creole
    Great...

    And thanks again for your help. It's people with your attitude that make SP successful.
    thanks creole...that's why we're here.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •