Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts

    past a value from a variable to a flash file?

    I wish to know how i pass a value to a SWF file so i can tell the SWF file what folder to access for the photos.

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You can use Flashvars, or better yet use SWFObject to embed your files, which also makes it easy to send variables through Javascript.

    See my signature for a post about embedding Flash Properly.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i have been using a ready made SWF which uses a XML file with the local urls, not full, for the images it is showing.

    all works ok, but i would need to have the SWF and xml in each folder with the images.

    but would like to have the xml file maybe have another field to say what folder to take the images from.

    at present i have to use a static url www.site.com/images/ then the image names are placed after this from the xml file to get the images to show.

    how would i add the folder name to get the images from in the xml and then recode the action code to read this.

    i only know how to ready the xml file i have now just be reading and learning, but not know how i ready one field for this and the others for that.

    these are my xml and action scripts...

    a guess going by other XML file i have tried looking at to find out would i be right maybe in saying that the variable would go in the <images> tag ? say a variable called... 'imagefolder'

    <images dir="images/">

    reason i want to do this way is to allow my to have different folders like albums.

    Code:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <images>
        <pic>
            <image>./images/1.jpg</image>
            <caption>Kresge</caption>
        </pic>
        <pic>
            <image>./images/stata_2.jpg</image>
            <caption>Lobby</caption>
        </pic>
        <pic>
            <image>./images/3.jpg</image>
            <caption>Construction</caption>
        </pic>
        <pic>
            <image>./images/4.jpg</image>
            <caption>Dome</caption>
        </pic>
        <pic>
            <image>./images/5.jpg</image>
            <caption>Structure</caption>
        </pic>
    </images>
    Code:
    function loadXML(loaded) {
    	if (loaded) {
    		xmlNode = this.firstChild;
    		image = [];
    		description = [];
    		total = xmlNode.childNodes.length;
    		for (i=0; i<total; i++) {
    			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    		}
    		firstImage();
    	} else {
    		content = "file not loaded!";
    	}
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("images.xml");
    // ///////////////////////////////////
    listen = new Object();
    listen.onKeyDown = function() {
    	if (Key.getCode() == Key.LEFT) {
    		prevImage();
    	} else if (Key.getCode() == Key.RIGHT) {
    		nextImage();
    	}
    };
    Key.addListener(listen);
    previous_btn.onRelease = function() {
    	prevImage();
    };
    next_btn.onRelease = function() {
    	nextImage();
    };
    // ///////////////////////////////////
    p = 0;
    this.onEnterFrame = function() {
    	filesize = picture.getBytesTotal();
    	loaded = picture.getBytesLoaded();
    	preloader._visible = true;
    	if (loaded != filesize) {
    		preloader.preload_bar._xscale = 100*loaded/filesize;
    	} else {
    		preloader._visible = false;
    		if (picture._alpha<100) {
    			picture._alpha += 10;
    		}
    	}
    };
    function nextImage() {
    	if (p<(total-1)) {
    		p++;
    		if (loaded == filesize) {
    			picture._alpha = 0;
    			picture.loadMovie(image[p], 1);
    			desc_txt.text = description[p];
    			picture_num();
    		}
    	}
    }
    function prevImage() {
    	if (p>0) {
    		p--;
    		picture._alpha = 0;
    		picture.loadMovie(image[p], 1);
    		desc_txt.text = description[p];
    		picture_num();
    	}
    }
    function firstImage() {
    	if (loaded == filesize) {
    		picture._alpha = 0;
    		picture.loadMovie(image[0], 1);
    		desc_txt.text = description[0];
    		picture_num();
    	}
    }
    function picture_num() {
    	current_pos = p+1;
    	pos_txt.text = current_pos+" / "+total;
    }

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    So you want to have one swf to reuse, and have a folder full of galleries, each with an XML file right? What method do you have to select which folder/xml file should be loaded? By just putting another element in the XML file doesn't seem to help the situation, because the Flash is still only written to know where one XML file is...
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    ok i have the following PHP file which is used instead of a static XML file.

    the flash action script i gave above had one error i forgot about, the file name it reads to get the images locations it should read as images.php not the xml file.

    this file contains...

    Code:
    <?php echo('<?xml version="1.0" encoding="utf-8" standalone="yes"?>'); ?>
    <? $owner = "Daniel"; ?>
    <?php
    include("dbconfigfile.php");
    $xmls = @mysql_query("SELECT * FROM `photo_album_xmls` WHERE `owner` = '" . $owner . "'") or die(mysql_error());
    ?>
    
    <images>
    <?php
    while($rows=@mysql_fetch_array($xmls)){
    ?>
        <pic>
            <image>./photos%20of%20something/<?php echo($rows[url]);?></image>
            <caption><?php echo($rows[desc]);?></caption>
        </pic>
    <?php
    }
    ?>
    </images>
    i have to place the files in a static folder at the moment which will make life very difficult later on.

    i will allow each member to upload to their own folders within the 'images' folder.

    and use the variable 'owner' to contain the name of the folder to be viewed.

    this variable is used above to get the image names from the mysql DB but also need to have this somehow reused in the SWF file to then read the folder that will have the PHP (xml) file that will then get the images fromthe folder in the images folder that is called the name in the variable 'owner'

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Why not just set up one PHP file that you pass variables to (from a session or whatever) and then passes the correct folder/image settings to the SWF? No need for multiple PHP files, that just makes it harder.

    You can use the database as your folder structure, rather than using actual folders. So images can be anywhere as long as you index them in the database according to their owner, then your PHP can sort them and put the correct file paths into the XML.

    As far as I can tell this is the best concept rather than trying to pass variables to Flash, and more likely to be secure and easier to expand.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #7
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    at the moment the SWF file reason a file called 'images.php' which is in the home dir of the site.

    the images.php file is the file above i gave, this gets the info URL (which can be anywhere) and the description which belong to the 'owner' (gonna change this variable to 'album'

    the SWF is accessed via the same method as the images.php file it is also located in the home dir,

    the SWf is embeded in the page i have set to shoew the slideshow being in this case www.site.com/slideshow.swf

    when someone click the links in the menu it shows the photos main page with the photo album slideshow in the middle this is embeded using the SWF file in the home dir, but as the SWF file runs it is not getting the album name to use when it runs its AScript which in turn read the images.php (the XML file in my home dir) where all the image urls are got when the PHP script within the images.php runs, i need to pass a value from the photo album script page they view to pass a value for the link they clicked to be sent to the SWF it uses so the XML (images.php file can use this to get the details from the DB that are for that album that should be viewed.

  • #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I'm sorry, but most of the post was one sentence and I'm not able to understand what you mean. Perhaps it would be better to make a diagram of the data flow?

    Are you saying you start with a list of albums, and then want to pass the selected album name to the PHP file to draw up the right images for that album? Please be as clear as possible, and break it down so its not one large sentence.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #9
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    ok sorry..


    visitor visits site, click photos then click the album to view.

    URL clicked could be say, www.site.com/?ac=photos&album=jason

    my site then displays the photos page due to the ACtion being they want to view photos.
    and then in this page is the SWF file
    the SWF is viewed and the action script in the SWF reads the XML file called get_image_urls.php which runs a script to collect the info from the DB, the direct URL the album name, owner and the description and the photos are got from the folder which is called 'jason' using the 'album' variable.
    but i need to first get this variable 'album' to pass its value to the SWF file so it can be used in the get_image_urls.php script which will get the info to phrase in this XML file it is creating on the fly for the SWF file.


    just thinking about it now.

    what i need to do is...

    the photos page is a PHP file which reads the $_GET['album'] and also displays the SWF file
    i need to know how i get the SWF to know the content of the $_GET['album'] variable

  • #10
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Alright I think I got it, thanks for the clarification!

    Here is what I would do. Change your PHP file to output your XML like this

    Code:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <images album="albumvariablehere">
        <pic>
            <image>./images/1.jpg</image>
            <caption>Kresge</caption>
        </pic>
        <pic>
            <image>./images/stata_2.jpg</image>
            <caption>Lobby</caption>
        </pic>
        <pic>
            <image>./images/3.jpg</image>
            <caption>Construction</caption>
        </pic>
        <pic>
            <image>./images/4.jpg</image>
            <caption>Dome</caption>
        </pic>
        <pic>
            <image>./images/5.jpg</image>
            <caption>Structure</caption>
        </pic>
    </images>
    Then you can access it in Flash by this code, which sets a variable with the album information. Put this in the loading part of the code.

    Code:
    var album = xmlNode.attributes.album
    Then you should be able to have the album available.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #11
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    no will not work

    would have to have a seperate XML (PHP) file for each folder which will not work.

    all data is going to be stored in the DB and got back from it to be used when the SWF accesses the XML (php) file which is phrased for use by the SWF to show the images

  • #12
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I don't understand any of this thread then.

    You have one swf, it should be completely reusable because it should load the images via XML.

    You have one images.php file which should dynamically create any XML file based on certain variables passed by the URL.

    All of your data can be stored in the database, meaning you it doesn't matter where your files are or what folders they are in, just index the link in the database.

    Where do you need another folder/file? I don't get it...sorry.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #13
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    ok i have created a zip folder of all the file relating to this problem i have.

    hope this can solve what i would like to do.


    this is my DB structure
    Code:
    CREATE TABLE IF NOT EXISTS `photo_album_xmls` (
      `owner` text NOT NULL,
      `url` text NOT NULL,
      `desc` text NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `photo_album_xmls`
    --
    
    INSERT INTO `photo_album_xmls` (`owner`, `url`, `desc`) VALUES
    ('Daniel', 'daniel/Daniel%20-%2001.JPG', 'Daniel - 1 of 2'),
    ('Daniel', 'daniel/Daniel%20-%2002.JPG', 'Daniel - 2 of 2');

    the action script in the SWF is...
    Code:
    function loadXML(loaded) {
    	if (loaded) {
    		xmlNode = this.firstChild;
    		image = [];
    		description = [];
    		total = xmlNode.childNodes.length;
    		for (i=0; i<total; i++) {
    			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    		}
    		firstImage();
    	} else {
    		content = "file not loaded!";
    	}
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("photoalbum_get_image_urls.php");
    // ///////////////////////////////////
    listen = new Object();
    listen.onKeyDown = function() {
    	if (Key.getCode() == Key.LEFT) {
    		prevImage();
    	} else if (Key.getCode() == Key.RIGHT) {
    		nextImage();
    	}
    };
    Key.addListener(listen);
    previous_btn.onRelease = function() {
    	prevImage();
    };
    next_btn.onRelease = function() {
    	nextImage();
    };
    // ///////////////////////////////////
    p = 0;
    this.onEnterFrame = function() {
    	filesize = picture.getBytesTotal();
    	loaded = picture.getBytesLoaded();
    	preloader._visible = true;
    	if (loaded != filesize) {
    		preloader.preload_bar._xscale = 100*loaded/filesize;
    	} else {
    		preloader._visible = false;
    		if (picture._alpha<100) {
    			picture._alpha += 10;
    		}
    	}
    };
    setInterval( advanceNextImage, 15000 );
    function advanceNextImage() {
    if (p<(total-1)) {
    p++;
    }
    else {
    p = 0;
    }
    if (loaded == filesize) {
    picture._alpha = 0;
    picture.loadMovie(image[p], 1);
    desc_txt.text = description[p];
    picture_num();
    }
    }
    function nextImage() {
    	if (p<(total-1)) {
    		p++;
    		if (loaded == filesize) {
    			picture._alpha = 0;
    			picture.loadMovie(image[p], 1);
    			desc_txt.text = description[p];
    			picture_num();
    		}
    	}
    }
    function prevImage() {
    	if (p>0) {
    		p--;
    		picture._alpha = 0;
    		picture.loadMovie(image[p], 1);
    		desc_txt.text = description[p];
    		picture_num();
    	}
    }
    function firstImage() {
    	if (loaded == filesize) {
    		picture._alpha = 0;
    		picture.loadMovie(image[0], 1);
    		desc_txt.text = description[0];
    		picture_num();
    	}
    }
    function picture_num() {
    	current_pos = p+1;
    	pos_txt.text = current_pos+" / "+total;
    }

    Code:
    <?
    if (stripstring($_GET[i]) == "daniel") {
    $owner = "daniel";
    } else {
    		?>show default<?
    		}
    
    
    if ($owner != "") {
    ?>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="670" height="670">
      <param name="movie" value="photoalbum_show_imagesV2aANY.swf">
      <param name=quality value=high>
      <embed src="./photoalbum_show_imagesV2aANY.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="670" height="670"></embed> 
    </object>
    <?
    }
    ?>
    Attached Files Attached Files
    Last edited by jasonc310771; 12-04-2008 at 11:22 PM.

  • #14
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    So you need to take a variable from HTML, pass it to Flash, pass it to PHP to grab the right XML?

    Use SWFObject, flashvars, and it allows you to pass that PHP value through the HTML page to Flash. There is a post about SWFObject in my signature called How to Embed Flash. Then you would just need to pass that variable along to PHP from Flash. Lets say it was called 'album'

    Embed Code

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
      <head>
        <title>SWFObject Example</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script type="text/javascript" src="swfobject.js"></script>
    
        <script type="text/javascript">
        swfobject.registerObject("swfplaceholder", "9.0.0", "expressInstall.swf"); // First parameter: name of Object ID, Second parameter: Minimum Flash version, Third Parameter: 
        </script>
    
      </head>
      <body>
        <div>
    
          <object id="swfplaceholder" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="780" height="420">
            <param name="flashvars" value="album=<?php echo $_GET[i]; ?>" />
            <param name="movie" value="swfFile.swf" />
            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="swfFile.swf" width="780" height="420">
            <!--<![endif]-->
              <p>Alternative content</p>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
          </object>
        </div>
      </body>
    </html>
    Flash Code Change
    Code:
    xmlData.load("photoalbum_get_image_urls.php?album="+album);
    Then your PHP XML file needs to grab this variable and process it

    Code:
    <?php echo('<?xml version="1.0" encoding="utf-8" standalone="yes"?>'); ?>
    <? $owner = $_GET[i]; ?>
    <?php
    include("dbconfigfile.php");
    $xmls = @mysql_query("SELECT * FROM `photo_album_xmls` WHERE `owner` = '" . $owner . "'") or die(mysql_error());
    ?>
    
    <images>
    <?php
    while($rows=@mysql_fetch_array($xmls)){
    ?>
        <pic>
            <image>./photos%20of%20something/<?php echo($rows[url]);?></image>
            <caption><?php echo($rows[desc]);?></caption>
        </pic>
    <?php
    }
    ?>
    </images>
    Have I helped here?
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.


  •  

    Posting Permissions

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