Solved

newbie Actionscript 3 code question

Posted on 2011-09-21
8
232 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now