Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to control MC after attachMovie ? 1

Status
Not open for further replies.

hovercraft

Technical User
Jun 19, 2006
236
US
Code:
onClipEvent(load)
{
	this._visible=false;
}


onClipEvent(enterFrame)
{
	if (Key.isDown(Key.CONTROL))
		{_root.attachMovie("mylaser", "mytest1", _root.getNextHighestDepth(), {_x:200, _y:200});
		
		}
}

After the instance of mylaser called mytest1 is created by pressing the control button, how and where would I put the code to animate the movie clip. I would like to simply reposition mytest1 so that it moves along it's y axis from the creation point (200,200) and move towards the top of the screen.

Thanks,
Dave
 
I don't know why you're using "onClipEvent", but anyway here's very basic example:
Code:
onClipEvent (enterFrame) {
	if (Key.isDown(Key.CONTROL) && laser == undefined) {
		laser = _root.attachMovie("mylaser", "mytest1", _root.getNextHighestDepth(), {_x:200, _y:200});
	}
	laser._y--;
}

Kenneth Kawamoto
 
Thanks Ken. I should have been a little more clear when I asked the question.

The onClipEvent is on a "control" object or in this practice example it's the ship its self.
The control object checks to see if a button is pressed to create the copy of the movie clip "mylaser".

Is it possible to program the onClipEvent of the instance "mylaser01" from within the "control" object (the object that gave the command to create the instance)?

Could this be accomplished with a "With" statement?

For example after the instance is created, have a statement in the onClipEvent (enterFrame) of the ship say:

Code:
with (_root.mylaser01) {onClipEvent (enterFrame){this._y = this._y -10;}}

The whole reason for this is because the object "mylaser01" doesn't reside on the stage (or even exsist) until it is created by the user pressing the CONTROL button. But without it being on the stage I can't program it's actions.

I'm probably over complicating this, but any help would be great.
Thanks again,
Dave
 
Code:
onClipEvent (enterFrame) {
	if (Key.isDown(Key.CONTROL) && !_root.mylaser01) {
		_root.attachMovie("mylaser", "mylaser01", _root.getNextHighestDepth(), {_x:200, _y:200});
		_root.mylaser01.onEnterFrame = function() {
			this._y -= 10;
		};
	}
}
(I would do it differently though.)


Kenneth Kawamoto
 
Wow, awesome! Thank you!

What sort of approach would you take?
 
My approach would be to control everything from one place - either from main timeline and/or external Class files. Attaching scripts to MovieClips and Buttons with "onClipEvent()" and "on()" handlers is pre-Flash 5 methodology and has number of uncool issues.
You must avoid attaching ActionScript code to objects ... This practice is strongly discouraged ...
From "ActionScript 2.0 Best Practices"

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top