Hi
I create a flash as3 where my stage has 3 buttons home button2 and button3. when i click home button a thumbnail xml gallery will loaded. when button 2 and button3 clicked it loads some text from another xml file. All it’s work well. My problem is after i clicked the home button the gallery loads then if i clicked the other buttons the gallery still displayed in the stage. The text from the other xml file will stack behind the gallery. How to solve this.
This is my code:
import fl.transitions.Tween;
import fl.transitions.;
import fl.transitions.easing.;
//Create a holder that will contain the title, content and image.
var holder:MovieClip = new MovieClip();
holder.addChild(contentText);
holder.addChild(titleText);
holder.addChild(imageHolder);
addChild(holder);
//Hide the holder at the beginning of the movie.
//We don’t want to show any content before the title, content and image has
//been loaded.
holder.visible = false;
//We don’t want the user to be able to click the text fields inside the buttons
homebtn.mouseChildren = false;
button2.mouseChildren = false;
button3.mouseChildren = false;
//Make the buttons look like buttons (hand cursor appears on hover)
homebtn.buttonMode = true;
button2.buttonMode = true;
button3.buttonMode = true;
//Specify the path to the XML file.
//You can use my path or your own.
var xmlFilePath:String = “about.xml”;
//We save the loaded XML data into a variable
var XMLData:XML;
//Load the XML file.
//We call the xmlDataLoaded() function when the loading is complete.
var loader = new URLLoader();
loader.load(new URLRequest(xmlFilePath));
loader.addEventListener(Event.COMPLETE, xmlDataLoaded);
//This function is called when the XML file is loaded
function xmlDataLoaded(e:Event):void {
//Create a new XML object from the loaded XML data
XMLData = new XML(loader.data);
XMLData.ignoreWhitespace = true;
//Call the function that adds event listeners for the buttons
addEventListeners();
//We dispatch a mouse click event for the first button,
//so we start the movie with the first page (without user having to select it).
}
//This function adds event listeners for the buttons
function addEventListeners():void {
homebtn.addEventListener(MouseEvent.CLICK, buttonClicked);
button2.addEventListener(MouseEvent.CLICK, buttonClicked);
button3.addEventListener(MouseEvent.CLICK, buttonClicked);
button2.addEventListener(MouseEvent.CLICK, flyMyObject);
button3.addEventListener(MouseEvent.CLICK, flyMyObject);
}
function flyMyObject(event:MouseEvent)
{
TransitionManager.start(holder, {type:Fly, direction:Transition.IN, duration:3, easing:Elastic.easeOut, startPoint:6});
}
function buttonClicked(e:Event):void {
//Make the holder invisible while we are loading data
holder.visible = false;
//Show the loading text
//Save the clicked button to a local variable
var clickedButton:MovieClip = (MovieClip)(e.target);
//Set the wanted page number according to which button the user clicked
var pageNumber:uint;
if (clickedButton == button2) {
pageNumber = 2;
} else if (clickedButton == homebtn)
{
var fadeTween:Tween;
var imageLoader:Loader;
var xmlList:XMLList;
var xml:XML = new XML();
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest(“images.xml”));
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
function LoadXML(event:Event):void
{
xml = new XML(event.target.data);
buildScroller(xml.image);
}
var scroller:MovieClip = new MovieClip();
var speed:Number;
var padding:Number = 20;
var thumbFadeOut:Number = .2;
var thumbFadeIn:Number = 1;
this.addChild(scroller);
scroller.y = 510;
function buildScroller(imageList:XMLList):void
{
for (var i:int = 0; i < imageList.length(); i++)
{
var thumbloader:MovieClip = new MovieClip();
thumbloader.x = (100 + 20) * i;
thumbloader.full = imageList*.attribute(“full”);
thumbloader.thumb = imageList*.attribute(“thumb”);
var ldr:Loader = new Loader();
ldr.load(new URLRequest(thumbloader.thumb));
thumbloader.addChild(ldr);
thumbloader.buttonMode = true;
thumbloader.addEventListener(MouseEvent.MOUSE_OVER, overScrollerItem);
thumbloader.addEventListener(MouseEvent.MOUSE_OUT, outScrollerItem);
thumbloader.addEventListener(MouseEvent.CLICK, clickScrollerItem);
scroller.addChild(thumbloader);
scroller.scaleX = 1.2;
scroller.scaleY = 1.2/2;
}
scroller.addEventListener(Event.ENTER_FRAME, moveScrollerThumbs);
}
function overScrollerItem(event:MouseEvent):void
{
var my_thumb:Loader = Loader(event.target);
my_thumb.alpha = 0.5;
}
function outScrollerItem(event:MouseEvent):void
{
var my_thumb:Loader = Loader(event.target);
my_thumb.alpha = 1;
}
function clickScrollerItem(event:MouseEvent):void
{
imageLoader = new Loader();
imageLoader.load(new URLRequest(event.currentTarget.full));
imageLoader.x = 25;
imageLoader.y = 120;
imageLoader.scaleY = 3/4;
imageLoader.scaleX = 3/4;
addChild(imageLoader);
fadeTween = new Tween(imageLoader,"scaleX",Elastic.easeOut, 10, 1.5, 1,true);
}
function moveScrollerThumbs(event:Event):void
{
if ( mouseY > scroller.y && mouseY < scroller.y + scroller.height)
{
if (mouseX < 50 && mouseX > 0)
{
speed = +5;
}
else if (mouseX > 750 && mouseX < 800)
{
speed = -5;
}
else
{
speed = 0;
}
scroller.x += speed;
if (scroller.x < - scroller.width + stage.stageWidth - padding)
{
scroller.x = - scroller.width + stage.stageWidth - padding;
}
else if (scroller.x > padding)
{
scroller.x = padding;
}
}}
function shadows() {
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.distance=3;
dropShadow.angle=90;
dropShadow.color=0x999999;
dropShadow.alpha=5;
dropShadow.strength=1;
dropShadow.quality=15;
scroller.filters=new Array(dropShadow);
}
shadows();
}
else {
pageNumber = 3;
}
for each (var page:XML in XMLData.pages.page) {
if (page. @ page_number == pageNumber) {
titleText.text = page.title;
contentText.text = page.content;
var myformat = new TextFormat();
myformat.color = 0xFFFFFF;
myformat.size =24;
myformat.align = "center";
titleText.setTextFormat(myformat);
contentText.setTextFormat(myformat);
var imageloader = new Loader();
imageloader.load(new URLRequest(page.image));
imageloader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
break;
}
}
}
function imageLoaded(e:Event):void {
holder.visible = true;
if(imageHolder.numChildren > 0) {
imageHolder.removeChildAt(0);
}
imageHolder.addChild(e.target.content);
}