all groups > flash actionscript > november 2006 >
You're in the

flash actionscript

group:

OOP Help


OOP Help crispymuscat
11/24/2006 5:37:38 PM
flash actionscript:
Please could someone explain to me as clearly as possible how I instantiate an
object in this situation

i have

holder.createEmptyMovieClip("holder",getNextHighestDepth());

i want to instantiate a another object (from a custom built class which
extends the Movieclip class)
within this holder level.

this is where i am confused and asking for guidance:

var _root.holder.namevariable:CustomObject= new CustomObject(); // doesn't
work--seems trashy

or should it be

var namevariable:CustomObject= new _root.holder.CustomObject(); // doesn't
work either--seems trashy


because if i just say,

var namevariable:CustomObject= new CustomObject();

the object is not sitting in the holder container, therefore the stacking
order is wrong






Re: OOP Help LuigiL
11/24/2006 9:37:17 PM
When you extend the MovieClip Class there needs to be a one-on-one relationship
with a movieclip in the library which is ilnked to the class using the
'Linkage' option. You use attachMovie() to instantiate a new instance.
->holder.createEmptyMovieClip("holder",getNextHighestDepth());
->holder.attachMovie("CustomObject","new_instance_name",depth);
target the CustomObject with:
holder.new_instance_name

CustomObject is the name you provide in the 'Linkage' identifier.
Re: OOP Help crispymuscat
11/25/2006 10:47:17 AM
:sad;
Thanks for the reply---i hope i understand the display objects , but how do
you target other objects such as arrays etc and is it necessary to be concerned
with where they are instantiated, ie for the sake of being consistent, i would
like to keep all objects within the same container, so that i dont have display
objects in one container and related array objects sitting on in the _root.
So if i am wanting to declare a new variable within the _root.holder.
----container,
what is the correct form for this
var bing:Array = new Array(); how do i keep the array within the holder
container
or
var _root.holder.bing:Array = new Array();


Re: OOP Help LuigiL
11/25/2006 5:16:33 PM
Attached an example of a class that extends the MovieClip Class. On the stage
(or use attachMovie() to instantiate a new instance) I have a box with an
instance name 'box_mc'. The mc is linked to the class in the library using the
Linkage option and the AS2 class is 'Box'. Inside the box mc I have a text_mc
and in the text_mc is a dynamic text field with an instance name 'test_txt'.

The class fade in the box and then sets the text for the text field. When that
is done it instructs the _root to go to and stop on frame 5. There I have code
on the timeline. Using the instance name of the box I can call a public method
of the class:
box_mc.doRotate();



//Box.as
import mx.transitions.*;
import mx.transitions.easing.*;

class Box extends MovieClip {

//class definition
//assets on the stage
private var text_mc:MovieClip;
//array to hold content
private var text_array:Array;

//class body
public function onLoad(){
trace("Box class called.");
text_array=new Array();
text_array[0]="The Box is here!";
showBox();
}

public function doRotate():Void{
rotateBox();
}

//private members
private function showBox():Void{
var thisObj:Box=this;
var aTween:Tween=new Tween(this,"_alpha",Strong.easeOut,0,100,.7,true);
aTween.onMotionFinished=function():Void{
thisObj.text_mc.test_txt.text=thisObj.text_array[0];
thisObj._parent.gotoAndStop(5);
};
}

private function rotateBox():Void{
var rTween:Tween=new Tween(this,"_rotation",Regular.easeOut,0,-180,2,true);
}
}
AddThis Social Bookmark Button