Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a function in an if statement

Status
Not open for further replies.

leeboycymru

Programmer
Jan 23, 2007
185
GB
I have created a function to help load jpeg's into a movie holder depending on the name of the variable attached to the codebase.

In this case the name of the variable in the codebase is "Home", but thats not really the problem, its the calling of the function of if a variable equals to the codebase variable, see below:

Code:
if (_root.button == "Home"){
	_root.onEnterFrame = function() {
		var link = _root.button;
	infoField._visible=true;
	startLoading("HomeImage.jpg");
	}
};

Code:
function startLoading(whichImage) {
	loadMovie(whichImage,"imageLoader");
	_root.onEnterFrame = function() {
		var link = _root.button;
		infoLoaded = imageLoader.getBytesLoaded();
		infoTotal = imageLoader.getBytesTotal();
		percentage = Math.floor (infoLoaded/infoTotal*100);
		infoField.text = percentage+"%";
		if (percentage>=100) {
			delete this.onEnterFrame;
			infoField._visible=false;
		}
	};
}

So my dilema is when (_root.button == "Home"), I want to call the function, but it doesnt seem to be working.

Lee
 
Thats a problem with this script, because the value of bottom comes in from the codebase, and the flash populates the webpage via jscript to overcome the horrible border you get and validation, so I can only publish it and test it through the browser, so I cant use trace.

Instead I set up a dynamic text field called link, and it should show the word "Home" when its called in onEnterFrame.

I did however test it locally using trace("boo"); inside the onEnterFrame, and it was called, so it seems that now onEnterFrame is working just that the function or the text field isnt working when viewed through the website via the browser.

 
If you put [tt]var button = "Home"[/tt] in the root timeline for testing, you won't need to test it in the browser. Just remove it when it's done.

One thing, in your first block of code, you shouldn't use [tt]onEnterFrame[/tt], or it will fire [tt]startLoading()[/tt] again and again.

Kenneth Kawamoto
 
Ok ye didnt think of that!

Ok I also took note of your startLoading() issue and changed the code to be like this:

Code:
_root.onEnterFrame = function(){

if (_root.button == "Home"){
    infoField._visible=true;
    startLoading("HomeImage.jpg");
	delete this.onEnterFrame;
	};
};

Seems to work fine, and this is the error Im coming back with:

Error opening URL "file:///U|/MyScripts/accend/htdocs/Hobbs%2DWeb%2DTemplate/site%5Fflash/flash/HomeImage.jpg"

So it doesnt seem to be able to find the image to continue with the script is that it?

Lee
 
Thanks kennethkawamoto,

It works now and it isnt loading the image over and over either.

Thanks

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top