snitch321 -1 Junior Poster in Training

Im using actionscript 3 and i managed to create one link to another page, however when i try to copy the ame code on the same frame for another symbol it doesnt work. e.g.

stop();
IntroductionSymbol.addEventListener 
	(MouseEvent.CLICK, onClick); 

function onClick
( event:MouseEvent):void 

{
gotoAndStop("9") 
}

That code works fine for one symbol, however why cant i just copy the same code below the existing code but alter the symbols name?

Dani AI

Generated

For : the behavior described usually comes from two separate, well-known AS3 issues rather than a Flash bug. First, declaring the same named function twice in the same scope causes a compile-time problem; copying the handler and pasting it again with the same function name will not work. Second, instance names must exist on the exact frame where the code runs. If an instance name is missing or the code is placed on a different frame, the listener will silently fail or produce a compiler message.

A simple, robust approach is to attach one handler to multiple symbols and decide the action inside that handler by checking the event source (use event.currentTarget). This avoids duplicate function declarations and keeps the timeline code short and maintainable. Mapping clicked instance names to frame labels or numbers scales cleanly when more symbols are added.

var map:Object = { intro_mc: "9", menu_mc: "10" };

intro_mc.addEventListener(MouseEvent.CLICK, handleClick);
menu_mc.addEventListener(MouseEvent.CLICK, handleClick);

function handleClick(e:MouseEvent):void {
    var label:String = map[e.currentTarget.name];
    if (label) gotoAndStop(label);
}

Quick checklist: confirm stage instance names in the Properties panel; place code on the same frame as those instances; prefer event.currentTarget over event.target for listeners on container clips; set mouseChildren = false if nested children intercept clicks; and either reuse a single handler or give each listener a unique function name to avoid redeclaration errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.