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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pure actionscript preloader

Status
Not open for further replies.

firegambler

Technical User
Sep 25, 2002
455
AT
hi,

actually i am trying to get a little insight into this whole object orientated thing. so i want to create a preloader which is pure code.
the problem is that the variable showing the percent loaded does not update, it stays at zero (at least that's what the textfield shows me); the variable that should show me the current frame of _root stays at 1 however the music that starts with frame 2 in my testfile can be heard.
finally the dynamically created textfields disappear when the film jumps to frame 2.

could anybody please correct my code and tell me why it didn't work?
i am not quite a newbie to flash but i am as far as it concernes object orientated programming...

thanks a lot [thumbsup]

here is my code (which is positioned on the first frame of the root):

Code:
_root.stop();
finishedloading = 0;
Preloader=new MovieClip();
MovieClip.prototype.makeTextfields=function(){
	//textfield for percentage
	_root.createTextField("percent",2,10,10,50,20);
	percent.type="dynamic";
	percent.variable="_root.percent";
	percent.border=true;
	percent.background=true;
	percent.backgroundColor="0x00ffff";
	
	//textfield for current (root)frame - just to see where we are while developing the code
	_root.createTextField("WhereAmI",1,10,40,50,20);
	WhereAmI.type="dynamic";
	WhereAmI.variable="_root.whereami";
	WhereAmI.border=true;
	WhereAmI.background=true;
	WhereAmI.backgroundColor="0x00ff00";
	
	// textStyle
	format=new TextFormat();
	format.font="Arial";
	format.bold="true";
	format.size="16";
	format.align="right";
	format.color="0x000066";
	//attach format to textfields
	WhereAmI.setTextFormat(format);
	percent.setTextFormat(format);
}// end of makeTextfields()

MovieClip.prototype.preload = function() {
	total = getBytesTotal();
	loaded = getBytesLoaded();
	percent = Math.round(100*loaded/total);
	_root.percent = percent+"%";
	_root.whereami = _root._currentframe;
	if (finishedloading==0) {
		if (percent == "100%") {
			_root.nextFrame();
			finishedloading = 1;
		}		//end of if-condition
	}	//end of if-condition
}//end of preload()
Preloader.createEmptyMovieClip(MCPreloader,1);
MCPreloader.onLoad=makeTextfields();
MCPreloader.onEnterFrame = preload();

regards

tektips.gif
 
well,

what i am trying to do is creating the whole preloader via script.
that is why i want to make a function and add it via prototype to the movieclip-class.
then i'd like to create a movieclip (via script) that will do the preloading work (supplying the variables for percentage,... with the relevant values).

then when i got that (and understood that) i want to create a preloader-bar and control its width,... via script.

it is not that this would be outstanding urgent, it is just that i am pretty keen on finally understanding that whole object orientated "crap" :)
and i guess that would be a pretty usable mini-project on the one hand to learn that kind of scripting and on the other hand having a preloader weighing almost 0k.


anyway thanks for the link, i guess it is pretty related to what i am trying to do and i'll have to do a little reflection on this to make this more transparent to my designers brain (which is trying to become also a programmer's one :))

furthermore i'd appreciate additional comments to help me correct my code (unless it is so screwed up that i can't do anything exept filling up my garbage with it ;-))


best

regards

tektips.gif
 
i didnt realy go through your code. i just glanced at it and... well thought....prototype preloader thats been done........


making a preloader that just has actionscript might be a way to get at object oriented programming but it just includes a bar....which will probably only have 3 properties...width, height and color

the link i gave has little to do with what you want.

maybe this would be a better one


go to, tutorials, mx, and look at 'intoduction to listners'

and maybe a few other there like asbroadcaster. these are not directly tuts on OOP but to me they show the principles in an easy to understand model.

anyway its like riding a bike or learning to swim...hard at first...then so so straightforward....just stick with it and it will all come together.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top