Skip to main content
Known Participant
August 12, 2006
Answered

attachMovie not working!!

  • August 12, 2006
  • 3 replies
  • 801 views
I can't get the attachMovie function to work and I set the Linkage on the symbol so it's not that...
here's my code...
This topic has been closed for replies.
Correct answer Newsgroup_User
> try:
>
> PourWater_btn.onRelease = function () {
> if(this._currentframe==1){ // assuming you only want to trigger your goto
> statement when _currentframe is 1.
> gotoAndPlay ("PourWater_Fe");
> }
> }

That's a good one. Or delete (or set to null) the onRelease handler of
PourWater_btn down the line. There are usually a number of ways to solve
your problems in ActionScript. If you "get" the idea of classes and
objects, you'll find you have a wealth of information right at your finger
tips. The _currentframe property kglad mentioned, for example ... it's a
property of the MovieClip class. Check out these classes, VaporAction! :)


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."



VaporAction,

> I want ElementFe_mc to fall to a table top when released...
> didn't think it would be hard to do, well, here's what I've
> tried...

Okay.

> ElementFe_mc.onRelease = function(): Void {
> this.stopDrag();
> if (ElementFe_mc._y < 412.4) {
> this._y++
> }
> }

Well, here's what you've got. The Button.onRelease or
MovieCip.onRelease event is dispatched when the user releases the mouse
after having clicked it. This only occurs once, unless the user clicks and
releases again.

So ... when the user releases, the following occurs: ElementVe_mc stops
dragging and its MovieClip._y property is incremented by one pixel (if it
happens to fall beneath 412.4 pixels at the time of the event).

I susped you want to increase the _y position as often as necessary,
rather than just once. To accomplish this, you'll have to continue
incrementing its value over time. You might, for example, set up a
MovieClip.onEnterFrame event handlers inside this onRelease handler ...

ElementFe_mc.onRelease = function(): Void {
this.stopDrag();
if (this._y < 412.4) {
this.onEnterFrame = function() {
this._y++;
}
}
}

Of course, you'll want a second if statement in there to determine when to
delete the onEnterFrame function. Make sense?


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


3 replies

Inspiring
August 14, 2006
>> this.attachMovie ("Element", "ElementFe_mc", this.getNextHighestDepth);
>
> should of course be:
>
> this.attachMovie ("Element", "ElementFe_mc", this.getNextHighestDepth());

But it's not working, I tell you!! ;)

The devil is in the details, and you caught one of many, Peter.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Inspiring
August 14, 2006
Even though you have now taken a different approach, in addition to David
and Kglad's responses, this:

> this.attachMovie ("Element", "ElementFe_mc", this.getNextHighestDepth);

should of course be:

this.attachMovie ("Element", "ElementFe_mc", this.getNextHighestDepth());

--
-------------------------------
Remove '_spamkiller_' to mail
-------------------------------


Inspiring
August 12, 2006
VaporAction,

> I can't get the attachMovie function to work and I
> set the Linkage on the symbol so it's not that...

It's important you realize the distinction between functions and
methods. attachMovie() is a method -- specifically, the
MovieClip.attachMovie() method. Functions, on the other hand, don't belong
to a particular class. You can think of functions as "free floaters."

So, attachMovie() only works when you invoke it on an instance of the
MovieClip class, commonly called a movie clip.

> Element1_btn.onRelease = function () {

If Element1_btn is a movie clip symbol, then you have a MovieClip
instance. If Element1_btn is a button symbol, then you have a Button
instance. As it happens, both classes, MovieClip and Button, feature an
onRelease event, so this would work in either cases.

> this.attachMovie ("Element", "ElementFe_mc", this.getNextHighestDepth);

Here, the global "this" property refers to the timeline or object it's
in. If this is a movie clip symbol, then "this" points to a MovieClip
instance -- and bingo, the MovieClip class features an attachMovie() method.
If this is a button symbol, then "this" refers to a Button instance -- and
the Button class does not feature an attachMovie() method.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Known Participant
August 12, 2006
quote:

Here, the global "this" property refers to the timeline or object it's
in. If this is a movie clip symbol, then "this" points to a MovieClip
instance -- and bingo, the MovieClip class features an attachMovie() method.
If this is a button symbol, then "this" refers to a Button instance -- and
the Button class does not feature an attachMovie() method.


So how would I attachMovie with a button?
kglad
Community Expert
Community Expert
August 12, 2006
to what timeline do you want to attach "Element"? if you want to attach it to the timeline that contains your button or _root use: