Assignign an mc to a class

Hi there,

I have created a dynamic image viewer which loads images and allows the user to expand and collapse the image, and its text box. Currently i have the actions in the onenterframe event of a pictureviewer_mc instance, and then set the status to open close, etc and use an if statement to move the pictureviewer depending on tis status. Now i want to be able to have x amount of picture viewers, dynamically, so i have migrated the onclipevents to a class, which extends the movieclip class.

Now, i have an MC in my libarary called PictureViewerTemplate
this contains the following

PictureViewerTemplate.holder_mc = holds image
PictureViewerTemplate.Textbox = holds text

which i have assigned using the linkage attribute, it to associated with the class i have written below. As i understand, any instances of PictureViewerTemplate will have available all properties and methods of my PictureViewer class.

Ok, so now what i need to know, is once i have placed my instance on the timeline and called it PictureViewer_MC, how do i call the constructor to initialise the object with the correct properties. Do i do it in the onload event for the mc itself, from the main time line?

Also, i have seen alot of easing scripts with math.abs and math.round but which one should i use and why.

I would be greatful if someone could have a look at my class and comment on it, like i said its my first one in actionscript though i am a programmer in other languages.

Does flash actionscript classes support composition? just wondered

Also, is it the norm to have say, the text box control methods in the pictureviewer, or should the textbox be a seperate Textbox object within the PictureViewer_mc instance.

Below is my new class,and below it is the original onenterframe code

Thnaks in advance

Jamo

class PictureViewer extends MovieClip {
 //current status which can be checked before methods are called
 private var Status:String = 'Closed';
 // the Open x position of the object
 private var OpenXpos:Number = 0;
 //The close position of the object (off stage)
 private var CloseXpos:Number = 0;
 //The display position of the viewer.
 private var DisplayXpos:Number = 0;
 //open speed 1 fastest
 private var OpenSpeed:Number = 0;
 //close speed 1 fastest
 private var CloseSpeed:Number = 0;
 //status of the text box
 private var TextboxStatus:String = 'Closed';
 function PictureViewer(SXpos:Number, SYpos:Number, OXPos:Number, CXPos:Number, DXpos:Number, OSpeed:Number, CSpeed:Number, St:String) {
  this._x = SXpos;
  this._y = SYpos;
  this.Status = St;
  this.OpenXpos = OXPos;
  this.CloseXpos = CXPos;
  this.DisplayXpos = DXpos;
  this.OpenSpeed = OSpeed;
  this.CloseSpeed = CSpeed;
  this.Status = 'Closed';
 }
 //the open function moves the viewer to the open position depicted in the OPos property
 function OpenMe() {
  this.onEnterFrame = function() {
   if (this._x<this.OpenXpos) {
	this._x += (this.OpenXpos-this._x)/this.OpenSpeed;
   }
   if (Math.round(this._x) == this.OpenXpos+1) {
	this.Status = 'Opened';
	stop();
   }
  };
  function Close() {
   this.onEnterFrame = function() {
	if (this._x>this.CloseXpos) {
	 this._x += (this.CloseXpos-this._x)/this.CloseSpeed;
	}
	//check if current xpos = Picture1_OpenXpos
	if (Math.round(this._x) == this.CloseXpos) {
	 this.Status = 'Closed';
	 stop();
	}
   };
  }
  //opens the viewer to full width, and brings in text box
  function Display() {
   this.onEnterFrame = function() {
	if (this._x<this.DisplayXpos) {
	 this._x += (this.DisplayXpos-this._x)/this.OpenSpeed;
	}
	//check if current xpos = Picture1_OpenXpos, set to opened
	if (Math.round(this._x) == this.DisplayXpos) {
	 //send the controller clip to frame 1, which will tell the text box to expand
	 ExpandText();
	 this.Status = 'Displayed';
	 stop();
	}
   };
  }
  //moves the viewer off stage, and resets its text box 
  function Reset() {
   this.onEnterFrame = function() {
	if (this._x>this.CloseXpos) {
	 this._x += (this.CloseXpos-this._x)/this.CloseSpeed;
	}
	if (Math.round(this._x) == this.CloseXpos) {
	 //re open the text box
	 OpenMe();
	 stop();
	}
   };
  }
  //removes the onEnterFrame event
  function Stop() {
   delete this.onEnterFrame;
  }
  //open the objects text box
  //currently uses hard coded value (375) will replace with a function which first determnes the width of
  //this, then the width of itself, and moves itself to align with the left of this.
  //will also need to create a method to load text into the text box from an external source
  //which will initially be a txt file, but will look to use a ds in the future or xml
  function ExpandText() {
   this.TextBox.onEnterFrame = function() {
	if (this.TextBox._x<(this._x-375)) {
	 this.TextBox._x += ((this._x-375)-this.TextBox._x)/5;
	}
	if (Math.round(this.TextBox._x) == (this._x-375)) {
	 //send the controller clip to frame 3, which will tell the text box to expand
	 TextboxStatus = 'expanded';
	 StopText();
	}
   };
  }
  //close text box
  function CollapseText() {
   this.TextBox.onEnterFrame = function() {
	if (_root.pic1_mc.TextBox._x<(_root.pic1_mc._x-375)) {
	 _root.pic1_mc.TextBox._x += ((_root.pic1_mc._x-375)-_root.pic1_mc.TextBox._x)/5;
	}
	if (Math.round(_root.pic1_mc.TextBox._x) == (_root.pic1_mc._x-375)) {
	 //send the controller clip to frame 3, which will tell the text box to expand
	 TextboxStatus = 'collapsed';
	 StopText();
	}
   };
  }
  //removes the current asset from this.holder_mc
  function UnloadAsset() {
   this.holder_mc.unloadMovie();
  }
  // params,  Prefix, path to image
  //   AssetName, imagename
  function LoadAsset(Prefix:String, AssetName:String) {
   loadMovie(Prefix+'/'+AssetName+'.jpg', 'this.holder_mc');
  }
  //remove the onenterframe event from the text box to stop it
  function StopText() {
   delete this.TextBox.onEnterFrame;
  }
  function getStatus():String {
   return Status;
  }
  function getTextboxStatus():String {
   return TextboxStatus;
  }
 }
}
 
 
 
