MovieClips on stage and displayobject

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.mypicture_mc._alpha = 50;
_root.mymovieclip_mc.myinsidemovieclip_mc.mytext_txt.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…

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;


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.

I understand your problem and Its exactly what I am lookin for too

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?

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…

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.mytext_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…