Hi I’m really stuck please help.
At the moment I am loading all my images individually and then adding them to the stage one by one. I would love to have it so that they were only added to the stage (or only began their tween) after they were ALL loaded so that they all appear at the same time.
The problem is I have one image class which calls an XML file for each image, which is called each time I add an image to the stage. Therefore I am running the image class everytime making it impossible for me to check to see if ALL are loaded.
Can anyone think of a way around this because everything works fine except for this problem and I’d love to finish this.
if you want to see my problem in action please go to
www.joegardner.co.uk/newsite/main.html
Thanks in advance.
Joe.
this is the image class…
[COLOR=“rgb(139, 0, 0)”]package {
import flash.events.*;
import flash.net.*;
import flash.display.*;
import flash.utils.*;
import gs.TweenMax;
import gs.easing.*;
// begin class
public class Image extends Sprite {
// create variables
public var alphaStart:Number;
public var alphaEnd:Number;
public var xStart:Number;
public var yStart:Number;
public var xRolloverStart:Number;
public var yRolloverStart:Number;
public var xRolloverEnd:Number;
public var yRolloverEnd:Number;
public var xEnd:Number;
public var yEnd:Number;
public var rotationNumber;
public var bitMap;
public var imageLoader:Loader=new Loader;
public var timer;
public var imageName;
public var allImages;
public var image;
public var numArray:Array = new Array;
var xml:XML;
// begin constructor
public function Image(image:String)
{
// load in new XML file
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onLoaded);
// when the xml file is loaded
function onLoaded(e:Event):void
{
xml = new XML(e.target.data);
// make variables from the data in the xml file
imageName = xml.image;
xStart = xml.xStart;
yStart = xml.yStart;
xEnd = xml.xEnd;
yEnd = xml.yEnd;
xRolloverStart = xml.rolloverXStart;
yRolloverStart = xml.rolloverYStart;
xRolloverEnd = xml.rolloverXEnd;
yRolloverEnd = xml.rolloverYEnd;
alphaEnd = xml.alphaEnd;
alphaStart = xml.alphaStart;
rotationNumber = xml.rotationNumber;
}
xmlLoader.load(new URLRequest(image+".xml"));
imageLoader.load(new URLRequest(image+".png"));
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, howMuch, false, 0, true);
function howMuch(evt:ProgressEvent):void
{
var percent = Math.round((evt.bytesLoaded/evt.bytesTotal)*100);
trace (percent);
}
}
// add the images to the stage once the load is complete
public function done(e:Event):void
{
bitMap = Bitmap(imageLoader.content);//get the xmlLoaders content as a bitmap
bitMap.smoothing = true;//turn on smoothing
addChild(imageLoader);
imageIn();
imageLoader.x = xStart;
imageLoader.y = yStart;
imageLoader.alpha = alphaStart;
imageLoader.rotation = rotationNumber;
}
// tween in the images
public function imageIn()
{
var myTweenEnd:TweenMax = new TweenMax(imageLoader, 2, {y:yEnd, x:xEnd,ease:Quad.easeOut}); //identical to the previous line - it just looks more object-oriented.
var myTweenAlpha:TweenMax = new TweenMax(imageLoader,1, {autoAlpha:alphaEnd, ease:Expo.easeIn});
}
// tween out the images
public function imageOut() {
var myTween:TweenMax = new TweenMax(imageLoader, 2, {autoAlpha:0,ease:Expo.easeIn}); //identical to the previous line - it just looks more object-oriented
var myTweenEnd:TweenMax = new TweenMax(imageLoader, 1, {y:yStart, x:xStart,ease:Quad.easeOut}); //identical to the previous line - it just looks more object-oriented.
timer = new Timer(1000, 1);
timer.start();
timer.addEventListener(TimerEvent.TIMER_COMPLETE, removeMe);
// remove the images
function removeMe(e:TimerEvent):void
{
removeChild(imageLoader);
imageLoader = null;
}
}
// tween out the images
public function imageRollover() {
//var myTween:TweenMax = new TweenMax(imageLoader, 2, {autoAlpha:0,ease:Expo.easeIn}); //identical to the previous line - it just looks more object-oriented
var myTweenEnd:TweenMax = new TweenMax(imageLoader, 1, {y:yRolloverEnd, x:xRolloverEnd,ease:Elastic.easeOut}); //identical to the previous line - it just looks more object-oriented.
}
// tween out the images
public function imageRollout() {
//var myTween:TweenMax = new TweenMax(imageLoader, 2, {autoAlpha:0,ease:Expo.easeIn}); //identical to the previous line - it just looks more object-oriented
var myTweenEnd:TweenMax = new TweenMax(imageLoader, 1, {y:yRolloverStart, x:xRolloverStart,ease:Elastic.easeOut}); //identical to the previous line - it just looks more object-oriented.
}
}
}[/COLOR]
and this is the main.as which uses the image class
[COLOR=“DarkRed”]package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.display.MovieClip;
import flash.events.;
import flash.net.;
import flash.utils.*;
import flash.net.URLLoader;
import flash.display.DisplayObjectContainer;
import flash.display.Loader;
// begin class
public class Main extends Sprite {
//create variables
public var image;
public var button;
public var back;
public var loader;
public var cigs;
public var era1967;
public var eraNav:EraNav = new EraNav();
public var news;
public var pencil;
public var artwork;
public var badge;
public var portfolio;
public var resume;
public var folder:String;
public var chooseEra:ChooseEra = new ChooseEra();
public var line:Line = new Line();
public var myName;
public var choose;
public var era1923;
public var era1952;
public var era1988;
public var aboutMe;
public var navAbout;
public var musicOn;
public var musicOff;
public var lighting;
public var soundtrack;
public var buttonName;
/// sound Variables
public var clickSound;
public var audio;
public var closeBtn;
public var moreBtn;
public var aboutMe2;
public var aboutMeBoolean:Boolean = false;
public var aboutMe2Boolean:Boolean = false;
public var vars:URLLoader = new URLLoader();
// begin constructor and load the first era
public function Main()
{
defaultEra();
}
// load the first era (sixties)
public function defaultEra():void
{
folder = "sixties";
everythingIn();
}
// take out the old era and load the twenties era
public function twenties(evt:MouseEvent):void
{
folder = "twenties";
everythingOut();
everythingIn();
}
// take out the old era and load the fifites era
public function fifties(evt:MouseEvent):void
{
folder = "fifties";
everythingOut();
everythingIn();
}
// take out the old era and load the sixties era
public function sixties(evt:MouseEvent):void
{
folder = "sixties";
everythingOut();
everythingIn();
}
// take out the old era and load the eighties era
public function eighties(evt:MouseEvent):void
{
folder = "eighties";
everythingOut();
everythingIn();
}
// bring everything in for the new era
public function everythingIn():void
{
soundtrack = folder+"/soundtrack";
soundtrack = new LoadSound(soundtrack);
addChild(soundtrack);
image = folder+"/background";
back = new Image(image);
addChild(back);
addChild(line);
line.x = 235;
line.y = 800;
image = folder+"/myName";
myName = new Image(image);
addChild(myName);
image = folder+"/newspaper";
news = new Image(image);
addChild(news);
image = folder+"/artwork";
artwork = new Image(image);
addChild(artwork);
image = folder+"/pencil";
pencil = new Image(image);
addChild(pencil);
image = folder+"/portfolio";
portfolio = new Image(image);
addChild(portfolio);
image = folder+"/close";
closeBtn = new Image(image);
image = folder+"/more";
moreBtn = new Image(image);
image = folder+"/cigs";
cigs = new Image(image);
addChild(cigs);
image = folder+"/resume";
resume = new Image(image);
addChild(resume);
image = folder+"/badge";
badge = new Image(image);
addChild(badge);
image = folder+"/chooseEra";
choose = new Image(image);
addChild(choose);
image = folder+"/navAbout";
navAbout = new Image(image);
addChild(navAbout);
image = folder+"/aboutMe";
aboutMe = new AboutMe(image);
image = folder+"/aboutMe2";
aboutMe2 = new AboutMe(image);
image = folder+"/musicOn";
musicOn = new Image(image);
addChild(musicOn);
image = folder+"/musicOff";
musicOff = new Image(image);
image = folder+"/era1923";
era1923 = new Image(image);
addChild(era1923);
image = folder+"/era1952";
era1952 = new Image(image);
addChild(era1952);
image = folder+"/era1967";
era1967 = new Image(image);
addChild(era1967);
image = folder+"/era1988";
era1988 = new Image(image);
addChild(era1988);
image = folder+"/lighting";
lighting = new Image(image);
lighting.mouseEnabled = false;
lighting.mouseChildren = false;
addChild(lighting);
era1923.addEventListener(MouseEvent.CLICK, twenties);
era1923.addEventListener(MouseEvent.MOUSE_OVER, overSound);
era1923.addEventListener(MouseEvent.MOUSE_OVER, overButton);
era1923.addEventListener(MouseEvent.MOUSE_OUT, outButton);
era1952.addEventListener(MouseEvent.CLICK, fifties);
era1952.addEventListener(MouseEvent.MOUSE_OVER, overSound);
era1952.addEventListener(MouseEvent.MOUSE_OVER, overButton);
era1952.addEventListener(MouseEvent.MOUSE_OUT, outButton);
era1967.addEventListener(MouseEvent.CLICK, sixties);
era1967.addEventListener(MouseEvent.MOUSE_OVER, overSound);
era1967.addEventListener(MouseEvent.MOUSE_OVER, overButton);
era1967.addEventListener(MouseEvent.MOUSE_OUT, outButton);
era1988.addEventListener(MouseEvent.CLICK, eighties);
era1988.addEventListener(MouseEvent.MOUSE_OVER, overSound);
era1988.addEventListener(MouseEvent.MOUSE_OVER, overButton);
era1988.addEventListener(MouseEvent.MOUSE_OUT, outButton);
navAbout.addEventListener(MouseEvent.MOUSE_OVER, overSound);
navAbout.addEventListener(MouseEvent.MOUSE_OVER, overButton);
navAbout.addEventListener(MouseEvent.MOUSE_OUT, outButton);
navAbout.addEventListener(MouseEvent.MOUSE_DOWN, downNavAbout);
moreBtn.addEventListener(MouseEvent.MOUSE_OVER, overSound);
moreBtn.addEventListener(MouseEvent.MOUSE_OVER, overButton);
moreBtn.addEventListener(MouseEvent.MOUSE_OUT, outButton);
moreBtn.addEventListener(MouseEvent.MOUSE_DOWN, downMoreBtn);
/*closeBtn.addEventListener(MouseEvent.MOUSE_OVER, overSound);
closeBtn.addEventListener(MouseEvent.MOUSE_OVER, overButton);
closeBtn.addEventListener(MouseEvent.MOUSE_OUT, outButton);
closeBtn.addEventListener(MouseEvent.MOUSE_DOWN, downCloseBtn);*/
resume.addEventListener(MouseEvent.MOUSE_OVER, overResume);
resume.addEventListener(MouseEvent.MOUSE_OUT, outResume);
musicOn.addEventListener(MouseEvent.MOUSE_OVER, overSound);
musicOn.addEventListener(MouseEvent.MOUSE_OVER, overButton);
musicOn.addEventListener(MouseEvent.MOUSE_OUT, outButton);
musicOn.addEventListener(MouseEvent.MOUSE_DOWN, downMusicOn);
musicOff.addEventListener(MouseEvent.MOUSE_OVER, overSound);
musicOff.addEventListener(MouseEvent.MOUSE_OVER, overButton);
musicOff.addEventListener(MouseEvent.MOUSE_OUT, outButton);
musicOff.addEventListener(MouseEvent.MOUSE_DOWN, downMusicOff);
}
public function overSound(evt:MouseEvent):void
{
audio = folder+"/buttonSound";
clickSound = new LoadSound(audio);
addChild(clickSound);
removeChild(clickSound);
clickSound = null;
}
public function overResume (evt:MouseEvent):void
{
resume.imageRollover();
}
public function outResume (evt:MouseEvent):void
{
resume.imageRollout();
}
public function overButton(evt:MouseEvent):void
{
button = (evt.target);
button.alpha = 1;
}
public function outButton(evt:MouseEvent):void
{
button = (evt.target);
button.alpha = 0.7;
}
public function downNavAbout(evt:MouseEvent):void
{
addChild(closeBtn);
if (aboutMeBoolean == false)
{
addChild(aboutMe);
//aboutMeBoolean = true;
aboutMe2Boolean == false;
addChild(moreBtn);
} else if (aboutMe2Boolean == true)
{
removeChild(aboutMe);
}
}
public function downMoreBtn(evt:MouseEvent):void
{
if (aboutMeBoolean = true)
{
removeChild(closeBtn);
removeChild(aboutMe);
removeChild(moreBtn);
addChild(aboutMe2);
addChild(closeBtn);
aboutMeBoolean = false;
aboutMe2Boolean = true;
}
}
/*public function downCloseBtn(evt:MouseEvent):void
{
if (aboutMeBoolean == true)
{
removeChild(aboutMe);
removeChild(moreBtn);
}
if (aboutMe2Boolean == true)
{
removeChild(aboutMe2);
closeBtn.imageOut();
}
}*/
public function downMusicOn(evt:MouseEvent):void
{
removeChild(musicOn);
soundtrack.unloadSound();
addChild(musicOff);
}
public function downMusicOff(evt:MouseEvent):void
{
removeChild(musicOff);
addChild(musicOn);
soundtrack = folder+"/soundtrack";
soundtrack = new LoadSound(soundtrack);
addChild(soundtrack);
}
// take everything out of the old era
public function everythingOut():void
{
back.imageOut();
pencil.imageOut();
news.imageOut();
cigs.imageOut();
portfolio.imageOut();
badge.imageOut();
resume.imageOut();
artwork.imageOut();
aboutMe.aboutOut();
myName.imageOut();
navAbout.imageOut();
era1923.imageOut();
era1952.imageOut();
era1967.imageOut();
era1988.imageOut();
musicOn.imageOut();
musicOff.imageOut();
closeBtn.imageOut();
soundtrack.unloadSound();
}
}
}[/COLOR]