//the code below is what is currently applied to each pictureviewer instance, 
//whcih is a pain
 
onClipEvent (load) {
 this._x = -258;
 this._y = 250;
 var Status:String = 'Closed';
 var OpenXpos:Number = -63;
 var CloseXpos:Number = -258;
 var DisplayXpos:Number = 245;
 var OpenSpeed:Number = 10;
 var CloseSpeed:Number = 4;
 //1 fastest - 10 slowest
}
onClipEvent (enterFrame) {
 if (Status == 'Open') {
  //check if current xpos  < Picture1_OpenXpos, if so carry out movement
  if (_root.pic1_mc._x<OpenXpos) {
   _root.pic1_mc._x += (OpenXpos-_root.pic1_mc._x)/OpenSpeed;
  }
  //check if current xpos = Picture1_OpenXpos, set to opened
  if (Math.round(_root.pic1_mc._x) == OpenXpos+1) {
   Status = 'Opened';
  }
 } else if (Status == 'Close') {
  //check if current xpos  > Picture1_OpenXpos, if so
  if (_root.pic1_mc._x>CloseXpos) {
   _root.pic1_mc._x += (CloseXpos-_root.pic1_mc._x)/CloseSpeed;
  }
  //check if current xpos = Picture1_OpenXpos
  if (Math.round(_root.pic1_mc._x) == CloseXpos) {
   Status = 'Closed';
  }
 } else if (Status == 'Display') {
  //check if current xpos  < Picture1_OpenXpos, if so carry out movement
  if (_root.pic1_mc._x<DisplayXpos) {
   _root.pic1_mc._x += (DisplayXpos-_root.pic1_mc._x)/OpenSpeed;
  }
  //check if current xpos = Picture1_OpenXpos, set to opened
  if (Math.round(_root.pic1_mc._x) == DisplayXpos) {
   //send the controller clip to frame 1, which will tell the text box to expand
   _root.McControl.gotoAndStop(2);
   Status = 'Displayed';
  }
 } else if (Status == 'Reset') {
  //check if current xpos  < Picture1_OpenXpos, if so carry out movement
  if (_root.pic1_mc._x>CloseXpos) {
   _root.pic1_mc._x += (CloseXpos-_root.pic1_mc._x)/CloseSpeed;
  }
  if (Math.round(_root.pic1_mc._x) == CloseXpos) {
   Status = 'Open';
  }
 }
}