A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: How to assign a custom class to multiple kinds of movieclips

  1. #1
    Senior Member
    Join Date
    Mar 2005
    Posts
    206

    resolved How to assign a custom class to multiple kinds of movieclips

    So on my stage and library, I have a movieclip for each state...named as STATE_AK, STATE_IA, STATE_NY, and so forth, inside the library...the clips are then placed on the stage

    I've created a class called State.as, and have linked each of the state movieclips to this class.


    How should I write the State class definition? So far, what I have is:

    Code:
    package{
    
    import flash.display.MovieClip;
    
        
    	public class State extends MovieClip{
    		...
                    public function State(){
                       ...
                    }
    
                    public function grow(){
                       this.scaleX = this.scaleY = 2.0;
                    }                
    
    	}
    }
    I'm not sure how to write the class so that it takes the existing movieclip as *the* movieclip, if that makes sense...so that the function "grow" doubles the size of the state.

    I get an error like this:

    TypeError: Error #1010: A term is undefined and has no properties.
    at State/size()
    at State$iinit()
    at flash.display::Sprite/flash.display:Sprite::constructChildren()
    at flash.display::Sprite$iinit()
    at flash.display::MovieClip$iinit()
    at US_BETA_fla::STATES_US_1$iinit()
    at flash.display::Sprite/flash.display:Sprite::constructChildren()
    at flash.display::Sprite$iinit()
    at flash.display::MovieClip$iinit()
    at US_BETA_fla::MainTimeline$iinit()
    Last edited by dcnguyen; 09-09-2008 at 12:09 PM.

  2. #2
    Member
    Join Date
    May 2008
    Posts
    49
    If your working with classes, you will need to import your main.as into the flash IDE document class.

    From your main.as you will need to create an instance of your MC class. IE var mcInstance1:MovieClip = new REPLACEWITHINSTANCEOFMC();
    addChild(mcInstance1); // since your instance contains display objects, to see them you must add the isntance to the stage.

    Now from the class you made.

    PHP Code:
    package{

    import flash.display.MovieClip;
    import MOVIECLIPHERE;

        public class 
    State extends MovieClip{
        public var 
    _img:MovieClip;

                    public function 
    State():void{
                      
    _img = new MOVIECLIPHERE();
                      
    addChild(_img);  now when you create the instanceit will display and image of whats imported.  so when you addChild this isntance from mainit will show the graphic.

                    }

                    public function 
    grow():void{
                       
    this.scaleX this.scaleY 2.0;  //you can use this to change the instance which changes ALL the graphics.  If you only have one graphic in this instance you'll be fine.  But if you have multiple objects like text fields, pictures, it would be best to change this, to the variable for the image.  In my example that would be _img.scaleX = this.scaleY = 2.0.  Note:  I would probably do scaleY *= 2.0 but that also depends on how you set everything else out.
                    
    }                

        }


    Hope this helps!

  3. #3
    Senior Member
    Join Date
    Mar 2005
    Posts
    206
    Thank you, yes the addChild thing was what I needed.

  4. #4
    Member
    Join Date
    May 2008
    Posts
    49
    glad i could help.

  5. #5
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    923
    (never mind I missed something)
    Last edited by realMakc; 09-10-2008 at 04:39 PM.
    who is this? a word of friendly advice: FFS stop using AS2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center