PDA

View Full Version : can't access the component through a mc


sted
06-08-2005, 11:57 AM
Hello,

I want a page to have a dynamical interface (in the same frame to avoid a lot of problems) so i have put a first interface with label, textarea etc. in a symbol movieclip, and i have to do others interfaces with another labels, pictures etc.

for the moment, i ve done
_root.attachMovie("test_mc", "foo", 42);
_root.foo.adynamicaltext.text = "blabla"; // work, it s not a label, just a dynamical text in the test_mc movieclip
_root.foo.atextarea.text = "blabla"; // doesn t work ! it s a textarea in the test_mc movieclip


i don't understand why with the textarea, label etc. all the components, it doesn t work. help please.

thanks

senocular
06-08-2005, 12:08 PM
A components "features" aren't accessible until the component is fully loaded, or at least initialized. Initialization happens within a certain order in Flash as flash goes frame by frame exectuting scripts. The frame scripts in your attachedMovie and component arent run (for initialization) until after the scripts in the current frame complete - that is the frame you're using attachMovie. That means that in that frame (the attachMovie frame) nothing will be initialized within the attached movie to be available for use. This includes the component and its text property. A simple textfield is basic enough that it doesn't need initialization like a component does.

What to do? Luckly, elements like components have an onLoad event you can assign a callback function to notifying you when initialization is compelte. In that onLoad function you can set the text for your component as the text property would then be accessible.
_root.attachMovie("test_mc", "foo", 42);
_root.foo.atextarea.onLoad = function(){
// this runs after the frame containing attachMovie is executed
// component is now initialized
// since this function is defined in _root.foo.atextarea
// 'this' in this function represents _root.foo.atextarea
this.text = "blabla";
}

sted
06-08-2005, 12:15 PM
ho yes of course. i have totally forgot this aspect of flash. it s working perfectly now.

muito obrigado ! [thanx a lot]

senocular
06-08-2005, 12:27 PM
De rien ;)