View Full Version : MovieClips on stage and displayobject
level4designs
June 2nd, 2008, 10:00 PM
ok... I have this flash remoting project, and I have it all working, I have imported packages, I understand classes... and as I start to learn AS3 from AS2, I am really really confused about how to access things?
IF I have a simple movie clip on the main timeline, I can access it fairly easy enough... but how do I access things inside of movieclips, inside of movie clips?
my 1st thought was if you give it an instance name, it is automatically created, perhaps call it via it's instance name? no...
my 2nd thought was I was trying to create new variables with the same names as my instances on stage and use addChild()? don't think so...
and of all the books I read, it really relies on very simplistic systems such as
var newtextbox:textBox = new textBox();
blah, blah, blah... or the tutorials show how to draw a circle or a square... who does this?
realistically, it seems we are all used to using flash to make compelling ads, banners, buttons, and what not and use it as a tool to combined the best of design with the simplicity of extending it with code... now it's all code it seems like? there has to be a way to use the timeline in a simple form?
so, problem.
AS2:
_root.mymovieclip_mc.myinsidemovieclip_mc.mypictur e_mc._alpha = 50;
_root.mymovieclip_mc.myinsidemovieclip_mc.mytext_t xt.text = "this is a test";
AS3:
what would be an equivilant? how do I access those if they are designed and built on the stage, ready to go... no need to build them in the code?
much appreciated :bucktooth: in advance...
cshaheen
June 3rd, 2008, 02:51 AM
If you have the objects on stage at compile time, you should be able to reference them directly, via parentClip.childClip1.childClip2. That is if you gave them all names, and you are referencing them FROM the main stage (not from within some object elsewhere in the display list).
If you created the objects at runtime (in your code), you should be able to reference them by their instance name, no matter where in the display list they are.
If that doesn't help, it would be easier to answer if you included some sample code to illustrate your question.
creatify
June 3rd, 2008, 02:53 AM
I'm not sure I completely understand the question... but, when you create an item like:
var foo:MovieClip = new MovieClip();
// you have to give it a name:
foo.name = "fooClip";
addChild(foo);
Then in later code, to access the clip by name, you have to know where it was added to, if the code above is on the root timline, and you are writing code on that same timline, you can simply use the following to access the clip:
fooClip.subclipname.subsubclipname;
//or this should work
this.fooClip.subclipname.subsubclipname;
//or
var ref:MovieClip = this.getChildByName("fooClip");
ref.subclipname.subsubclipname;
level4designs
June 3rd, 2008, 11:54 AM
var foo:MovieClip = new MovieClip();
// you have to give it a name:
foo.name = "fooClip";
addChild(foo);
is this all done for me above if I have an object on the stage and I give it an instance name?
ooh, now I'm getting it I think... so I CAN path to my objects... I believe _root doesn't work in AS3, but root does? or I see you are using "this" and "parent" is that more preferred?
I believe I tried the following:
root.mymovieclip_mc.myinsidemovieclip_mc.mypictur e_mc.alpha = 50;
and this did not find it... and I have all my clips named obviously... which is why I am getting frustrated. I just want to be able to find the objects that are on my stage.
mjg08
June 3rd, 2008, 12:57 PM
I understand your problem and Its exactly what I am lookin for too
budkin
June 3rd, 2008, 04:00 PM
I'm struggling with this same issue right now and can't seem to find the answer. Basically, how would I reference a movieclip loaded at runtime that is inside another movieclip that is also loaded at runtime?
cshaheen
June 3rd, 2008, 08:41 PM
A clean way to get around this error would be to package all the contents on your stage currently into one movieclip, and then export it for actionscript (in the right-click, linkage menu option in the Library). Then you can remove the original off the timeline, and create one via actionscript and add it to the stage. Then you have a singular reference to all that predefined content in your movieclip, and you can access any property of its contents intuitively, from frame 1 on the main timeline:
var mainClip_mc:MovieClip = new mainClip();
this.addChild(mainClip_mc);
mainClip_mc.mypicture_mc.my_image_jpg.alpha = .5;
The way root works now is quite different, and explained much better than I could in this thread (http://www.kirupa.com/forum/showthread.php?p=1952513)
level4designs
June 3rd, 2008, 10:47 PM
ok, this does work IF it is on the main timeline and typed into a frame
productsmain_mc.products_mc.mytext_txt.text = "test";
so it does reference other movie clips within movie clips, similar to what AS2 does in that respect...
now, I want that same thing within my class file. and it errors out and says this:
ReferenceError: Error #1065: Variable productsmain_mc is not defined.
cshaheen: I like your idea, and want to do it, but my software needs to be on stage for my customers, rather than in the library, although I do understand that method... thanks for the suggestion...
so if the above code did work in my timeline actionscript, how can I do something like that in my class file that is called on the main timeline as well. I thought my code would be treated as if it was on the main timeline.
do I need to build my interface on frame 1, then call my classes on frame 2, so they exist? I went into publish settings and made sure that the "Automatically declare stage instances" was checked, just assumed it would do that all for me, but I also have them all with instance names as well... any help is appreciated...
level4designs
June 4th, 2008, 12:52 PM
ok, finally have it figured out...
stage must be passed around to each class involved, just like a variable... each new class I make has no idea that stage exists...
I made a little function like this, as senoculars article presents:
var stage:Stage;
//sets the stage reference here
public function setStage(stageRef:Stage) {
stage = stageRef;
}
then I have to call it before each class method I call so I set the stage, then call my methods if they are to handle something on the stage. for example in a class for search, I set stage and then I call my function.
searchs.setStage(stage);
searchs.handlesearchresults(searchresults);
now all my classes can see the stage...
I use this inside each method to actually reach my stuff.
stage.getItemAt(0).productsmain_mc.products_mc.myt ext_txt.text = "test";
Is there a way, anybody know, to eliminate the "stage.getItemAt(0)" and just use a variable like mainTimeLine or something like that? I know I"m passing a Stage reference through the classes, anything else I could use there?
thanks everyone for the help...
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.