Skip to main content
April 11, 2008
Question

Flash and CF variables

  • April 11, 2008
  • 2 replies
  • 396 views
Hello everyone. I am pulling an xml file into a flash file but I want to take it a step further and make the path to the xml file dynamic. Can I do that with cfml and flash? I want to say

slides_xml.load("#current_user#_comments.xml");

Can I do that?
    This topic has been closed for replies.

    2 replies

    Inspiring
    April 13, 2008
    Hi,

    You're not rambling at all. Sorry if my previous post was not altogether clear. I believe I understand what you are trying to do and FlashVars is your answer.

    In your ActionScript, you would do this:
    // first setup the dynamically generated user
    var thisUser:String = user;
    var thisUserXML:String = " http://www.mysite.com/slideshow/" + thisUser + "_slides.xml";
    // now, call/load your XML document
    slides_xml = new XML();
    slides_xml.onLoad = startSlideShow;
    slides_xml.load(thisUserXML);
    slides_xml.ignoreWhite = true;

    In your HTML/CFML page, you need to send the required user information to the Flash file. This is where FlashVars comes in handy.

    Naturally, I do not know how you determine what "user" is on the site so that you can show the respective slides but, for now, I'll pretend it comes from a cookie.

    <!--- set a default user --->
    <cfparam name="user" default="craig" type="string"/>
    <cfif IsDefined("cookie.user")>
    <cfset user = Trim(cookie.user)/>
    </cfif>
    <html>
    <head>
    <title>My Slideshow</title>
    </head>
    <body>
    <!--- Now that the user's name is set (above), we're going to pass that to the Flash file. Of course, this is abbreviated code for the OBJECT and EMBED tags...and for that matter, you should use JavaScript to place a SWF file on a page (to get around Microsoft's inherent security restrictions in IE 6 and 7). --->
    <cfoutput>
    <object>
    <param name="FlashVars" value="thisUser=#user#"/>
    <embed flashvars="thisUser=#user#"/>
    </object>
    </cfoutput>
    </body>
    </html>

    The CFML/HTML page passes in a user value (in this example, the string craig) to the SWF file. The ActionScript statements at the top of my reply would first set the string variable thisUser to have a value of "craig". Then, we build the custom XML path (thisUserXML), which would be http://www.mysite.com/slideshow/craig_slides.xml.

    Finally, the ActionScript code would load the data from this custom URL and call your startSlideShow function when complete.

    Hope this helps,
    Craig
    Inspiring
    April 12, 2008
    Hello,

    You cannot use ColdFusion directly in your Flash movie/ActionScript code. You can, however, utilize FlashVars in your HTML code that calls/sets the Flash Object (SWF).

    This involves passing data into your Flash movie in name/value pairs (like passing variables in the URL) from the HTML markup. In your Flash movie, you can then read the variable's data where relevant.

    In the HTML, you can use ColdFusion to set the desired variable and value. It's something like:
    <cfset user = "activeUser" />
    <cfoutput>
    <object blah blah blah>
    <param name="FlashVars" value="currUser=#user#" />
    </object>
    </cfoutput>

    You then receive a variable called currUser in your ActionScript and could do something along the lines of:
    var theUser:String = currUser + "_comments.xml";
    slides_xml.load(theUser);

    Each time the Flash movie is loaded, you can send in a custom user value based on whatever routines you use to establish the user.

    Here's a link to an Adobe Knowledge Base article on using FlashVars:
    http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_16417&sliceId=1

    Hope that helps!
    Craig
    April 12, 2008
    Ok I think we are headed down the right path but that post was still a bit over my head. What I really want to do is give each user their own movie so they can put it on their blog. The problem with that is that final movie has to have a hardcoded path inside flash to call their own xml file. Right?

    The way I'm seeing this is that I give each person their own movie and it will pull in their slides. I am close but am missing something. Here is what I currently have in my flash movie that shows all slides...

    slides_xml = new XML();
    slides_xml.onLoad = startSlideShow;
    slides_xml.load(" http://www.mysite.com/slideshow/slides.xml");
    slides_xml.ignoreWhite = true;

    But what I want to do is something like this for many users...

    slides_xml = new XML();
    slides_xml.onLoad = startSlideShow;
    slides_xml.load(" http://www.mysite.com/slideshow/#users#_slides.xml");
    slides_xml.ignoreWhite = true;

    So I think you are getting me there but I am still missing a piece of the puzzle. I want to have it so the movie is created once, and pulls in a unique xml file without me having to create a new movie for each person.

    Am I rambling?