Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)

Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
Old 07-12-2002, 06:33 AM   #1
FlashGuru
Flash'a'holic
 
Join Date: Dec 2000
Location: London, UK
Posts: 82
Send a message via ICQ to FlashGuru
Default Bug Fix: movieclip.onLoad/movieclip.onData

It is common practice with the new event model, for us to want to use the movieclip.onData and movieclip.onLoad events to create preloaders for loaded movies and loaded images, unfortuneatley flash totally resets a movieclip when the movieclip.loadMovie method is called, to make way for the new .swf file. Therefore all event handlers applied to the movieclip are removed and all inheritance is reset.

Heres an actionscript based fix, that will solve this problem for you:

Code:
Movieclip.prototype.oldLoadMovie=Movieclip.prototype.loadMovie
Movieclip.prototype.loadMovie=function(url,vars){
	if(this.onData != undefined && this.onData != null){
		this._parent.createEmptyMovieClip("__fixEvents",7777)
		this._parent.__fixEvents.theTarget=this
		this._parent.__fixEvents.onData=this.onData
		if(this.onLoad != undefined && this.onLoad != null){
			this._parent.__fixEvents.onLoad=this.onLoad
		}
		this._parent.__fixEvents.onEnterFrame=function(){
			this.oldv=this.v
			this.v=this.theTarget.getBytesLoaded()
			if(this.v != this.oldv){
				this.onData.call(this.theTarget)
			}
			if(this.v == this.theTarget.getBytesTotal()){
				this.theTarget.onData=this.onData
				if(this.onLoad != undefined){
					this.theTarget.onLoad=this.onLoad
				}
				this.onLoad.call(this.theTarget)
				this.removeMovieClip()
			}
		}
	}
	this.oldLoadMovie(url,vars)
}
Place the above code on the first frame of the main timeline and then use this code to test it:

Code:
this.createEmptyMovieClip("tester",1)
tester.onData=function(){
	trace("hey")
}
tester.onLoad=function(){
	trace("loaded")
}
tester.loadMovie("your.swf")
FlashGuru is offline   Reply With Quote
Old 07-12-2002, 08:47 AM   #2
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,625
Default

Swoit!
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder
Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 07-12-2002, 05:53 PM   #3
Abelius
Worldkit Vote Holder
 
Abelius's Avatar
 
Join Date: May 2002
Location: Miami - USA
Posts: 815
Send a message via Yahoo to Abelius
Default

Highly interesting...!
__________________
Cordially,
Abelius
Commuting between Birmingham, AL, Miami, FL and Beijing, China
http://www.worldkit.com
Abelius is offline   Reply With Quote
Old 07-22-2002, 11:50 AM   #4
Mortimer Jazz
Thing
 
Mortimer Jazz's Avatar
 
Join Date: Jun 2001
Location: UK
Posts: 2,418
Default

FG When you say that Flash resets the movie is this a bug or intentional?

If the movie already exists on the timeline and has code on it, resetting it would wipe all the code? Why does the commenting method work? Do you know?

Just intrigued and I'd imagine you'd be the man to answer thoses q's

]Thanks,
MJ

Last edited by Mortimer Jazz; 07-22-2002 at 12:36 PM..
Mortimer Jazz is offline   Reply With Quote
Old 07-22-2002, 02:26 PM   #5
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,625
Default

As Guy's email might be sufferring in his site downtime I thought I'd step in here. When you load content into a timeline it's jus tlike loading over _level0. Everything gets whiped out. It's intentional; designed to stop conflicts from redundant objects and save virtual memory I imagine. In most cases it's cool 'cept for this particular case!
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder
Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 07-22-2002, 02:48 PM   #6
Mortimer Jazz
Thing
 
Mortimer Jazz's Avatar
 
Join Date: Jun 2001
Location: UK
Posts: 2,418
Default

So it resets a clip and not replaces it is that right?

What I'm getting at is this: one method of getting onLoad to work is to create an mc instance on stage (rather than use createMovieClip) and attach comment tags (or indeed, any code) to the instance.

If Flash does initialise everything why doesn't it also clear the comment tags on the mc (which is one method of getting onLoad to work)

