Hi Helen,

I'm aware of the lack of private (and protected) constructors.
What I'm talking about is something different though.
It's about assets (movieclips or whatever) that are part of a class, but placed 
on stage rather than created through code.

Let's say you have a movieclip "MyComponent" with a class attached to it: 
"MyComponent".
Inside the MyComponent movieclip you drop a Button component, instance name: 
"my_btn"

The first annoying thing (IMO) is that you cannot (do not have to) declare the 
instance in your class (which is the error Matt ran 
into, because he did declare the instance, which results in a compile error).


//AS2 - working code
class MyComponent extends MovieClip {

    private var my_btn:mx.controls.Button;

    function MyComponent() {
        //
    }

    function onLoad() {
        trace(my_btn);
    }
}

// AS3 - throws error because instances on stage are automatically declared
// Compiler Error: a conflict exists with definition my_btn in namespace 
internal
package {

    import flash.display.MovieClip;
    import fl.controls.Button;

    public class MyComponent extends MovieClip {

        private var my_btn:Button;

    }

}

So to get rid of that, you have to go into the publish settings and disable 
this new (annoying) feature:
Publish Settings > Flash tab > Settings > uncheck "Automatically declare stage 
instances".

With that done, you'll now get the following error:
ReferenceError: Error #1056: Cannot create property my_btn on MyComponent.

That's gibberish for saying: "you have to make the my_btn instance public 
instead of private".

// AS3 working code - with declare stage instances disabled
package {

    import flash.display.MovieClip;
    import fl.controls.Button;

    public class MyComponent extends MovieClip {

        public var my_btn:Button;

    }

}

Now, how silly is that..

regards,
Muzak

----- Original Message ----- 
From: "Helen Triolo" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, July 13, 2007 3:10 AM
Subject: Re: [Flashcoders] Accessing MovieClips on a timeline from an AS3 class


> Colin Moock's book says it's because of adherence to ECMAScript 4, and points 
> to this page for explanation: 
> http://kuwamoto.org/2006/04/05/as3-on-the-lack-of-private-and-protected-constructors
>
> Helen
>
>
> Francis Cheng wrote:
>
>>I'm guessing that the odd reason has something to do with the behavior
>>of the "private" attribute in AS2 versus AS3. As most of you are aware,
>>the "private" attribute in AS2 only restricts access at compile time. In
>>AS3, however, "private" restricts access at both compile time and
>>runtime. Just a guess, though, I could be barking up the wrong tree.
>>
>>Francis
>>
>>-----Original Message-----
>>From: [EMAIL PROTECTED]
>>[mailto:[EMAIL PROTECTED] On Behalf Of Muzak
>>Sent: Thursday, July 12, 2007 5:21 PM
>>To: [email protected]
>>Subject: Re: [Flashcoders] Accessing MovieClips on a timeline from an
>>AS3 class
>>
>>
>>>This means that you either have to declare the variables yourself (and
>>>
>>they have to be public, by the way)
>>
>>>or declare the class as dynamic so that the variables can be added at
>>>
>>runtime (specifically, at the time the
>>
>>>assignment statements are executed).
>>>
>>
>>I think the "has to be public" thing is one of the most annoying things
>>that has changed between AS2 and AS3.
>>In AS2 you can place assets on stage and declare them as private in your
>>class.
>>In AS3 this is not allowed/possible for some odd reason.
>>
>>regards,
>>Muzak
>>


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to