| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Flash'a'holic
|
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)
}
Code:
this.createEmptyMovieClip("tester",1)
tester.onData=function(){
trace("hey")
}
tester.onLoad=function(){
trace("loaded")
}
tester.loadMovie("your.swf")
![]() |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,625
|
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. |
|
|
|
|
|
|
|
|
#3 |
|
Worldkit Vote Holder
|
Highly interesting...!
![]()
__________________
Cordially, Abelius Commuting between Birmingham, AL, Miami, FL and Beijing, China http://www.worldkit.com |
|
|
|
|
|
#4 |
|
Thing
Join Date: Jun 2001
Location: UK
Posts: 2,418
|
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.. |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,625
|
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. |
|
|
|
|
|
#6 |
|
Thing
Join Date: Jun 2001
Location: UK
Posts: 2,418
|
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? |
|
|
|
|
|
#7 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,625
|
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. |
|
|
|
|
|
#8 |
|
Thing
Join Date: Jun 2001
Location: UK
Posts: 2,418
|
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? |
|
|
|
|
|
#9 |
|
Thing
Join Date: Jun 2001
Location: UK
Posts: 2,418
|
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.. |
|
|
|
|
|
#10 |
|
Thing
Join Date: Jun 2001
Location: UK
Posts: 2,418
|
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 ............................ |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |