Groups | Blog | Home
all groups > flash actionscript > april 2006 >

flash actionscript : Hopefully simple question - control mc on frame 10 from root


ACB
4/19/2006 9:25:06 PM
I have a movieclip (instance name 'animation') that is ten frames long, each
frame is a keyframe containing a single PNG. This movieclip has a stop on
frame 1 and frame 10.

With an onPress event handler on another movieclip I am calling the movie of
10 PNGs to play forward or reverse depending on its current state. The
first time you press the button it plays forward, press it again and it
plays backwards. All is working great... except

On the last frame of the movieclip (the 10th frame) I have another movieclip
with an instance name 'record'.

How do I refer to the record movieclip with dot notation or associative
array notation assuming 'animation' is sitting on the _root timeline?

Right now I have tried:
animation.record and animation["record"], but it is not working as expected.

However, if I place the movieclip record on it's own layer with a keyframe
in frame 1 continuing through 10 then I am able to control the movie clip
with the notation above. So, how do I control a movieclip on frame 10 of a
nested movie clip?

THANKS!!!
amy

blemmo
4/20/2006 12:00:00 AM
Hi,

you can only control an instance when it exists on stage, so you can't control
'record' when 'animation' is on another frame than frame 10.
To set some properties of 'record' from root, you could set variables in
'animation', check on frame 10 for their value and change 'record' accordingly.
Direct access to 'record' from root is only possible in frame 10 of 'animation'.

hth,
blemmo
ACB
4/20/2006 9:15:02 AM

[quoted text, click to view]

Blemmo,

First off, thanks for answering. I see your posts around quite a bit and
appreciate people who have the knowledge and don't mind spreading it around.

I am relativley new to actionscript. I started using Flash 6 about five or
six years ago but I only did timeline tweens and did not touch the program
for a few years. Although I do have a background in OOP in several
languages so I have caught on quickly to as starting with mx2004.

One of the things I *hated* when I first started (esp. reading other's
files) was finding the code in all of the embedded MCs in the movie. So,
now, I have started doing all of my in-movie code on a single _root frame.
Then, after development I move it into an external as file. So I can't do
this, right?

The movieclip 'record' on frame 10 of 'animation' is a picture of a record.
When an mc is pressed the movieclip 'animation' plays from frame 1 to 10,
stopping on 10 where the movieclip 'record' resides. Now that the mc
'animation' is on frame 10 I want to activate an onPress event handler to
the 'record' mc. So, since 'animation' is on frame 10, should I be able to
control 'record'?

for simplicity's sake:

button1_mc.onRelease = function() {
this.onEnterFrame = function() {
animation.nextFrame();
if(animation._currentframe == 10) {
delete this.onEnterFrame;
animation.record.onPress = handleRecordPress;
}
}
}

function handleRecordPress() {
blah blah blah;
}

Thanks.





Oh well.


ACB
4/20/2006 9:37:42 AM
[quoted text, click to view]


It must have been too late when I was scripting last night - tried it again
and it works like I wanted.

Thanks.

blemmo
4/20/2006 5:05:57 PM
The code you posted should be ok, did you try if it works? If not, there's
probably a scope problem, try
animation.record.onPress = _root.handleRecordPress;
maybe it can't find the handleRecordPress function because of the various
scope changes in the code.
AddThis Social Bookmark Button