Do the comment tags stop the movie from being totally re-initialised and therefore 'save' the code that's been assigned via the onLoad?
Mortimer Jazz is offline   Reply With Quote
Old 07-22-2002, 03:15 PM   #7
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,625
Default

The methods which the onLoad and onData handlers link to are children of the specific MC they are applied to. When new content is loaded into that MC the timeline is cleared and the methods are therefore deleted... Does that help?
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder
Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 07-22-2002, 04:24 PM   #8
Mortimer Jazz
Thing
 
Mortimer Jazz's Avatar
 
Join Date: Jun 2001
Location: UK
Posts: 2,418
Default

so why does the 'commenting-method' still work?

why do the "children of the specific MC" methods not get deleted when you use the comments?
Mortimer Jazz is offline   Reply With Quote
Old 07-23-2002, 01:26 AM   #9
Mortimer Jazz
Thing
 
Mortimer Jazz's Avatar
 
Join Date: Jun 2001
Location: UK
Posts: 2,418
Default

Jesse, the following is how I thought the whole onLoad thing was set up to work. I've mainly been reading Moock's asdg book, but I'm not saying I didn't manage to misinterpret something along the way! From what you're saying it sounds like I might have misunderstood part of it, and I'd be grateful to be put right if I have
Here goes...........

______________________________________________
1) onLoad is a method of the movieClip object

2) A method is essentially a function stored in an object property.
In our case our function would be attached to a property of the movieclip Class's prototype object, so it can be shared accross all instances via inheritance.

...so when you write: myClip.play();
you are actually saying: "look through myClip's list of PROPERTIES for one called 'play'... (and if I don't have one, check the Class that made me)". You then append the call operator "()" to run whatever value (in this case our function) is inside that property.
-----
[note: this seems to be correct because you can also call array elements that hold functions like this: myArray[i]();
------
3) The object you then create (in this case our movie clip) inherits
the onLoad method from the prototype
__________________________________________________ _
If it is done this way then onLoad and Data funcs aren't children of the object

[edit: sorry for the multiple posts guys (now deleted)!
I wasn't trying to make a point - heheh! I was just having a bit of a fight with the server last night. I kept getting a 404's.
I checked this morning only to find about 20 duplicates on this thread! Lol]

Last edited by Mortimer Jazz; 07-23-2002 at 11:51 AM..
Mortimer Jazz is offline   Reply With Quote
Old 07-24-2002, 11:20 AM   #10
Mortimer Jazz
Thing
 
Mortimer Jazz's Avatar
 
Join Date: Jun 2001
Location: UK
Posts: 2,418
Default

Jesse? Anyone?

WHAT DOES THE EMPTY LINE DO TO STOP THE onLOAD FROM GETTING REINITIASLIZED?????????????

which can also be looked at from the point of view:

IS THIS REALLY WHAT'S HAPPENING IN THE FIRST PLACE??


Look at the different working methods on this thread.
http://www.were-here.com/forums/show...ghlight=onLoad

It is Madokan who firsts suggests the 'empty-line' method (at the top of page 2).
I can see why some of the 'working methods' here appear to work*, but I can't see why the empty-line method works if it really is handling the objects as you suggested Jesse.
Do you see? I don't know how else to explain what I'm getting at now! I really appreciate your answers but both seemed to have missed answering the above point.

I'd hate to leave this unresolved. If anyone can help out here.....
Please correct me, chastize me, slap me but don't leave me hanging
____________________________

*For example:
this[myMC].onLoad probably works because this[myMC] evals to level0, instead of myMC, so it's prolly doing the onLoad stuff based on when level0 loads and NOT based on the movieclip at all!
__________________
............................
FLEX/FLASH BLOG
Previous Flash Tutorials

............................
Mortimer Jazz is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
a BUG or Not a BUG ??? Xeef ActionScript 2.0 4 02-28-2005 05:29 PM
Flash Depth Bug? IceCo ActionScript 2.0 7 02-28-2005 05:16 AM
select textArea stylesheet bug jayfour000 ActionScript 2.0 3 08-26-2004 07:44 PM
A Small Bug in Design ?????? Neo Anderson Site Check 3 01-09-2003 04:40 AM
IceProjector > another bug found! Tankshell Flashants Support Forum 5 07-31-2002 11:47 AM


All times are GMT. The time now is 02:29 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.
You Rated this Thread: