Jump to content


Flash accessing external files


  • You cannot reply to this topic
5 replies to this topic

#1 MKayHavoc

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 28 March 2006 - 09:17 AM

Hi,

I've creating a photo gallery in flash, and I'm wanting to have it so that it loads files as follows:

gallery\image\image(x).jpg - the full size image at 750x750.
gallery\thumb\thumb(x).jpg - the thumbnail image at 75x75.
gallery\caption\caption(x).txt - the caption for the image.

I'm wanting to create a loop within the ActiveScript that will load pictures into the gallery until there are no more files left. So that all someone has to do is add files to the folders and they will just appear in the gallery.

1, Is this possible?
2, Whats the code?

Cheers

MkayHavoc

#2 DarkSuiyoken

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 28 March 2006 - 06:36 PM

Yes, that is definitely possible.

What you need to do is first create a text file with all the filenames of your images or your captions seperated with seperators.
A short example is here:
&thumbs=blackandwhitethumb.jpg<|>blackandwhitethumb.jpg&

Then, using loadVars, load it inside your flash file. Here is the code:
thumbs_lv.onLoad = function(success) {
	if (success) {
		trace("loadedVars");
		loadImages();
	}
};
depth=100
thumbs_lv.load("data.txt");

Notice that loadImages() is actually a function. This is where you parse the text file and also do all the main stuff like loading the images into a grid.

I will just paste the code here and try to comment each line for you to let you see what each line does:

function loadImages() {
//this line splits the text file by deleting all the "<|>" and what is left seperated by those things leaves you ONE array item.
thumbs_array = thumbs_lv.thumbs.split("<|>");
//calling this to make the total number of images in the array a variable.
maxnum = thumbs_array.length;
//this sets the number of columns you want.
col = 5;
//rows are actually set by the number of coloums of course and how to get that? simple math, total number of images divided by coloums!
rows = Math.ceil(maxnum/col);
limit = maxnum-1;
//spacing for the width
spacingi = 70;
//spacing for the height
spacingj = 85;
//counter to track the number of images
counter = 0;
for (var i = 0; i<=rows; i++) {
for (var j = 0; j<col; j++) {
//attaches the movie inside a movie clip named stage_mc. notice that depth plays an important role here as it is unique for every time a image is loaded due to the depth++ located below.
//mcThumb is a background for the image that will be loaded in.
stage_mc.attachMovie("mcThumb", "thumb"+depth+"_mc", depth);
var temp_mc = stage_mc["thumb"+depth+"_mc"];
trace(temp_mc);
temp_mc.fx = spacingi*j;
temp_mc.fy = spacingj*i;
temp_mc._x = temp_mc.fx;
temp_mc._y = temp_mc.fy;
temp_mc.empty_mc.createEmptyMovieClip("holder_mc", 1000);
temp_mc.empty_mc.holder_mc.loadMovie("data/images/"+thumbs_array[counter]);
//this unloads the movie if it has loaded all of them.
temp_mc.date_txt.text = date_array[counter];
if (counter>limit) {
temp_mc.unloadMovie();
}
counter++;
depth++;
}
}
}


Now this is just a very rough guide to explain how it all works, i don't really have time to explain all in detail as I promised earlier. This whole chunk already took me some time, so I hope you at least get the idea how it works. =x.

if anyone has the time to explain it to him, please feel free to, thanks!

Edited by DarkSuiyoken, 28 March 2006 - 06:52 PM.


#3 MKayHavoc

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 29 March 2006 - 04:38 AM

That's very helpful. Thank you very much. :-)

#4 MKayHavoc

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 04 April 2006 - 01:06 PM

Instead of having a file which you have to update everytime you add a new picture. Is there a way to write this into the actual Flash file?

Code that loops within the file and stops when there are no more files left? I'd like people to be able to just add the images and not have to update the file.

#5 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 04 April 2006 - 02:09 PM

then you need to use a PHP system which outputs an XML or a txt file which is then linked to the swf..

#6 Chaos_Blader

    Young Padawan

  • Members
  • Pip
  • 18 posts

Posted 04 April 2006 - 05:04 PM

View PostMKayHavoc, on Apr 4 2006, 06:06 PM, said:

Instead of having a file which you have to update everytime you add a new picture. Is there a way to write this into the actual Flash file?

Code that loops within the file and stops when there are no more files left? I'd like people to be able to just add the images and not have to update the file.


This code is coded in PHP 5

You cannot "search" directories within Flash,

<?php
header("Content-type:text/xml");
echo "<images>"
$images = scandir("path/to/images")
foreach($image as $images) {
if ($image != "." && $image != "..") {
ehco "<image link=\"www.mysite.com/path/to/images".$image."\" />";
}
}
echo "</image>";
?>

in Flash to get the XML Data

var imagesXML:XML = new XML();
imagesXML.ignoreWhite = true;
imagesXML.load("images.php");
imagesXML.onLoad = function() {
for (var info = imagesXML.firstChild.firstChild; info != null; info = info.nextSibling) {
linkToImage = info.attibutes.link
// Your code to add it to your gallery...
}
};





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users