Here is the link…
http://www.joedigital.tv/LAB/FlepStudio/ImagesScroller/main.html
Long term, the combobox will be populated from an SQL database. And XML files, will be added with a certain naming convention created via a PHP script, which will also link SQL database names with XML file names and locations.
The only code I have changed is in Main.as. My thought was I was going to have LoadingXML.as dynamically pull from a .txt file. And everytime a new “Item” was “selected” in the comboBox, flash would write URLvairables to that txt file, and then when LoadingXML was forced to UPDATE it would pull the myComboBox.selectedItem name , now stored in the txt file, and change what XML file it is opening.
I have tried this in a couple different ways, I can see that the problem lies in REFRESHING the Arrays, if I knew how to load “LoadingXML.as” fresh everytime a comboBox Item was selected, I would be done. But I don’t know how to removeChild so to speak the Arrays and finally how to call back up “loadImages()” and have it load LoadingXML fresh everytime. Where in LoadingXML I would place…
//Create the URLLOader instance
var myLoader:URLLoader = new URLLoader()
//the data will come as URL-encoded variables
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES
//Load using an URLRequest, even beeing local
myLoader.load(new URLRequest("refXML.txt"))
//onLoad handler listener
myLoader.addEventListener(Event.COMPLETE, onDataLoad)
//Error handling
myLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError)
myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError)
//Could be an error or just a message
myLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus)
//add a listener for the complete event
function onDataLoad(evt:Event){
Title_txt.htmlText = evt.target.data.Title
}
//error callbacks
function onIOError(evt:IOErrorEvent){
trace("IOError: "+evt.text)
}
function onHTTPStatus(evt:HTTPStatusEvent){
trace("HTTPStatus: "+evt.status)
}
function onSecurityError(evt:SecurityErrorEvent){
trace("SecurityError: "+evt.text)
}
stop()
and do something like this to the LoadingXML.as code
package
{
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.xml.*;
import flash.geom.ColorTransform;
public class LoadingXML extends XMLDocument
{
private var _fla:MovieClip;
public function LoadingXML(fla:MovieClip)
{
_fla=fla;
this.loadXML();
}
private function loadXML():void
{
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE,completeHandler);
// Cambia l'url del file XML
var request:URLRequest=new URLRequest(evt.target.data.Title + ".xml");
try
{
loader.load(request);//request);
}
catch(error:Error)
{
trace('Problem loading documents.');
}
}
private function completeHandler(event:Event):void
{
var loader:URLLoader=URLLoader(event.target);
var result:XML=new XML(loader.data);
var myXML:XMLDocument=new XMLDocument();
myXML.ignoreWhite=true;
myXML.parseXML(result.toXMLString());
var node:XMLNode=myXML.firstChild;
var n:int=int(node.childNodes.length);
for(var i:int=0;i<n;i++)
{
var obj:Object=new Object();
obj.image=node.childNodes*.attributes['source'];
obj.pop=node.childNodes*.attributes['popup'];
_fla.objects_array.push(obj);
}
_fla.loadImages();
}
}
}
Finally, here is the modified Main.as, as noted below this is a modification of Fleps work found below…
/*
*************************************
* Images Scroller
* http://www.FlepStudio.org
* © Author: Filippo Lughi
* version 1.0
*************************************
*/
package
{
//Mix - Slider and TextInput, FlepStudio
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Loader;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
//FlepStudio
import flash.events.TextEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.system.Security;
import fl.events.SliderEvent;
//ComboBox
import fl.controls.Button;
import fl.controls.ComboBox;
import fl.controls.List;
public class Main extends MovieClip
{
public var file_xml:LoadingXML;
public var objects_array:Array;
public var pics_array:Array;
public var container_mc:MovieClip;
public var gal_ctnr_mc:MovieClip;
public var gal_combo_ui:MovieClip;
private var counter:int=0;
private var ratio:Number;
private var speed:int=1;
private var boo:Boolean=true;
private var inputTextField:TextField = new TextField();
private var result:String = "";
public var tim:Timer = new Timer(50);
public var xInc:Number = 100;
public function Main()
{
Security.LOCAL_TRUSTED;
init();
loadXML();
configureListeners();
TextEvent_TEXT_INPUT();
galleryCombo();
}
private function init():void
{
stage.frameRate=31;
objects_array=new Array();
pics_array=new Array();
container_mc=new MovieClip();
addChild(container_mc);
gal_ctnr_mc=new MovieClip();
addChild(gal_ctnr_mc);
gal_combo_ui=new MovieClip();
addChild(gal_combo_ui);
}
private function loadXML():void
{
file_xml=new LoadingXML(this);
}
//ComboBox - Start
private function galleryCombo():void
{
var myComboBox:ComboBox = new ComboBox();
myComboBox.prompt = "Select an item";
myComboBox.addItem({label:"images"});
myComboBox.addItem({label:"Item B"});
myComboBox.addItem({label:"Item C"});
myComboBox.move(10, 10);
myComboBox.addEventListener(Event.CHANGE, clickHandler);
gal_combo_ui.addChild(myComboBox);
var myList:List = new List();
myList.rowCount = myList.length;
myList.selectable = false;
myList.move(myComboBox.x, myComboBox.y + myComboBox.height + 10);
gal_combo_ui.addChild(myList);
function clickHandler(event:Event):void
{
if (myComboBox.selectedIndex > -1)
{
configureListeners();
}
}
}
//ComboBox - End
//Sliders and InputText - Start
public function TextEvent_TEXT_INPUT()
{
inputTextField.x = 800;
inputTextField.y = 400;
inputTextField.border = true;
inputTextField.type = TextFieldType.INPUT;
inputTextField.addEventListener(TextEvent.TEXT_INPUT, textInputHandler);
this.addChild(inputTextField);
}
private function textInputHandler(event:TextEvent):void
{
var numExp:RegExp = /[0-9]/;
event.preventDefault();
inputTextField.text = result;
inputTextField.setSelection(result.length + 1, result.length + 1);
if (inputTextField.text.length == 1 || inputTextField.text.length == 2)
{
if(numExp.test(event.text) == true)
{
updateCombination(event.text);
}
else
{
sliderLabel.text = "input type numeric";
}
}
else
{
if(numExp.test(event.text) == true)
{
updateCombination(event.text);
}
else
{
sliderLabel.text = "input type numeric";
}
}
if(inputTextField.text.length == 2)
{
posX();
result="";
}
}
private function posX():void
{
sliderLabel.text = "";
gal_ctnr_mc.x = xInc + Number(inputTextField.text);
}
private function updateCombination(s:String):void
{
sliderLabel.text = "";
result += s;
inputTextField.text = result;
inputTextField.setSelection(result.length + 1, result.length + 1);
}
private function configureListeners():void
{
slider.addEventListener(SliderEvent.CHANGE, sliderChanged);
slider.addEventListener(SliderEvent.THUMB_DRAG, sliderDrag);
}
private function sliderDrag(e:SliderEvent):void {
trace("Slider dragging: " + e.target.value);
inputTextField.text = e.target.value;
posX();
}
private function sliderChanged(e:SliderEvent):void {
inputTextField.text = e.target.value;
}
//Sliders and InputText - End
public function loadImages():void
{
var caricatore:Caricatore=new Caricatore(this,objects_array[counter].image,counter);
counter++;
}
public function positionClips():void
{
removeChild(loading_txt);
removeChild(info_txt);
for(var i:int=0;i<pics_array.length;i++)
{
if(i>0)
pics_array*.x=pics_array[i-1].x+pics_array[i-1].width;
pics_array*.visible=true;
}
ratio=-container_mc.width/stage.stageWidth;
addListeners();
addMouseListeners();
moveContainer();
}
private function addListeners():void
{
for(var i:int=0;i<pics_array.length;i++)
{
pics_array*.addEventListener(MouseEvent.MOUSE_DOWN,openPopUp);
}
}
private function addMouseListeners():void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseIsMoving);
stage.addEventListener(Event.MOUSE_LEAVE,mousehasGone);
}
private function mouseIsMoving(evt:MouseEvent):void
{
boo=true;
}
private function mousehasGone(evt:Event):void
{
boo=false;
}
private function moveContainer():void
{
container_mc.addEventListener(Event.ENTER_FRAME,moveMe);
}
private function moveMe(evt:Event):void
{
if(boo)
{
var arrX:Number=mouseX*ratio+stage.stageWidth/2;
var dx:Number=arrX-evt.currentTarget.x;
var ax:Number=dx*.1;
evt.currentTarget.x+=ax;
check(evt.currentTarget as MovieClip);
}
else
{
evt.currentTarget.x-=speed;
check2(evt.currentTarget as MovieClip);
}
}
private function check(m:MovieClip):void
{
if(m.x<-m.width+stage.stageWidth)
m.x=-m.width+stage.stageWidth;
else if(m.x>0)
m.x=0;
}
private function check2(m:MovieClip):void
{
if(m.x<=-m.width+stage.stageWidth)
speed*=-1;
else if(m.x>=0)
speed*=-1;
}
private function openPopUp(evt:MouseEvent):void
{
var logoLoader:Loader=new Loader();
var galleryLoader:URLRequest=new URLRequest(objects_array[evt.currentTarget.id].pop);
logoLoader.load(galleryLoader);
var total:uint = gal_ctnr_mc.numChildren;
if (total > 0)
{
gal_ctnr_mc.addChildAt(logoLoader,0);
logoLoader.x = 0;
logoLoader.y = 150;
gal_ctnr_mc.removeChildAt(1);
}
else
{
gal_ctnr_mc.addChildAt(logoLoader,0);
logoLoader.x = 0;
logoLoader.y = 150;
}
}
}
}
Thanks!
-maconbot