all groups > flash actionscript > august 2006 >
You're in the

flash actionscript

group:

AS 3 - Referencing and unloading child MC's


AS 3 - Referencing and unloading child MC's Ignitrix
8/7/2006 10:30:03 PM
flash actionscript: I'm using AS 3 in Adobe Flash 9 Public Alpha.

I have a MovieClip named "RandImg" in my Library with an associated
"RandImg.as" class file. I'm placing this MC on the stage during design time.
This MC contains an instance of another MC with with the instance name of
"mcDefault". In the constructor of my RandImg.as class file, if I attempt to
reference mcDefault, I get the following error when I try to compile:
ReferenceError: Error #1056: Cannot create property mcDefault on RandImg.
How do I reference this movie clip in AS 3?


Also, if I want to remove mcDefault from memory, but keep the RandImg MC in
memory, in the "RandImg.as" class file would I just call: removeChild(
mcDefault ); ?


Thanks!
~JC

Re: AS 3 - Referencing and unloading child MC's butcho
8/8/2006 1:26:39 AM
Hi,

can you give us a bit of code ... that will help. And did you declare your
movieClip before (and outside of) the constructor? Like this i mean:

class RandImg{

private var mcDefault:MovieClip; // --> here it is .. mcDefault

public function RandImg(){ // --> cunstructor
trace("mcDefault path = " + mcDefault);
}
}

If mcDefault is not declare before and outside your constructor, its
impossible for your class to access it. Of course you are probably aware of
that .. but im trying to figure out what can be the problem .. just guessing.

So please give us some code and we will try to help!
Re: AS 3 - Referencing and unloading child MC's butcho
8/8/2006 1:27:43 AM
Hi,

can you give us a bit of code ... that will help. And did you declare your
movieClip before (and outside of) the constructor? Like this i mean:

class RandImg{

private var mcDefault:MovieClip; // --> here it is .. mcDefault

public function RandImg(){ // --> cunstructor
trace("mcDefault path = " + mcDefault);
}
}

If mcDefault is not declare before and outside your constructor, its
impossible for your class to access it. Of course you are probably aware of
that .. but im trying to figure out what can be the problem .. just guessing.

So please give us some code and we will try to help!
Re: AS 3 - Referencing and unloading child MC's butcho
8/8/2006 1:30:32 AM
Hi,

can you give us a bit of code ... that will help. And did you declare your
movieClip before (and outside of) the constructor? Like this i mean:

class RandImg{

private var mcDefault:MovieClip; // --> here it is .. mcDefault

public function RandImg(){ // --> cunstructor
trace("mcDefault path = " + mcDefault);
}
}

If mcDefault is not declare before and outside your constructor, its
impossible for your class to access it. Of course you are probably aware of
that .. but im trying to figure out what can be the problem .. just guessing.

So please give us some code and we will try to help!
Re: AS 3 - Referencing and unloading child MC's butcho
8/8/2006 1:33:53 AM
Hi,

can you give us a bit of code ... that will help. And did you declare your
movieClip before (and outside of) the constructor? Like this i mean:

class RandImg{

private var mcDefault:MovieClip; // --> here it is .. mcDefault

public function RandImg(){ // --> cunstructor
trace("mcDefault path = " + mcDefault);
}
}

If mcDefault is not declare before and outside your constructor, its
impossible for your class to access it. Of course you are probably aware of
that .. but im trying to figure out what can be the problem .. just guessing.

So please give us some code and we will try to help!
Re: AS 3 - Referencing and unloading child MC's Ignitrix
8/8/2006 11:16:14 PM
Thanks for responding butcho. I did, of course, declare protected var
mcDefault:MovieClip; before my constructor with the rest of my variables. I
did some more messing around, it appears that in Flash 9 and AS3, the problem
is that I can't actually have a named MC inside of a parent movie clip that has
an associated class..? If I place mcDefault on the stage inside of RandImg
during design time, the swf compiles properly. However, if I give the mcDefault
an instance name, and do nothing else different, then I get my compile error:
ReferenceError: Error #1056: Cannot create property mcDefault on RandImg. I
don't get it; this used to work great in AS2...
Re: AS 3 - Referencing and unloading child MC's Ignitrix
8/8/2006 11:51:40 PM
I found the answer in another thread:

http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=612&threadid=
1169750

Apparantly, you have to declare the variable as public (which seems
counter-inuitive since a big part of AS3 was better OOP and
data-encapsulation). But alas, at least for now, it will have to do...
AddThis Social Bookmark Button