Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Referencing A Nested Clip

Posted on 2004-11-21
22
Medium Priority
?
249 Views
Last Modified: 2010-04-07
Hello -

I'm relatively new to Flash.  Please forgive me if my terminoligy is incorrect.  Hope someone can help with this.

I have a main movie (page3.fla) which contains a movieclip with an instance name of "gallery".
Inside "gallery" is actionScript that loads images from a directory (taken from a tutorial located at http://www.kirupa.com/developer/mx/photogallery.htm).

This is a snippet from the "gallery" clip:

MovieClip.prototype.changePhoto = function(d) {
      this.pIndex = (this.pIndex+d)%this.pArray.length;
      if (this.pIndex<0) {
            this.pIndex += this.pArray.length;
      }
      this.onEnterFrame = fadeOut;
};

I'm trying to advance to the next image with the following code attached to a button instance in my main movie:

on (release) {
      gallery.changePhoto(1);      
}

It doesn't seem to be doing anything but frustrating the heck out of me!

I've tried _root.gallery and this.gallery and all kinds of other things but can't get any of it to work.

Any help would be GREATLY appreciated.

Thanks

B
0
Comment
Question by:ttist25
  • 11
  • 8
  • 2
  • +1
22 Comments
 
LVL 16

Expert Comment

by:vickerleung
ID: 12641718
ttist25,

try modify the code to this to check if it helps

function changePhoto (d) {
     this.pIndex = (this.pIndex+d)%this.pArray.length;
     if (this.pIndex<0) {
          this.pIndex += this.pArray.length;
     }
     this.onEnterFrame = fadeOut;
};
0
 
LVL 8

Expert Comment

by:sokhodom
ID: 12641865
ttist,
May i know how do you load your gallery movie to your main movies? Using loadMovie? Plz write code down.. Sometimes, the loadMovie might give you problem as well.
SokhodoM
0
 
LVL 1

Author Comment

by:ttist25
ID: 12641921
vicker -

Thanks for posting so quickly.  I tried the code you posted with negative results.  Can you tell me from what I posted if the reference I'm using "gallery.changePhoto(1)" is the correct syntax for refering to this?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:vickerleung
ID: 12641939
ttist,

If you wanna check if the function is called

function changePhoto (d) {
     trace ("success"); <========== add this line~~!!
     this.pIndex = (this.pIndex+d)%this.pArray.length;
     if (this.pIndex<0) {
          this.pIndex += this.pArray.length;
     }
     this.onEnterFrame = fadeOut;
};

If the text success prints out, that means a call success
If success then is the function content's problem instead

Vicker
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12641952
hi there ttist,

I had a look at the Kirupa tutorial you mentioned, if you're doing it as per the tutorial, your changePhoto method is actually residing on the timeline, not the movieclip, therefore to call it, you need to simply say _root.changePhoto(1);

Unless you've changed the whole construction of the movie, that is your problem.

blu.
0
 
LVL 1

Author Comment

by:ttist25
ID: 12641956
sokhodom -

I have created the gallery movie clip as a new movie symbol in the library and just inserted an instance of it on it's own layer in the main movie.

0
 
LVL 1

Author Comment

by:ttist25
ID: 12642120
blue -

What I am trying to do is insert the gallery as a movie clip instance in my main timeline.   I have been successful in creating the gallery as a standalone movie but the actionScript conflicts with other events on my main timeline so I was trying to add it as a movie clip instance with its own timeline to prevent those conflicts.

I created a new symbol in the library of the main movie and followed the instructions in the tutorial and I'm stuck at this point.  If I add buttons directly to the gallery instance, they don't appear when I run the swf.  So I tried putting them on the main movie and still no luck.

I'm sooooooooooooo confuuuuuuuuuuuuused!!!!

0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12642181
i'm a bit confused as to which approach you're using, you say that you tried Vicker's suggestion but to no avail.

i suspect that because the tutorial used Movieclip.prototype - it would cause all movieclips to act "funny" - thus the problem you had, so what you should be doing then, is as per Vicker's code (replacing the movieclip.proto bit) - and refer to it using _root.

i think that should solve it, otherwise you'll need to post the file

blu.
0
 
LVL 1

Author Comment

by:ttist25
ID: 12658205
Ok - I've given up on trying to get this to work as a movie clip inside the main movie.  My new approach is to create the gallery as a standalone movie and load the swf into a movieclip on the stage using loadMovie.

I created galleryKitchens.swf using the Kirup tutorial referenced above.  I added forward and backward buttons to the stage so the user can advance and rewind the images using:

on (release) {
      _root.changePhoto(1);      
}

This works great as a standalone movie.  The buttons work, it pulls in the images etc.

I assigned the following actionScript to a button on the stage of my main movie:

on (release) {
      bucket.loadMovie('galleryKitchens.swf');
}

Bucket is the movie clip instance in my main movie into which the gallery movie (galleryKitchens.swf) loads.

When I click my button it loads galleryKitchens.swf and pulls in the first image, but I can't see the forward and backward buttons (they flash for a quick instance when it is loading and disappear).

It's almost as if the image is loading ontop of the button layer but the buttons work great if I open galleryKitchens.swf alone.

Any ideas?

Brian
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12662427
Hi Brian, yeah, i'd say that's your problem. *Trying to visualise your setup here*
make sure that galleryKitchens.swf doesn't have a background on it?
Surely the btns are below it - not on top of it. because then they shouldn't overlap.

where are the next and back btns? on the _root where bucket is?

are the next and back btns inside bucket? or is bucket an empty Movie clip?

try using a swapDepths as in

bucket.loadMovie('galleryKitchens.swf');
bucket.swapDepths(clipwithbtns);

or specify a level to load into.
0
 
LVL 1

Author Comment

by:ttist25
ID: 12666119
Blu -

The following link is to a question I posted at kirupa.com.  It gives a much better description of the setup than the feeble attempt I posted here.

http://www.kirupaforum.com/forums/showthread.php?t=77238

Also, I'd be happy to post the .fla's if you can tell me where/how to do that.

In answer to your questions:
galleryKitchens.swf has 3 layers:

layer1  - is the actionscript layer with the script from the tutorial in frame 1.  It has been modified as per vickerleung's instruction (changed all 'MovieClip.prototype' to 'function functionName()').  It works great until it's nested.

layer2 - is a rectangle the size of the images which was converted to a MovieClip instance (photo) as per the tutorial instructions.

layer3 - contains the back/forward buttons.  They are the green gel buttons from the common libraries -> buttons library.  they have the following code attached:

       on (release) {
           _root.changePhoto(1);
       }

I tried moving the nav buttons up and down the layers to no avail.

I also tried loading the movieclip bucket into level 5 with the following (from a button on the parent of galleryKitchens):

       on (release) {
      bucket.loadMovie('galleryKitchens.swf', 5);
       }

This didn't make a difference.

I'm assuming that since the buttons are in the same movieclip as galleryKitchens that we can't use the swapDepths thing.

Anyway - thanks again for all of your help.  I'll be a happy man when we get this.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12666291
either get yourself some free space, geocities or something,
and post your zipped files there.
or,
mail to bluegenie(at)bigfoot(Dot)com

0
 
LVL 1

Author Comment

by:ttist25
ID: 12666580
Blue,

I just sent you an email with a link
0
 
LVL 1

Author Comment

by:ttist25
ID: 12666961
Blu -

The email got kicked back.  Is it bluegenie or blue-genie?
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12672447
oh shyte, sorry its blue-genie(at)bigfoot(dot)com

0
 
LVL 1

Author Comment

by:ttist25
ID: 12674639
Ok bud.  I just sent the email.  Really looking forward to your response.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12675252
Ok, i'm confused now even further.

Which file of all those is giving you the problem, there's images missing here.
can you please narrow it down and specify which file is the one where there's the problem instead of me going through each file.

What's the difference between galleryKitchensMod1.swf and galleryKitchens.swf

then your code is looking for page2.swf yet your pages are page2a.swf - I thought you'd removed the Movieclip.prototype code?

where's the latest version up to the point of your last post? i'd must rather have that then to have to sift through all the stuff again.

blu.
0
 
LVL 1

Author Comment

by:ttist25
ID: 12675584
I am sooo sorry Blue.  I apologize.  I was in such a hurry to get everything to you that I didn't consider how confusing that would be.  Again, very sorry.

I have uploaded a new zip file named blue.zip to the same directory.  It contains the following files:

temp1.fla - this is the main movie file
gallery.fla - this is the movie that is loaded into temp1 when the gallery button is clicked on temp1
galleryKitchens.fla - this is the movie that is loaded into 'bucket' from the 'kitchenButt' button on gallery.fla

I also included the index.html file, page1.fla (which is the first movie loaded into temp1) and the image files in the proper directories.

If you open gallerKitchens.swf you can see how that is supposed to work.

If there is anything else I can clarify please let me know.

And thanks again for all of your help.  It truly is appreciated.

Brian
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 2000 total points
ID: 12679293
Hey Brian - thanks, much better :-)

