I’m having trouble with this little image viewer which I’ve been working on as just sort of a learning exercise. What I would like to have happen is for a text area component to gently slide up or down to a set distance below each new image, triggered by clicking on items in a list. It seems like it ought to work, but for some reason I can only get the text to slide to the right position after two clicks on the same item in the list.
Any ideas?
import mx.transitions.Tween;
import mx.transitions.easing.*;
// populates arrays with XML attributes...
function parseXML(success:Boolean):Void {
if (success && this.status == 0) {
var theRoot:XMLNode = this.firstChild;
for (i=0; i<theRoot.childNodes.length; i++) {
title_array.push(theRoot.childNodes*.attributes.title);
description_array.push(theRoot.childNodes*.attributes.description);
picture_array.push(theRoot.childNodes*.attributes.picture);
myList.addItem(title_array*);
}
}
}
// supposed to fade in holder_mc alpha and slide desc_txt to a set distance below each new image loaded into holder_mc...
function fadeAndSlide() {
new Tween(holder_mc, "_alpha", Weak.easeIn, 0, 100, .4, true);
var moveT:Tween = new Tween(desc_txt, "_y", Weak.easeIn, desc_txt._y, holder_mc._height+25, .4, true);
}
// Creates an empty movie clip for each jpg image...
function createLoad() {
_root.createEmptyMovieClip("holder_mc", getNextHighestDepth());
holder_mc._x = 128;
holder_mc._y = 20;
loadMovie(picture_array[myList.selectedIndex], holder_mc);
fadeAndSlide();
}
// clicking on a list item displays image in holder_mc and text in description_txt
// uses the eventObj parameter
// to capture the event
function myHandler(eventObj:Object) {
if (eventObj.type == "change") {
desc_txt.text = description_array[myList.selectedIndex];
createLoad();
}
}
// creates list of items...
this.createClassObject(mx.controls.List, "myList", 1, {_x:20, _y:20});
//creates text area for descriptions of each item...
createClassObject(mx.controls.TextArea, "desc_txt", getNextHighestDepth(), {text:"description", _y:300, _x:128, _width:300, _height:50, wordWrap:true});
var title_array:Array = new Array();
var description_array:Array = new Array();
var picture_array:Array = new Array();
// creates XML object...
var book_xml:XML = new XML();
book_xml.ignoreWhite = true;
book_xml.load("slideViewer.xml");
book_xml.onLoad = parseXML;
var myList:mx.controls.List;
var myHandler:Function;
// Register the myHandler function with myList.
// When an item is selected (triggers the change event)
myList.addEventListener("change", myHandler);