Solved

newbie Actionscript 3 code question

Posted on 2011-09-21
8
271 Views
Last Modified: 2012-05-12
This is probably a really basic question, since I am newbie at AS3 but I need help.

I have thumbnails in a portfolio slideshow movie clip. Each client featured in the movie clip has three thumbnails that when clicked are to show the corresponding image by going to the labeled frame for that image.

I used the following code on the first client at frame 1:

//"ace_1" is the instance of the first thumbnail
ace_1.addEventListener(MouseEvent.CLICK, ace1);
function ace1 (event:MouseEvent):void {
gotoAndPlay("ace");
trace("moved next");
};

//"ace_2" is the instance of the second thumbnail
ace_2.addEventListener(MouseEvent.CLICK, ace2);
function ace2 (event:MouseEvent):void {
gotoAndPlay("ace2");
trace("moved next");
};

//"ace_3" is the instance of the third thumbnail
ace_3.addEventListener(MouseEvent.CLICK, ace3);
function ace3 (event:MouseEvent):void {
gotoAndPlay("ace3");
trace("moved next");
};


It worked just fine with no error and correct traces (I was so excited ). So I wrote similar code for the next client modifying the instance names and function names and the labeled frames.


anc_1.addEventListener(MouseEvent.CLICK, anc1);
function anc1 (event:MouseEvent = null):void {
gotoAndPlay("anchor");
trace("moved next");
};

anc_2.addEventListener(MouseEvent.CLICK, anc2);
function anc2 (event:MouseEvent = null):void {
gotoAndPlay("anc2");
trace("moved next");
};

anc_3.addEventListener(MouseEvent.CLICK, anc3);
function anc3 (event:MouseEvent = null):void {
gotoAndPlay("anc3");
trace("moved next");
};


This gave me the "1023:Incompatible override" and "1021: Duplicate function definition" errors.

Being a newbie at Actionscript3 I don't know what I need to change. I have 14 clients I have to get similar thumbnails working on.

Sure could use some help.
Thanks.
Adriana
0
Comment
Question by:jabberwok_e
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 8

Accepted Solution

by:
Jen0910 earned 300 total points
ID: 36574931
I'd advise you to just create separate movie clips for each client instead of placing them all on the main timeline and trying to duplicate code. Then, when you have the code working for one, you're done. You can just duplicate the movie clip itself, rename it and replace the thumbnails for each client. When you've got all 14 done, place them on the main timeline with correct instance names for each movieclip. So basically, you create 1 item and save yourself 13 extra steps.

Don't create more work for yourself! :)
0
 

Author Comment

by:jabberwok_e
ID: 36575056
I have on the main scene timeline four categories which are buttons (print, branding, multimedia, interactive). Each of these category buttons go to and play the frame on the main scene timeline that contains the movie clip for that category.

Right now I have a MC for print called "printMC" that is on frame 1 of the main scene timeline and a MC for branding called "brandMC" that is on frame 2  and a MC for multimedia called "multiMC" that is on frame 3  and a MC for interactive called "interMC" that is on frame 4 of the main scene timeline . "printMC" has 14 client (each with their three thumbnails).  If I understand what you are saying, I would create 14 individual MCs for each client and place them within the frames of printMC. Right? I'll give it a try.

From a learning perspective I'd like to know why the errors happened. If I used different instance references and different functions names why does it error out that I have a duplicate function definition? What part of the code creates the "definition" of the function? Also what in my code created the "incompatible override" (which I'm not sure what that even means)?

Thanks
Adriana
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36575336
It's hard to say where is the problem in your code without running on my local machine your FLA file
But you can optimize your code and that may help solve your problem

anc_1.name = "anchor";
anc_2.name = "anc2";
anc_3.name = "anc3";

anc_1.addEventListener(MouseEvent.CLICK, mouseHandler);
anc_2.addEventListener(MouseEvent.CLICK, mouseHandler);
anc_3.addEventListener(MouseEvent.CLICK, mouseHandler);

function mouseHandler (event:MouseEvent):void {
      gotoAndPlay(event.target.name);
      trace("moved next");
};
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 29

Assisted Solution

by:dgofman
dgofman earned 200 total points
ID: 36575365
And funally you can create you function and pass instance + name

addEvent(anc_1, "anchor");
addEvent(anc_2, "anc2");
addEvent(anc_3, "anc3");

function addEvent(target:Sprite, name:String):void{
      target.name = name;
      target.addEventListener(MouseEvent.CLICK, mouseHandler);
}
function mouseHandler (event:MouseEvent):void {
      gotoAndPlay(event.target.name);
      trace("moved next");
};
0
 

Author Comment

by:jabberwok_e
ID: 36575493
One thing I just noticed is that I use the same name for some frame labels as I use in the function names. Changing the function names seems to be eliminating the problem so far, but I am still testing it out.

@dgofman I do find your code optimizing very interesting. I'm so new at this that I am sure my code is clumsy and could most likely be streamlined to be cleaner and more efficient.
0
 
LVL 8

Expert Comment

by:Jen0910
ID: 36575574
You would create 1 mc, which you have pretty much done already since you can copy your work referenced above into a new mc symbol called "printClient1_mc" or something like that which easily identifies it. then, go into your library panel, duplicate that "printClient1_mc" symbol, give it a correct name (ie ""printClient2_mc"") and all you need to do is swap the images symbols with the movie clip, or swap bitmaps if you left them as bitmaps and are not animating them. repeat that process another 12 times to get your 14 clients. All the code in it will work for all 14 since they are in separate mc's and not on the main timeline.

I have my portfolio setup exactly the same way you explained, and believe me, this process saves many, many hours. It's hard for me to tell you exactly why you are having cod problems with the files, there may be other things going on. but i know this idea/process can help avoid what you are going through all together, and its also great for when you want to expand your portfolio and add more items in the future.
0
 

Author Comment

by:jabberwok_e
ID: 36576446
The solution to resolve the issue in my existing code was to make sure that my functions names were not duplicated in my frame label names. Once I changes the function names it worked.
0
 

Author Closing Comment

by:jabberwok_e
ID: 36576488
In the end I found out what was the issue and corrected my existing code and learned that you cannot have duplicate function and frame label names, but Jen0910 gave an excellent suggestion on a way to structure a portfolio. One that I may implement in the future.

dgofman provided an interesting piece of streamlined code. I haven't tried it out since i figured out my issue and already had all my code placed. but I will try it on my future projects.

Both help to educate this AS3 newbie.
0

Featured Post

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
anti-download video publishing site? 6 625
Can't play a movie website which used to be playable 4 704
Youtube video error 30 871
free flash maker 5 222
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

739 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