View Full Version : [FMX] CreateThisMovieClip and DoSomething.onRelease
w1cked5mile
March 1st, 2004, 03:24 PM
Solve one problem. Still have another. Why doesn't this code work correctly for the onRelease?
createEmptyMovieClip("MC", 1);
MC.loadMovie("MC.swf", "_root.MC");
MC.onrelease = function() {
trace("hello world");
};
Thank you for any help!
Creative minds have always been known to survive any kind of bad training.
--Anna Freud (1895-1982)
Seticus
March 1st, 2004, 03:40 PM
that's some strange AS, better is this:
_root.createEmptyMovieClip("MC", 1);
loadMovie("MC.swf", MC);
now here is where you are mistaken:
MC is a movieclip and you want to ad onrelease to it? you should use : "onMouseUp" I think:
MC.onMouseUp = function() {
trace("hello world");
};
Seticus
March 1st, 2004, 04:32 PM
this doesn't seem to work either, strange, never done this before
I'll have to look into that... Maybe someone else knows
w1cked5mile
March 1st, 2004, 04:33 PM
The code provided:
_root.createEmptyMovieClip("MC", 1);
MC.loadMovie("MC.swf", MC);
MC.onMouseUp = function() {
trace("hello world");
};
doesn't provide the results either. The loaded MC does not act as a button and the mouse does not change to indicate a button.
Any other suggestions?
Seticus
March 1st, 2004, 04:37 PM
it works when you don't load a movie into it (onrelease works fine too)
So if you load a movie into a mc, you cannot use onrelease anymore? This must be a bug, I can't find any information on the web about this either...
Seticus
March 1st, 2004, 05:22 PM
I've found a rather simple solution: make an empty movieclip inside an empty movieclip, like this:
_root.createEmptyMovieClip("MC", 0);
_root.MC.createEmptyMovieClip("MC2", 0);
loadMovie("MC.swf", MC.MC2);
MC.onRelease = function() {
trace("hello world");
};
So it seems you can't give an onRelease event to a mc where you load a movie into. So now, you load a movie into a mc that's located in a mc that trigers the event.
Should work perfectly now.
w1cked5mile
March 1st, 2004, 07:47 PM
So... what's the deal that you can't do an onRelease for the MC without dropping it in another MC first. If I drop a dummy MC on the _root of a .swf I can reference it with a mc.onrelease but for a empty movie clip I created and loaded another .swf in, I can't?
Anyone care to post an answer as to where it breaks down or why?
flash4food
March 1st, 2004, 09:13 PM
its because (i think) when u load something on an MC it deletes all of that mc's content including code, the solution would be to add the onRelease handler after loading the content, like this:
MC.loadMovie("MC.swf");
MC.onLoad=function(){
if(_width!=0){
MC.onMouseUp = function() {
trace("hello world");
}
};
try it and let me know if it works
w1cked5mile
March 1st, 2004, 09:38 PM
Flash4Food - I think your right when it comes to over writing the MC when you load something into it but I am actually creating an empty MC then loading an external .swf then trying to make that MC respond to an onRelease event.
The code you provided didn't provide the trace response and didn't display the hand indicating a button.
w1cked5mile
March 1st, 2004, 09:46 PM
Just wondering why these .FLA/.SWF won't work.
This is a scaled down MC of a larger project's problem that I'm trying to solve. The resolution of embedding multiple MCs provided by Seticus above also breaks functions in the loaded MCs by the way.
claudio
March 1st, 2004, 09:58 PM
Assign the onRelease event after the clip has been fully loaded.
createEmptyMovieClip("MC", 1);
MC.loadMovie("MC.swf");
myInterval = setInterval(preload, 50, MC, "hello word");
function preload(clip, text) {
var t = clip.getBytesTotal(), l = clip.getBytesLoaded();
if (t && l == t) {
clearInterval(myInterval);
clip.onRelease = function() {
trace(text);
};
}
}
w1cked5mile
March 1st, 2004, 10:11 PM
That works for the code I posted. Hopefully I can adapt it to my larger project. Thank you all very much for the help.
So the conclusion is that it's not fully loading the .swf and can't be assigned an onRelease action?
claudio
March 1st, 2004, 10:16 PM
The problem is when you load some movie into a movieclip, the dynamic event handlers of that movieclip are erased.
Since you are not assuring the movie has been fully loaded before assigning the event handler, the event handler gets assigned and then erased because the new content "arrives".
w1cked5mile
March 2nd, 2004, 09:39 AM
Update...
In my larger project that I pulled the above code out of, I was not able to apply the fix provided by claudio. When I tried it, some of the actions in the loaded .swf did not occur. I assume this is because loading the onrelease event on top of the .swf unloaded other on or onclipevent events. Now that everyone is thouroughly confused...
However, I worked around it by putting the onrelease event in the loaded .swf and using if statements to test which loaded .swf I'm in.
It's a little convoluted and I'm sure I can make it more effecient but it works like I want it to now. Thank you all for your help.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.