;

PDA

Click to See Complete Forum and Search --> : How to assign a custom class to multiple kinds of movieclips


dcnguyen
09-09-2008, 12:05 PM
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:


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()

cyberoptics
09-09-2008, 01:39 PM
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.


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 instance, it will display and image of whats imported. so when you addChild this isntance from main, it 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!

dcnguyen
09-09-2008, 02:13 PM
Thank you, yes the addChild thing was what I needed.

cyberoptics
09-09-2008, 11:42 PM
glad i could help. :)

realMakc
09-10-2008, 04:36 PM
(never mind I missed something)