?
Solved

Need Help Creating an Array in Flash

Posted on 2009-07-16
7
Medium Priority
?
273 Views
Last Modified: 2013-11-11
I have an older version of a Flash photo gallery (Flash 8/Action Script 1).  I'm using Flash CS3 to edit the source FLA file on an Windows XP Dell PC.  The gallery uses an external XML file to populate the gallery.  The original XML calls for :
       <pic>
        <image>gallery/photo01_web.jpg</image>
        <thumbnail>gallery/photo01_thumb.jpg</thumbnail>
        <caption>Insert caption here</caption>
        </pic>
I want to add a 4th node so that the user can download a hi-res version of the photo.  The XML would now be:
        <pic>
        <image>gallery/photo01_web.jpg</image>
        <thumbnail>gallery/photo01_thumb.jpg</thumbnail>
        <caption>Insert caption here</caption>
        <original>gallery/hires/photo01_hires.jpg</original>
       </pic>

The download button works on the first image, but will not work on the second, third, etc. images in the gallery.  If I go back to the first image after clicking the other images, the download for the first image no longer works.

The AS1 is below.  Can someone help me with make the array work>
function initGallery() {
	function loadXML(loaded) {
		if (loaded) {
			xmlNode = this.firstChild;
			total = xmlNode.childNodes.length;
			for (i=0; i<total; i++) {
				_root.small_image[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
				_root.big_image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
				_root.description[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
				_root.original[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
				if (i == 0) {
					_root.loadGImage(_root.description[i],_root.big_image[i], _root.original[i]);
				}
				// end if   
				++_root.total_images;
			}// end of for
			createSmall();
			_root.downloadButton._visible = true;
		} else {
			content = "file not loaded!";
		}// end else if
	}// End of the function
	xmlData = new XML();
	xmlData.ignoreWhite = true;
	xmlData.onLoad = loadXML;
	if (_root.xml_file == undefined) {
		_root.xml_file = "images.xml";
	}
	// end if   
	xmlData.load(xml_file);
}// End of the function
function createSmall() {
	_root.smallContainer.createEmptyMovieClip("smallImageContainer",10);
	var _loc4 = 0;
	var _loc3 = 0;
	for (var _loc2 = 0; _loc2<_root.small_image.length; ++_loc2) {
		_root.smallContainer.imageContainer.attachMovie("smallImage","smallImage_"+_loc2,100+_loc2);
		m = _root.smallContainer.imageContainer["smallImage_"+_loc2];
		m._x = _loc3*50;
		m._y = 0;
		m.imageContainer.loadMovie(_root.small_image[_loc2],100);
		m.iData = Array();
		m.iData.big = _root.big_image[_loc2];
		m.iData.title = _root.description[_loc2];
		++_loc3;
	}// end of for
	_root.smallImageContainer._x = 5;
	_root.smallImageContainer._y = 0;
}// End of the function
function loadGImage(title, bigImgURL, originalURL) {
	_root.bigImage.imageContainer.loadMovie(bigImgURL,100);
	_root.bigImage.imageContainer._x = 0;
	_root.bigImage.imageContainer._y = 0;
	_root.title.text = title;
	_root.downloadButton.onRelease = function() {
		getURL(originalURL, "_blank");
	};
}// End of the function
function goFullScreen() {
	Stage.displayState = "fullScreen";
}// End of the function
function exitFullScreen() {
	Stage.displayState = "normal";
}// End of the function
function menuHandler(obj, menuObj) {
	if (Stage.displayState == "normal") {
		menuObj.customItems[0].enabled = true;
		menuObj.customItems[1].enabled = false;
	} else {
		menuObj.customItems[0].enabled = false;
		menuObj.customItems[1].enabled = true;
	}// end else if
}// End of the function
_root.description = new Array();
_root.small_image = new Array();
_root.big_image = new Array();
_root.original = new Array();
_root.total_images = 0;
initGallery();
var fullscreenCM = new ContextMenu(menuHandler);
fullscreenCM.hideBuiltInItems();
var fs = new ContextMenuItem("Go Full Screen", goFullScreen);
fullscreenCM.customItems.push(fs);
var xfs = new ContextMenuItem("Exit Full Screen", exitFullScreen);
fullscreenCM.customItems.push(xfs);
_root.menu = fullscreenCM;
downloadButton._visible = false;

Open in new window

0
Comment
Question by:dparker_alr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

by:dparker_alr
ID: 24871308
Increasing point value.
0
 
LVL 14

Expert Comment

by:TanLiHao
ID: 24876577
Post the .fla together with the .xml. I cannot be sure what is wrong with only the code shown.
0
 

Author Comment

by:dparker_alr
ID: 24878533
Thanks for hte help.  The EE system would not accept .FLA files for upload. I've posted them to the following location:  http://www.dfwserver.com/temp02
0
Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

 
LVL 14

Expert Comment

by:TanLiHao
ID: 24884757
I found your problem, and since I do not have the photos I could not really test out properly, but I'm quite sure this code will work.

I uploaded the .fla and renamed it as .fla.txt, so you rename the .fla back to .fla.

gallery071609.fla.txt
0
 

Author Comment

by:dparker_alr
ID: 24897530
Thank you so much, but there's a problem with opening the file.  I downloaded and renamed it, but Flash CS3 keeps giving me an "unexpected file format" error.  I think this EE upload system may have corrupted it.  Can you copy-and-paste the AS code?
0
 
LVL 14

Accepted Solution

by:
TanLiHao earned 1600 total points
ID: 24902087
As the code is really scattered here and there, yeah you originally coded it like this so I didn't change them, so it's rather difficult for me to show which code belongs where but I will try.

Anyway I think you are unable to open it because I accidentally saved it as flash cs4 format. So try the new flash file and if you still cannot, see the code snippet on how to edit your code.

// Frame 1 Code in Action Layer, replace with this
 
function initGallery() {
	function loadXML(loaded) {
		if (loaded) {
			xmlNode = this.firstChild;
			total = xmlNode.childNodes.length;
			for (i=0; i<total; i++) {
				_root.small_image[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
				_root.big_image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
				_root.description[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
				_root.original[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
				if (i == 0) {
					_root.loadGImage(_root.description[i],_root.big_image[i], _root.original[i]);
				}
				// end if   
				++_root.total_images;
			}// end of for
			createSmall();
			_root.downloadButton._visible = true;
		} else {
			content = "file not loaded!";
		}// end else if
	}// End of the function
	xmlData = new XML();
	xmlData.ignoreWhite = true;
	xmlData.onLoad = loadXML;
	if (_root.xml_file == undefined) {
		_root.xml_file = "images.xml";
	}
	// end if   
	xmlData.load(xml_file);
}// End of the function
function createSmall() {
	_root.smallContainer.createEmptyMovieClip("smallImageContainer",10);
	var _loc4 = 0;
	var _loc3 = 0;
	for (var _loc2 = 0; _loc2<_root.small_image.length; ++_loc2) {
		_root.smallContainer.imageContainer.attachMovie("smallImage","smallImage_"+_loc2,100+_loc2);
		m = _root.smallContainer.imageContainer["smallImage_"+_loc2];
		m._x = _loc3*50;
		m._y = 0;
		m.imageContainer.loadMovie(_root.small_image[_loc2],100);
		m.iData = Array();
		m.iData.big = _root.big_image[_loc2];
		m.iData.title = _root.description[_loc2];
		m.iData.originalURL = _root.original[_loc2];
		++_loc3;
	}// end of for
	_root.smallImageContainer._x = 5;
	_root.smallImageContainer._y = 0;
}// End of the function
function loadGImage(title, bigImgURL, originalURL) {
	_root.bigImage.imageContainer.loadMovie(bigImgURL,100);
	_root.bigImage.imageContainer._x = 0;
	_root.bigImage.imageContainer._y = 0;
	_root.title.text = title;
	_root.downloadButton.onRelease = function() {
		getURL(originalURL, "_blank");
	};
}// End of the function
function goFullScreen() {
	Stage.displayState = "fullScreen";
}// End of the function
function exitFullScreen() {
	Stage.displayState = "normal";
}// End of the function
function menuHandler(obj, menuObj) {
	if (Stage.displayState == "normal") {
		menuObj.customItems[0].enabled = true;
		menuObj.customItems[1].enabled = false;
	} else {
		menuObj.customItems[0].enabled = false;
		menuObj.customItems[1].enabled = true;
	}// end else if
}// End of the function
_root.description = new Array();
_root.small_image = new Array();
_root.big_image = new Array();
_root.original = new Array();
_root.total_images = 0;
initGallery();
var fullscreenCM = new ContextMenu(menuHandler);
fullscreenCM.hideBuiltInItems();
var fs = new ContextMenuItem("Go Full Screen", goFullScreen);
fullscreenCM.customItems.push(fs);
var xfs = new ContextMenuItem("Exit Full Screen", exitFullScreen);
fullscreenCM.customItems.push(xfs);
_root.menu = fullscreenCM;
downloadButton._visible = false;
 
// End frame 1 code
 
// go to library, search for sprite 5 (smallImage), double click it, go to the actions of the button, replace with this code
 
on (release)
{
    _root.loadGImage(iData.title, iData.big, iData.originalURL);
}
// end code

Open in new window

gallery071609.fla.txt
0
 

Author Closing Comment

by:dparker_alr
ID: 31604221
It works beautifully!  Thank you so very, very much.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
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.
Suggested Courses

765 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