Okay, first things first, the problem is simply a case of confused roots ie. in your galleryKitchens.fla - you'll notice you have a couple of references to _root.photo - but once you load galleryKitchens.swf into _level0.bucket - your root structure then changes.

I tried putting in this._lockroot = true which ususally would do the trick, but it didn't - go figure.

anyways, if you change those _root.photo to this.photo - you'll notice that your btns now appear - but you'll also notice that they won't work - don't be disheartened - change your code on the buttons to -

 on (release) {
      _level0.bucket.changePhoto(-1);
}

but then - yet another problem - your original picture you'll see, shows through when you're doing the alpha fade out, so what i'd sugest there is use an unload when they first click on the gallery link to remove it.

hope this all makes sense.

ps. like your design (looks good).
blu.
0
 
LVL 1

Author Comment

by:ttist25
ID: 12680817
BLUE!!!!!!!!!!!!!!!!!!!!!!!!!!!

You're the man!  Thanks Boss.

It works great now.  I just did a couple things differently.  On the buttons instead of '_level0.bucket.changePhoto' I did 'this.bucket.changePhoto' (the level0 wouldn't work for some reason???).

Also, I couldn't get unload to work on the original pic so I just set the alpha of the original picture to 0 on release.

PRESTO!

You have no idea how happy I am to have this working.  Thanks so much for your patience.

Great job.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12680844
Um, i'm not so sure about the man bit, but um yeah, alright.
Not keen on the sex change idea, but you're very welcome.

I like the Boss bit though ;-)
there's many ways to beat a horse (or however the saying goes) - I guess once you know what the problem is, there's a number of ways to solve it, but I'm glad its working.

blu
0
 
LVL 1

Author Comment

by:ttist25
ID: 12680922
Ok then - Boss it is!

Thanks again Blu.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question