Difference between revisions of "Talk:Gallery.as"

From Organic Design wiki
(Another way)
m
Line 6: Line 6:
 
     function myProtoConstructor( parentMovieClip, layer ) {
 
     function myProtoConstructor( parentMovieClip, layer ) {
 
         var name = 'swf'+layer; // involving layer makes a unique name within the parent context
 
         var name = 'swf'+layer; // involving layer makes a unique name within the parent context
         parentMovieClip.createEmptyMovieClip( name, layer ); // give it a unique name
+
         parentMovieClip.createEmptyMovieClip( name, layer );
 
         this.swf = parent[name];
 
         this.swf = parent[name];
 
         }
 
         }
 
</pre>
 
</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>.
+
::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>. [[User:Nad|Nad]] 17:06, 10 Apr 2006 (NZST)

Revision as of 05:06, 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 );
        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. Nad 17:06, 10 Apr 2006 (NZST)