PDA

View Full Version : Calling a previously made function in an if statment



Idostuff
January 8th, 2009, 05:01 PM
So I have a small gallery type of thing I'm running. You click on the thumbs and an image loader puts the images on the stage.

That part works great, yay!

However, I would love to have some back and next buttons.

Currently i'm assigning all the thumbnails a number value - on the next button it checks to see what number is up.

next_btn.buttonMode = true;
next_btn.addEventListener(MouseEvent.CLICK, nextPic);
function nextPic(e:Event):void
{
if(picNumber == 1)
{

}
}

What I want to do, is pass a function I've already made in the if statment instead of re-writing the whole thing. Here is the function that is down further in my code:

function show2(e:Event):void
{
var textLoader:URLLoader= new URLLoader();
var textRequest:URLRequest = new URLRequest("two.txt");
var imageRequest:URLRequest = new URLRequest("two.jpg");
function textLoaded(e:Event):void
{
cssLoader.load(cssRequest);
cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
}
function cssLoaded(e:Event):void
{
textLoader.addEventListener(Event.COMPLETE, textLoaded);
imageLoader.load(imageRequest);
fadeTween = new Tween(imageLoader, "alpha", None.easeNone,0,1,.5, true);
addChild(imageLoader);
addChild(imageText);
}

Any advice would be hugely appreciated, thanks!

GrndMasterFlash
January 8th, 2009, 05:17 PM
humm, not sure if i understand you correctly but if your trying to use the functions you have below and your looking for a way to call them without having to use your e:Event than what you could do is make the params an array like so
function show2(...params):void this way you don't have to pass in anything and it can still be assigned to an event so you could just call it like



if(picNumber == 1)
{
show2();
}


and everything would be cool, that is if i understand what you are asking.... ?:|

Idostuff
January 8th, 2009, 05:22 PM
Thanks for your help - I'm new to the wide wonderful world of code. Hence my lack of articulation. I will give the array a whirl.