Difference between revisions of "Talk:Gallery.as"

From Organic Design wiki
m
(Another way)
Line 2: Line 2:
 
:You can't create a movieclip as a child of a non-movieclip because ''createEmptyMovieClip'' is only a method of the ''MovieClip'' class. So you can't make a new movieclip with ''new()'', it has to be one of the movieclips own methods.
 
:You can't create a movieclip as a child of a non-movieclip because ''createEmptyMovieClip'' is only a method of the ''MovieClip'' class. So you can't make a new movieclip with ''new()'', it has to be one of the movieclips own methods.
 
:But the movieclip object does come with a method to inherit from other objects which is the ''registerClass'' method, but you have to associate it with another movieclip object or it will no longer be one itself (although, you could use a normal object if it inherited the movieclip properties with <tt>obj.prototype=new movieclip</tt>). --[[User:Nad|Nad]] 15:07, 10 Apr 2006 (NZST)
 
:But the movieclip object does come with a method to inherit from other objects which is the ''registerClass'' method, but you have to associate it with another movieclip object or it will no longer be one itself (although, you could use a normal object if it inherited the movieclip properties with <tt>obj.prototype=new movieclip</tt>). --[[User:Nad|Nad]] 15:07, 10 Apr 2006 (NZST)
 +
::You can side-step all these complex methods but still use prototypes by just having the movieclip as a property of the object (like object.swf), but the movieclip itself could be created in _root or whatever by your prototype's constructor, but just a ref to it is in your object's swf property. eg...
 +
<pre>
 +
    function myProtoConstructor( parentMovieClip, layer ) {
 +
        var name = 'swf'+layer; // involving layer makes a unique name within the parent context
 +
        parentMovieClip.createEmptyMovieClip( name, layer ); // give it a unique name
 +
        this.swf = parent[name];
 +
        }
 +
</pre>
 +
::then when you go (eg.) <tt>something = new myProtoConstructor( _root, 100 )</tt>you use ''something'' like a normal object, and adjust its corresponding movieclip via its ''swf'' property, eg. <tt>something.swf._alpha = 50</tt>.

Revision as of 05:05, 10 April 2006

I think i'm on the right track. Seems there is some scope or nesting problem. I have successfully created a prototype movie clip but it will not show on the stage.--Rob 14:49, 10 Apr 2006 (NZST)

You can't create a movieclip as a child of a non-movieclip because createEmptyMovieClip is only a method of the MovieClip class. So you can't make a new movieclip with new(), it has to be one of the movieclips own methods.
But the movieclip object does come with a method to inherit from other objects which is the registerClass method, but you have to associate it with another movieclip object or it will no longer be one itself (although, you could use a normal object if it inherited the movieclip properties with obj.prototype=new movieclip). --Nad 15:07, 10 Apr 2006 (NZST)
You can side-step all these complex methods but still use prototypes by just having the movieclip as a property of the object (like object.swf), but the movieclip itself could be created in _root or whatever by your prototype's constructor, but just a ref to it is in your object's swf property. eg...
    function myProtoConstructor( parentMovieClip, layer ) {
        var name = 'swf'+layer; // involving layer makes a unique name within the parent context
        parentMovieClip.createEmptyMovieClip( name, layer ); // give it a unique name
        this.swf = parent[name];
        }
then when you go (eg.) something = new myProtoConstructor( _root, 100 )you use something like a normal object, and adjust its corresponding movieclip via its swf property, eg. something.swf._alpha = 50.