View Full Version : help with nested movie clips?

09-01-2007, 04:57 PM
Okay Ė Iím a relative newbie to OOP, have spent the last two months teaching myself AS3 for an interactive art installation. I know the code Iíve been writing is very basic and probably not the most efficient way to do things, but so far itís been working and with the time constraints Iím under thatís the most important thing.

But Iíve been stuck for almost a week now on two particular problems:

1. How do I access variables and objects from within nested timelines? Specifically I have 3 arrays that have been created on the first frame of the actions layer of the main timeline, as well as several movie clips created on the MTL that themselves contain nested movie clips. All the arrays and movieclips Iím trying to access from nested timelines have been created outside of any functions Ė that should make them global, right? And Iíve tried pre-pending both root and parent to their names from within the controlling clip (and parent.parent, if the controlling clip is double-nested), but I keep getting either a null object error or, in the case of the array trace, an undefined value.

2. Iím also having trouble referring to a nested movie clip on the main timeline. If a movie clip called sceneMarker01_mc is on frame 10 of a movie clip called sceneMarkers_mc, and

a. sceneMarker01_mc is an instance of mc_sceneMarker01
b. sceneMarkers_mc is an instance of mc_sceneMarkers thatís been created and added to the display list outside of any functions

shouldnít I be able to refer to sceneMarker01_mc within a function on the MTL like this?

if (sceneMarkers_mc.sceneMarker01_mc.currentFrame = sceneMarkers_mc.sceneMarker01_mc.totalFrames)

or perhaps like this?

if (sceneMarkers_mc.sceneMarker01_mc[currentFrame] == sceneMarkers_mc.sceneMarker01_mc[totalFrames])

Neither is working; I get the following error both times:

TypeError: Error #1010: A term is undefined and has no properties.

For those of you who might have a little more time on their hands, hereís some additional info about the project. Maybe you can suggest a solution to the overall problem that Iím trying to solve:

The installation is a table with an RFID reader attached, and 78 RFID cards. Each cardís unique bar code has a movie clip associated with it. The user choses 10 cards at random and scans them over the RFID reader, and when theyíve all been chosen the 10 movie clips are played in sequential order, with an interstitial movie clip between each that says ďAct 1,Ē ďAct 2,Ē etc.

Iíve got the scanning and storing of the bar codes working fine; itís the navigation between the card movie clips and the interstitial (scene marker) movie clips that Iím having trouble with.

Here are the relevant objects Iím working with:

var countingArray:Array = new Array();

var playlistArray:Array = new Array();

var deckArray:Array = new Array();
deckArray[0] = "3000324410";
deckArray[1] = "0a00b68c65";
deckArray[2] = "3000c1e570";
deckArray[3] = "0103c5c32e";
deckArray[4] = "0f00b347f5";
deckArray[5] = "0d00555426";
deckArray[6] = "010646a58d";
deckArray[7] = "0f0055518d";
deckArray[8] = "0f00ad6cf8";
deckArray[9] = "30000d34f8";
deckArray[10] = "0a00b66e84";
deckArray[11] = "0f000f303a";
deckArray[12] = "01065e9928";
deckArray[13] = "30000d0b46";
deckArray[14] = "0e00ec1418";

var sceneMarkers_mc:mc_sceneMarkers = new mc_sceneMarkers();

var masterCards_mc:mc_masterCards = new mc_masterCards;

The countingArray is where the bar code values are stored as theyíre scanned in.

The deckArray values are the electronic bar codes associated with all the RFID tags (there will ultimately be 78; this is just the test version).

On the 10th scanned tag, all the elements in countingArray are sliced into playlistArray. Iím creating playlistArray because I intend to shift through it, knocking each tag value into the [0] position one at a time, and I need to keep the length of countingArray at 10 to make code further up still work. I also want to use the declining length of playlistArray as a variable for movieclip navigation, though I havenít worked that bit into my code yet.

The sceneMarkers_mc is where the interstitial movie clips live. Itís a 10-frame mc with a 50-frame mc on each frame. The frame numbers of sceneMarkers_mc match the length of playlistArray in reverse order, so sceneMarkers_mc(10) contains sceneMarker01_mc -- the movie clip that plays the scene marker for ďAct 1.Ē Frame 9 holds sceneMarker02_mc, etc.

The masterCards_mc is a 78-frame movie clip with a multi-frame movie clip on each frame. This is where the movies associated with the bar codes live. The frame numbers of masterCards_mc match the index values of deckArray; ie, masterCards_mc(10) contains the movie clip that should play if the RFID tag with the bar code 0a00b66e84 (which is at deckArray[10]) is chosen.

Thereís a movie clip that counts down the progress as each card is selected and then fades out on the 10th card; from there Iíve tried a bunch of different approaches to navigating between the correct frames of sceneMarkers_mc and masterCards_mc, but I keep running into errors and scope issues. Lines 301 through 315 in the file Iíve attached get the application to go from the countdown screen to the first scene marker, but from there I havenít been able to devise a workable way to get things to play in the right order without overlap. You can see the direction I was trying to go in with the commented-out playCard01 function at the end, but Iím getting an error trying to use the nested mc reference. Iíve also tried putting array shifts and gotoAndPlay commands on the final frames of the nested masterCards_mc and sceneMarkers_mc movies, but I just get the errors I mentioned at the top of this post.

Iím so discouraged at this point. I feel like I need to become a much more advanced programmer than I can become in 2 weeks time in order to finish this project.

Any help would be much, much appreciated.

(The file I uploaded is just the code; the full .fla is available here:


though it's pretty useless for debugging unless you have an RFID reader or you replace the RFID functions with mouse events or something.)

09-01-2007, 07:44 PM
Okay, after spending the better part of the day putting that post together, then re-reading a bunch of stuff on root, parent and timeline, I've figured out my problem.

Or at least, this round of problems.

I'm sure I'll be back with more, heh.