all groups > flash actionscript > may 2004 >
You're in the

flash actionscript

group:

attached movieclip looses functionality


attached movieclip looses functionality xyz123
5/23/2004 6:50:54 PM
flash actionscript: Hello,

I defined a movieclip, sub_mc, containing a button to which this simple code
is attached:
on (press) {
trace("button pressed");
}

When test run I can press this movieclip sub_mc and the text "button pressed"
is shown in the output screen.
Next I attache this movieclip sub_mc to another movieclip, in my case
"main_mc". The button behaviour of the sub_mc is now totally gone.
(_root.main_mc.attachMovie("sub","sub2_mc",2)
In my case main_mc is just a square converted to a movieclip symbol "main" in
the library. The sub_mc is a square converted to a button symbol "sub" in the
library.
Is it normal for attached movieclips to lose functionality this way? Is there
a workaround/dfferent approach to just have a clip attached without loosing
this functionality? What I expect from "attache" is inheriting from the super
container with maintaining the own behaviour. But maybe this is a wrong
assumption.

Thanks
Re: attached movieclip looses functionality stwingy
5/23/2004 8:32:10 PM
I`m a little unsure how you are putting code on a button which you are
attaching dynamically.
try this:
draw a square , give it an instance name main_mc in the property inspector.
Give your button a linkage identifier of sub in the library. On the first frame
of the main timeline type
_root.main_mc.attachMovie("sub", "sub2_mc", 2);
main_mc.sub2_mc.onPress = function() {
trace("button pressed");
};
Re: attached movieclip looses functionality stwingy
5/23/2004 8:32:18 PM
I`m a little unsure how you are putting code on a button which you are
attaching dynamically.
try this:
draw a square , give it an instance name main_mc in the property inspector.
Give your button a linkage identifier of sub in the library. On the first frame
of the main timeline type
_root.main_mc.attachMovie("sub", "sub2_mc", 2);
main_mc.sub2_mc.onPress = function() {
trace("button pressed");
};
Re: attached movieclip looses functionality xyz123
5/23/2004 9:48:09 PM
You are right I did forget something to describe my case.

In fact the "sub" symbol contains another symbol which I converted to a button
(just another square with corresponding state color changes) . Since I now have
an instance of this button available in the "sub" movieclip, I added button
event handler code on this timeline. Again this works fine if you just put an
instance of "sub" to the stage. But doing it via the attachement in the main
instance "main_mc"(being just a bigger square) it shows the smaller sub_mc
nicely in the left top corner, but while clicking on it nothing happens(no
action defined on main_mc).

It is important for me to have the behaviour already present in the element
like sub_mc before attaching to another, and not having to re-code the
behaviour via the attacher. In this basic study I try to find out if I can
simulate physical elements to "join" together for a period of time like
magnets, but then at some point getting separated again. While joining keeps
the elements together they still must keep there own behaviour. So selecting
the attached sub_mc should still generate its specific on (press)
{trace("button pressed");} result.
So far I did not succeed yet.

Re: attached movieclip looses functionality stwingy
5/24/2004 3:18:16 PM
I`m not sure what you are doing wrong. I have reconstructed your example and it seems to work fine.
http://www.gifsrus.com/testfile/btneg.fla
Re: attached movieclip looses functionality xyz123
5/24/2004 7:38:04 PM
Indeed it works. And now I had an opportunity to compare. And ..oeps.. guess
what my main_mc contains another piece of code that I didn't consider of any
importance for this case but......it is the only thing different and turns out
to be creating the "function loss". Added to my main_mc is the code:

on (press) {
startDrag(this);
}
on(release){
stopDrag();
}

And.... just to make certain, I added this code to your main_mc / symbol.
Result: the button function of the attached clip is gone. I suppose that this
resulting behaviour is the "natural" thing, but in fact I can't think of any
logical explanation realy.
Basically my question is now answered: functionality is not lost if no a.s.
is added to main_mc....but if you do it may be or may not be lost.
This unexpected behaviour is still not what I want. I do need to drag main_mc
and still have button functionality of the attached clip. So if I am right my
problem starts to convert to understanding the mechanism behind the result of
the "attache" action : what actualy does happen and thus what are the
consequences is more like the question now? Most probably inheriting behaviour
plays a key roll here.


Thanks
AddThis Social Bookmark Button