PDA

View Full Version : storing initial position of MC



lunatic
April 17th, 2004, 01:07 AM
Okay maybe its because I've been working on this all day and can't think straight any longer but this seems like it should be really obvious and I'm getting frustrated that I can't think of how to do it. :m:

I have a movie clip sitting just off stage. When the file is first launched I want to record the x position of this movie clip in a variables, say startX. When a button is pressed (and there are several of these) I am using Voetsoejba's easing code (brilliant) twice, once to move an MC just in the x direction (easeX):
(on the main timeline, whre movetxt and content are the two MCs)


//record initial positions
menux = movetxt._x;
menuy = movetxt._y;
_global.startX = getProperty(_root.content, _x);
_global.startY = getProperty(_root.content, _y);
MovieClip.prototype.easeX = function(to) {
this.onEnterFrame = function() {
this._x = to-(to-this._x)/1.3;
if (this._x>to-1 && this._x<to+1) {
delete this.onEnterFrame; }
};
};

and another to move another mc in both x and y directions (ease):


//also on main timeline
MovieClip.prototype.ease = function(x, y) {
this.onEnterFrame = function() {
this._x = x-(x-this._x)/1.3;
this._y = y-(y-this._y)/1.3;
if (this._x>x-1 && this._x<x+1 && this._y>y-1 && this._y<y+1) {
delete this.onEnterFrame;
this._x = x;
this._y = y;
}
};
};

on the button


on (release) {
//bunch of other stuff
_root.content.easeX(135.6);
_root.content.gotoAndPlay(2);
_root.content.holder.loadMovie("calendar.swf");
movetxt.ease(menux, menuy);
}

There is also, on the content box that eases in, a close button with this script to ease it back off the stage:


on(release){
_root.content.easeX(_global.startX);
_root.movetxt._visible = false;
_root.movetxt._x = menux;
_root.movetxt._y = menuy;
}


So here is what is happenning: first time you hit the button to load it works like a charm but when you hit the close button it eases mostly, but not all the way, off the screen. Hit a button again to bring back the content mc and it disappears completely. Hit it a third time and the content mc just appears in place where it should, it doesn't ease.

So what is going on? What am I doing wrong? :*( Is all this blather too complicated to sort out without an fla?

thanks for any help! :smirk:

Voetsjoeba
April 17th, 2004, 04:49 AM
It would indeed be handier to provide a FLA :)

McGiver
April 17th, 2004, 08:57 AM
yep, the fla would indeed be handier.
I read through the code, but i can't find anything wrong :/

lunatic
April 17th, 2004, 11:37 AM
Okay, here it is! Thanks so much for taking a look at it. I hope its not too confusing. The buttons with the code are on the drums (there are also three bells - one each on the three drums in the back row). However, the code I mentioned above is on the drum on the left in the back row (when you test the movie and roll over that drum it says "news"), the smallest of the 'standing' drums. The button is on the head of the drum and has an instance name of 'kenb'. THis is my working test. I have (I think) the same code on the next drum over, ('sanb'), the standing one in the middle but its that first one that i'm working with primarily.

Once I get it to work it will go on all the other drums as well.

Thanks so much! Oh, and for some reason the calendar loads but the text doesn't show up for the events. If someone wants to tackle that they can but that is a secondary issue for me right now! :sigh:

Cheers :pleased:

File is here: click me (http://home.comcast.net/~mkatzmoye/main.zip)

scotty
April 17th, 2004, 01:59 PM
I've had a quick look and I think if you remove frame 1 from your content mc, it's working.

scotty(-:

edit/ For your calendar problem, look in the as of the calender, the showActiveDays prototype, for _root.clip.output_txt.text.
Change this in:
_root.output_txt.text ;) \edit

lunatic
April 17th, 2004, 06:05 PM
To the rescue once again! Thanks so much Scotty - that did it!

:trout: <-- for forgetting I changed the name of the holder movie clip on the main file when I was going through the calendar code!

Thanks again!

scotty
April 17th, 2004, 06:27 PM
You're welcome, lunatic=)

lunatic
April 18th, 2004, 12:02 AM
I have another question if I may be so bold. You noticed in the file that the background image is b/w and when you roll over each drum there is an invisible button that triggers the color images to pop up.

Each color image is an mc. I have all the mcs in an array (say called drums). When the content MC eases in I want to disable all teh buttons so in addition to the code mentioned above I have added the following:


Button.prototype.enabled = false;

On the close button on the content MC I set it to true so the button are enabled when teh content MC slides back off stage.

So here is the problem. When the mouse rolls over or presses a button teh color image of the drum appears. When the content MC rolls in teh color drum MC is still there, underneath it and the buttons are now disabled. When you close the content MC and it slides out of view the color drum MC is still there. I put all the color MCs in an array so that on the close button I could add the following:


Button.prototype.enabled = true;
for (var i in drums) {
_root.drums[i]._visible = false;
}

but its not working. You have to roll over and roll off the button again to get the color image to go away.

Any thoughts? Is something wrong with my for loop? I'm still a little shaky on arrays so maybe thats the problem? :h:

Any help much appreciated! :ne:

scotty
April 18th, 2004, 05:44 AM
Don't know the exact code you're using, but this is working:

drums = [ken, san, dun, bell1, bell2, bell3, djem1, djem2, djem3];
for (var i in drums) {
_root.drums[i]._visible = false;
trace(_root.drums[i]._visible);
}

A usefull thread/post by Sen could be:
http://www.kirupaforum.com/forums/showthread.php?t=12082#post85182
(but maybe you've read this allready)

scotty(-:

lunatic
April 18th, 2004, 11:14 AM
Yeah, thats the exact code I"m using. :( Oh well, I guess I'll try something else. Thanks for trying! (-:

p.s. the trace returns an undefined . . .

scotty
April 18th, 2004, 11:19 AM
Or post your .fla with what you've got this far?

scotty(-:

lunatic
April 18th, 2004, 11:30 AM
Well heres the weird thing. If I put trace(_root.drums[0]) it returns the correct name (or any other number) as long as the trace is outside the for loop. If it is inside the for loop then I get "undefined'. Also, if I use trace(_root.drums[0]._visible) anywhere (inside or outside the for loop) then I get undefined . . .
:h: any clue as to what is going on? :s:

p.s. if this doesn't trigger any ideas then I'll gladly post the fla again . . .

scotty
April 18th, 2004, 11:39 AM
drums = [ken, san, dun, bell1, bell2, bell3, djem1, djem2, djem3];
Are the "objects" in your array without quotes?
With quotes you refer not to an object but to string, which can't have properties (someone please correct me if I'm wrong;) )

scotty(-:

lunatic
April 18th, 2004, 11:51 AM
Yes, I did have quotes around them! :P I think I had a previous fla that used them so I thought it was necessary.

Now the trace outside returns _level0.instancename or true outside the for loop (trace _root.drums[0] and trace _root.drums[0]._visible) but returns NOTHING (not even undefined) inside the for loop?

Why would a trace return nothing? Does that mean the code isn't executing? :-/

lunatic
April 18th, 2004, 11:55 AM
Smack me please . . . :trout: . . . .aaaah, that's better. I got it. :sigh: I just needed a _root in the for loop because I'm calling the code inside a heavily buried MC. So now it looks like:


for (var i in _root.drums) {
_root.drums[i]._visible = false;
}


Thanks for all your help Scotty!! :love: It was removing the quotes in the array that did it!

scotty
April 18th, 2004, 12:00 PM
LOL, I was just trying it here and found the same answer=)

And no problem, lunatic;)

scotty(-: