Pass a File Name as a Variable in to a Flash Object

Posted on 2004-11-23
Last Modified: 2012-06-21
I have a simple flash object that has an image (let's say a simple jpg file) and buttons to move, zoom in and zoom out.  I would like this object to be the basis for a web-based image viewing system, but in order to do this, I want to be able to pass in an variable that contains a filename that then this file is loaded into my flash "movie".  Is this possible?  If so, how do you structure the Flash movie and create the HTML code?  I would expect the HTML code would look something like:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=",0,29,0" width="320" height="320">
  <param name="movie" value="myFlashMovie.fla">
      <param name="myFileNameVariable" value="/images/somefile.jpg">
Question by:bmccleary
    LVL 4

    Assisted Solution

    I bleieve it goes like you have but:

    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=",0,0,0" width="544" height="249" id=" helloWorld " align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="movie" value="helloWorld.swf" />
    <PARAM NAME=FlashVars VALUE="var1=Hello%20World">
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
    <embed src="helloWorld.swf" quality="high" bgcolor="#ffffff" width="544" height="249" name=" helloWorld " flashvars="var1=Hello%20World" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="" />

    notice how:
    <PARAM NAME=FlashVars VALUE="var1=Hello%20World">

    the name=FlashVars gets it into the flash movie. When u access var1 from within the actionscript you should get a "Hello World"

    LVL 16

    Accepted Solution


    The structure of Flash simply will be using the loader component

    You are using at least MX version, right?

    If it is then do use the following to make the image put inside your movie

    First of all, from the component window, drag the Loader to the stage, name it as jpeg_loader

    Second, apply the following code to the frame 1 main movie

    jpeg_loader.autoLoad = false;
    jpeg_loader.contentPath = myFileNameVariable;
    jpeg_loader.load ();

    Vicker :)
    LVL 9

    Expert Comment

    <PARAM NAME=movie VALUE=movie.swf?image=MyImage.jpg> <PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=><EMBED src=movie.swf?image=MyImage.jpg quality=high bgcolor=...... etc etc

    Notice: the above is not supported by all browsers!
    LVL 9

    Expert Comment

    This article gives in-depth description of getting variables in/out of flash. If you need to pass in a list of files, you might want to consider using an XML file. I have done similar things using ASP that, for example, dynamically generates an XML file containing the list of files in a folder on the server, then parsing that XML in flash, but anyway, here's the article:

    Author Comment

    I have Flash MX Version 6.0, but when ti look at the components section, there is no option for a Loader component.  Do I need Flash MX 2004 or am I missing something?  Can I use something other than a loader control?

    Author Comment

    Thanks for the info... it did require Flash MX 2004

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now