Reply to this topic Start new topic

 Flash accessing external files
MKayHavoc
post Mar 28 2006, 09:17 AM
Post #1


Young Padawan
*

Group: Members
Posts: 25
Joined: 13-March 06
Member No.: 16,929



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
Go to the top of the page
 
DarkSuiyoken
post Mar 28 2006, 06:36 PM
Post #2


Young Padawan
*

Group: Members
Posts: 63
Joined: 9-February 06
Member No.: 16,026



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:
CODE
&thumbs=blackandwhitethumb.jpg<|>blackandwhitethumb.jpg&


Then, using loadVars, load it inside your flash file. Here is the code:
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!

This post has been edited by DarkSuiyoken: Mar 28 2006, 06:52 PM
Go to the top of the page
 
MKayHavoc
post Mar 29 2006, 04:38 AM
Post #3


Young Padawan
*

Group: Members
Posts: 25
Joined: 13-March 06
Member No.: 16,929



That's very helpful. Thank you very much. :-)
Go to the top of the page
 
MKayHavoc
post Apr 4 2006, 01:06 PM
Post #4


Young Padawan
*

Group: Members
Posts: 25
Joined: 13-March 06
Member No.: 16,929



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.
Go to the top of the page
 
funkysoul
post Apr 4 2006, 02:09 PM
Post #5


The Funky Stuff
****

Group: Publishing Betazoids
Posts: 2,307
Joined: 21-February 05
From: Zurich, Switzerland
Member No.: 3,327



then you need to use a PHP system which outputs an XML or a txt file which is then linked to the swf..
Go to the top of the page
 
Chaos_Blader
post Apr 4 2006, 05:04 PM
Post #6


Young Padawan
*

Group: Members
Posts: 18
Joined: 28-July 05
Member No.: 9,180



QUOTE(MKayHavoc @ Apr 4 2006, 06: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.



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...
}
};
Go to the top of the page
 

Reply to this topic Start new topic
Forum Options & Statistics
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 9th February 2010 - 02:56 PM
Pixel2Life Home Advanced Search Get Started Credit Corner Get Started Credit Corner Forum Options The P2L Staff Top Overall Posters Top Today Posters Today Active Topics