AS3 for transfering pauseposition of MC1 to MC2 - actionscript-3

Hi I'm quite a new on flash and need some code. I have 3 MCs say MC1, MC2 and MC3. I will have 3 dedicated buttons that will pause the music of one MC and transfer the frame position to another MC and start playing. so say for example if MC2 is playing and I press the MC3 button I would like it to take the pause position of MC2 (not MC1) and continue playing from that frame on MC3 as well as switching the visuals from MC2 to MC3. it's a Multilingual app and all 3 MC's have the same frame length. in other words I would like to switch between languages.
Thanks in advance, any help would be great.
EDIT: up till now I have
mtlyrvult.stop();
itlyrvult.stop();
engvult.addEventListener(MouseEvent.CLICK, playMC1);
function playMC1(e:MouseEvent):void {
itlyrvult.stop();
enlyrvult.gotoAndPlay(itlyrvult.currentFrame);
itlyrvult.gotoAndStop(1); //frame one is empty
engvult.mouseEnabled = false;
itvult.mouseEnabled = true;
}
itvult.addEventListener(MouseEvent.CLICK, playMC2);
function playMC2(e:MouseEvent):void {
enlyrvult.stop();
itlyrvult.gotoAndPlay(enlyrvult.currentFrame);
enlyrvult.gotoAndStop(1); //frame one is empty
itvult.mouseEnabled = false;
engvult.mouseEnabled = true;
}
This switches from one language to another. Now my client gave me another language. mtlyrvult. And I don't know how AS3 will recognise which mc is playing to take the the pauseposition/currentframe from it.

I stick to your code (no class, method, members, addChild, ...). I didn't try the final draft with Flash or SDK.
I assume that you have:
3 MovieClip objects : enlyrvult, itlyrvult, mtlyrvult;
3 InteractiveObject (SimpleButton, MovieClip, ...) objects : engvult, itvult, mtvult;
and that enlyrvult is playing when we begin here (if not: enlyrvult.play(); or enlyrvult.stop();).
itlyrvult.stop(); // or itlyrvult.gotoAndStop(1);
mtlyrvult.stop(); // or mtlyrvult.gotoAndStop(1);
engvult.addEventListener(MouseEvent.CLICK, playMC1);
itvult.addEventListener(MouseEvent.CLICK, playMC2);
mtvult.addEventListener(MouseEvent.CLICK, playMC3);
// play enlyrvult
function playMC1(e:MouseEvent):void {
// stop them
itlyrvult.stop();
mtlyrvult.stop();
// play me
enlyrvult.gotoAndPlay(mtlyrvult.currentFrame);
// hide them
itlyrvult.gotoAndStop(1); //frame one is empty
mtlyrvult.gotoAndStop(1); //frame one is empty
// My trigger is out, theirs are fine
engvult.mouseEnabled = false;
itvult.mouseEnabled = true;
mtvult.mouseEnabled = true;
}
// play itlyrvult
function playMC2(e:MouseEvent):void {
// stop them
enlyrvult.stop();
mtlyrvult.stop();
// play me
itlyrvult.gotoAndPlay(enlyrvult.currentFrame);
// hide them
enlyrvult.gotoAndStop(1); //frame one is empty
mtlyrvult.gotoAndStop(1); //frame one is empty
// My trigger is out, theirs are fine
itvult.mouseEnabled = false;
engvult.mouseEnabled = true;
mtvult.mouseEnabled = true;
}
// play mtlyrvult
function playMC3(e:MouseEvent):void {
// stop them
enlyrvult.stop();
itlyrvult.stop();
// play me
mtlyrvult.gotoAndPlay(itlyrvult.currentFrame);
// hide them
enlyrvult.gotoAndStop(1); //frame one is empty
itlyrvult.gotoAndStop(1); //frame one is empty
// My trigger is out, theirs are fine
mtvult.mouseEnabled = false;
engvult.mouseEnabled = true;
itvult.mouseEnabled = true;
}
OR, for as much (300?) as you want...
// add to your import:
import flash.utils.Dictionary;
// in your const/var section
const STARTING_FRAME:int = 1;
var dict = new Dictionary(); // mapping and memory
var currentTrack:MovieClip; // we will know who's last
initAll();
playTrack(enlyrvult, STARTING_FRAME, engvult);
function clickHandler(e:MouseEvent):void {
var playheadFrame:int = currentTrack.currentFrame; // we remember position
var trigger:InteractiveObject = (e.currentTarget as InteractiveObject); // who shot me ?
var nextTrack:MovieClip = (dict[trigger] as MovieClip); // who's next ?
resetAll(); // and again.. (http://en.wikipedia.org/wiki/Sisyphus)
playTrack(nextTrack, playheadFrame, trigger);
}
function playTrack(mc:MovieClip, fram:int, iObj:InteractiveObject):void {
currentTrack = mc;
currentTrack.gotoAndPlay(fram);
iObj.mouseEnabled = false;
}
function resetAll():void {
for (var key:InteractiveObject in dict) { key.mouseEnabled = true; }
for each (var value:MovieClip in dict) { value.gotoAndStop(1); } // diff-> each
}
function initAll():void {
dict[engvult] = enlyrvult;
dict[itvult] = itlyrvult;
dict[mtvult] = mtlyrvult;
//dict[avult] = alyrvult; //<- new one like this: dict[trigger]=lyrMC; add as much as you can!
for (var key:InteractiveObject in dict) {
key.addEventListener(MouseEvent.CLICK, clickHandler);
}
resetAll();
}

Related

Flash AS3 - Drag and drop multiple objects to multiple targets

I have multiple objects to drag to multiple targets.
I have a code without error.
I am using multiple functions. But I wonder if I pass the objects and the specific target with one function like dropIt since I have more objects and duplicated functions.
This picture is what I want to implement.
and the code is as follows.
Thanks in advance.
var obj1:Array = [obj_1, obj_10];
var obj2:Array = [obj_2, obj_20];
for each(var redsMC:MovieClip in reds)
{
obj1MC.buttonMode = true;
obj1MC.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
obj1MC.addEventListener(MouseEvent.MOUSE_UP, dropIt);
obj1MC.startX = obj1MC.x;
obj1MC.startY = obj1MC.y;
}
for each(var orangesMC:MovieClip in oranges)
{
obj2MC.buttonMode = true;
obj2MC.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
obj2MC.addEventListener(MouseEvent.MOUSE_UP, dropIt1);
obj2MC.startX = obj2MC.x;
obj2MC.startY = obj2MC.y;
}
function pickUp(event:MouseEvent):void
{
event.target.startDrag(true);
event.target.parent.addChild(event.target);
}
function dropIt(event:MouseEvent):void
{
event.target.stopDrag();
if(event.target.hitTestObject(target1)){
event.target.buttonMode = false;
event.target.x = target1.x;
event.target.y = target1.y;
}else if(event.target.hitTestObject(target10)){
event.target.buttonMode = false;
event.target.x = target10.x;
event.target.y = target10.y;
}
else
{
event.target.x = event.target.startX;
event.target.y = event.target.startY;
event.target.buttonMode = true;
}
}
function dropIt1(event:MouseEvent):void
{
event.target.stopDrag();
if(event.target.hitTestObject(target2)){
event.target.buttonMode = false;
event.target.x = target2.x;
event.target.y = target2.y;
}else if(event.target.hitTestObject(target20)){
event.target.buttonMode = false;
event.target.x = target20.x;
event.target.y = target20.y;
}
else
{
event.target.x = event.target.startX;
event.target.y = event.target.startY;
event.target.buttonMode = true;
}
}
You should somehow make your draggable objects know their targets, thus when your SWF registers an end drag event, the object that was being dragged would check against its target and if not colliding, then float/jump back. Since your objects derive from MovieClips, it's possible to add custom properties to them without doing any declarations, but be sure to check if there is something in a custom property before using it. Let's say you have assigned each draggable object a desiredTarget as whatever target you need them to be dragged. Then, you can do like this:
function dropIt(e:MouseEvent):void {
var desiredTarget:MovieClip=e.target.desiredTarget as MovieClip; // get where this should be placed
e.target.stopDrag(); // we still need to release the dragged object
if (!desiredTarget) return; // no target - nothing to do (also helps with debug)
if (e.target.hitTestObject(desiredTarget)) {
e.target.buttonMode=false;
e.target.x=desiredTarget.x;
e.target.y=desiredTarget.y;
} else {
// move dragged object back to starting position
e.target.x=e.target.startX;
e.target.y=e.target.startY;
}
}
Despite the fact Vesper's answer is already accepted, I think it to be far too brief and insufficient, on top of that it doesn't actually answer how to design a system where any number of objects could be dropped to any number of targets, without substantial changes to the code.
// Unlike the Object class, that allows String keys only
// the Dictionary class allows you to store and
// access data by the object instance.
var theValids:Dictionary = new Dictionary;
// We'll store the original (x,y) coordinates here.
var theOrigin:Point = new Point;
// The Sprite class is the superclass of MovieClip, furthermore,
// the startDrag method defined for Sprite class, so unless you
// create your own dragging code, you are bound to use Sprites,
// while you cannot drag SimpleButtons and TextFields this way.
// We'll store the current dragged object here.
var theObject:Sprite;
// This first argument is the object you want to be draggable.
// The "...targets:Array" means you can call this method with
// any number of arguments, the first one is mandatory, the
// rest will be passed in a form of Array (empty Array if you
// call this method with a single argument).
function setupDraggable(source:Sprite, ...targets:Array):void
{
// Make the object draggable.
source.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
source.mouseChildren = false;
source.mouseEnabled = true;
source.buttonMode = true;
// Keep the list of the object's targets so it can be
// retrieved later by the key of the object itself.
theValids[source] = targets;
}
// Ok, let's setup the objects and link them to their designated
// targets. The whole point of the rest of the code is to make
// this one part as simple as it possible: you just edit
// these lines to tell which one objects go where.
// This object can be dropped to a single target.
setupDraggable(obj_1 , target1);
// These objects can go to two targets each.
setupDraggable(obj_10, target1, target10);
setupDraggable(obj_2 , target2, target20);
// This one object can be dropped to any of targets.
setupDraggable(obj_20, target1, target10, target2, target20);
// The MOUSE_DOWN event handler.
function onDown(e:MouseEvent):void
{
// Get the reference to the object under the mouse.
theObject = e.currentTarget as Sprite;
// Keep the object's initial position.
theOrigin.x = theObject.x;
theOrigin.y = theObject.y;
// Put the dragged object on top of anything else.
// We are operating in the parent context of all these
// objects here so there's no need to address anObj.parent.
setChildIndex(theObject, numChildren - 1);
// Start dragging.
theObject.startDrag(true);
// Listen to the MOUSE_UP event, which could happen offstage
// and out of the dragged object, so the only reliable
// way is to listen it from the Stage. That's why we
// are keeping theObject reference as an additional
// variable, without relying on event's data.
stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
}
// The MOUSE_UP event handler.
function onUp(e:MouseEvent):void
{
// Unsubscribe the MOUSE_UP event handler.
stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
// Stop the dragging process.
theObject.stopDrag();
// Let's assume there could be more than a single collision.
// We need to figure the one target that is closest.
var theTarget:DisplayObject;
var theDistance:int = 100000;
// Store the dragged object position so we can
// measure distances to the valid collisions, if any.
var thePlace:Point = theObject.localToGlobal(new Point);
// Now, the magic. Lets browse through the
// valid targets and see if there's a collision.
for each (var aTarget:DisplayObject in theValids[theObject])
{
if (theObject.hitTestObject(aTarget))
{
// Let's see if the current collision is closer
// to the dragged object, than the previous one
// (if any, that's what initial 100000 for).
var aPlace:Point = aTarget.localToGlobal(new Point);
var aDistance:int = Point.distance(aPlace, thePlace);
if (aDistance < theDistance)
{
theTarget = aTarget;
theDistance = aDistance;
}
}
}
// If there's at least one collision,
// this variable will not be empty.
if (theTarget)
{
// Make the object non-interactive.
theObject.removeEventListener(MouseEvent.MOUSE_DOWN, onDown);
theObject.mouseEnabled = false;
theObject.buttonMode = false;
// Glue the dragged object to the center of the target.
theObject.x = theTarget.x;
theObject.y = theTarget.y;
}
else
{
// If we're here, that means there was no valid collisions,
// lets return the object to its designated place.
theObject.x = theOrigin.x;
theObject.y = theOrigin.y;
}
// Clean-up. Remove the reference, the object is no longer
// being dragged, so you won't need to keep it.
theObject = null;
}
P.S. I didn't test it, but I think I put enough comments to explain the whole idea.

Flash CS4 How do you set variable to the Object Dragging Collison?

I am doing a game for my computer science class and I am working on inventory, dragging an item into it. I do not know how to set the item as whatever the user clicked to drag.
At the moment I hard coded it to the item they are dragging, but in the future I want more items, so a variable set to the item they are dragging would make it work perfectly, but I don't know what it's called to do that.
Here is my code for inventory item dragging
function dragItem (event:MouseEvent):void
{
knife_loot.startDrag();
}
function dropItem (event:MouseEvent):void
{
knife_loot.stopDrag();
if ((knife_loot.hitTestObject(inv_game)) && (inv_game.visible == true))
{
trace("Item dropped in inventory")
trace("")
knife_loot.x = 80
knife_loot.y = 120
}
}
// end of dragging and dropping items
You can start with:
// List the items you want to drag.
var aList:Array = [knife_loot, spoon_loot, fork_loot];
// InteractiveObject is superclass for SimpleButton, Sprite and MovieClip.
// If you're sure what they all are then just use their class instead.
for each (var anItem:InteractiveObject in aList)
{
// Subscribe them all for dragging.
anItem.addEventListener(MouseEvent.MOUSE_DOWN, onDrag);
}
public var draggedItem:InteractiveObject;
function onDrag(e:MouseEvent):void
{
// Use e.currentTarget because original MouseEvent e.target
// could be something from deep inside of top object e.currentTarget.
draggedItem = e.currentTarget as InteractiveObject;
draggedItem.startDrag();
// Let's hook drop events.
stage.addEventListener(Event.MOUSE_LEAVE, onDrop);
stage.addEventListener(MouseEvent.MOUSE_UP, onDrop);
}
function onDrop(e:Event):void
{
// Unhook drop events.
stage.removeEventListener(Event.MOUSE_LEAVE, onDrop);
stage.removeEventListener(MouseEvent.MOUSE_UP, onDrop);
// Drop the item.
draggedItem.stopDrag();
if ((draggedItem.hitTestObject(inv_game)) && (inv_game.visible == true))
{
trace("Item", draggedItem.name, "was dropped to inventory.");
trace("");
draggedItem.x = 80;
draggedItem.y = 120;
}
// Forget the item.
draggedItem = null;
}

as3: Mute button and volume slider on one sound channel

I have truly exhausted all my knowledge on this problem so I hope that my peers will be able to help me?
I am building a audio mixer that has five tracks with a volume slider and mute button per track. The reason for a mute button as opposed to a start/stop button per track is so that all the samples will be in sync regardless of when a sample is introduced.
The app has global start, stop and pause buttons which all function normally but I cannot get the volume slider and mute button to work in tandem on an individual sound channel.
The volume slider and the mute button will both work if I comment out the other function but when both are in play then only the volume slider works.
I'm guessing that there is a conflict because I have two separate variables using the soundTransform object/class but maybe you can shed some light on this conundrum?
Here is my code for one track... Any help appricated.
var mySound1:Sound1 = new Sound1();
var myChannel1:SoundChannel = new SoundChannel();
var volumeAdjust1:SoundTransform = new SoundTransform();
volumeAdjust1.volume = 0;
mute_btn1.stop();
mute_btn1.addEventListener(MouseEvent.CLICK,togglemute_btn1);
var Mute1:Boolean = false;
function togglemute_btn1(event:MouseEvent)
{
if (Mute1)
{
mute_btn1.gotoAndStop(1);
volumeAdjust1.volume = 1;
myChannel1.soundTransform = volumeAdjust1;
Mute1 = false;
}
else
{
mute_btn1.gotoAndStop(2)
volumeAdjust1.volume = 0;
myChannel1.soundTransform = volumeAdjust1;
Mute1 = true;
}
}
/*if the section below is commented out then the mute_btn1 works fine
otherwise the volume slider functions are dominent*/
var dragging1:Boolean = false;
var mySliderLength1:uint = 300;
var boundingBox1:Rectangle = new Rectangle(0,0,0,mySliderLength1);
slider_mc1.knob_mc1.addEventListener(MouseEvent.MOUSE_DOWN, dragKnob1);
stage.addEventListener(MouseEvent.MOUSE_UP, releaseKnob1);
slider_mc1.knob_mc1.buttonMode = true;
function dragKnob1(myEvent:Event):void
{
slider_mc1.knob_mc1.startDrag(false, boundingBox1);
dragging1 = true;
slider_mc1.knob_mc1.addEventListener(Event.ENTER_FRAME, adjustVolume1);
}
function releaseKnob1(myEvent:Event):void
{
if (dragging1)
{
slider_mc1.knob_mc1.stopDrag();
dragging1 = false;
}
}
function adjustVolume1(myEvent:Event):void
{
var myVolume1:Number = slider_mc1.knob_mc1.y / mySliderLength1;
var myTransform1:SoundTransform = new SoundTransform(myVolume1);
if (myChannel1!=null)
{
myChannel1.soundTransform = myTransform1;
}
}
You should check your Mute1 variable in that listener of yours, and if muted, then volume=0, otherwise volume is calculated. And indeed, do remove your enter frame listener at the point of stopDrag() call.
function dragKnob1(myEvent:Event):void
{
slider_mc1.knob_mc1.startDrag(false, boundingBox1);
dragging1 = true;
slider_mc1.knob_mc1.addEventListener(Event.ENTER_FRAME, adjustVolume1);
}
function releaseKnob1(myEvent:Event):void
{
if (dragging1)
{
slider_mc1.knob_mc1.stopDrag();
dragging1 = false;
slider_mc1.knob_mc1.removeEventListener(Event.ENTER_FRAME, adjustVolume1);
// ^ this line added
}
}
function adjustVolume1(myEvent:Event):void
{
if (Mute1) return;
// ^ and this line added
var myVolume1:Number = slider_mc1.knob_mc1.y / mySliderLength1;
var myTransform1:SoundTransform = new SoundTransform(myVolume1);
if (myChannel1!=null)
{
myChannel1.soundTransform = myTransform1;
}
}
I believe your issue is you keep adding the Enter_Frame listener every time the mouse is clicked but it never gets removed. So even after you let go of the knob the adjustVolume1 function is still getting called (which messes up anything the mute function call is doing on the frame after the mute toggle function is called).
So how I think I would deal with this given the current state is move the Enter_Frame listener addition outside of the dragKnob function and in the adjustVolume1 handler just check if dragging1 is true otherwise just return.
slider_mc1.knob_mc1.addEventListener(Event.ENTER_FRAME, adjustVolume1);
function dragKnob1(myEvent:Event):void
{
...
}
function adjustVolume1(myEvent:Event):void
{
if(!dragging1)
return;
...
}

use 1 object multiple times in as3?

I'm trying to make something like bookmarks, I have 1 note on the stage and when the user clicks it, it starts to drag and the users drops it where they want. the problem is I want these notes to be dragged multiple times.. here is my code:
import flash.events.MouseEvent;
//notess is the instance name of the movie clip on the stage
notess.inputText.visible = false;
//delet is a delete button inside the movie clip,
notess.delet.visible = false;
//the class of the object i want to drag
var note:notes = new notes ;
notess.addEventListener(MouseEvent.CLICK , newNote);
function newNote(e:MouseEvent):void
{
for (var i:Number = 1; i<10; i++)
{
addChild(note);
//inpuText is a text field in notess movie clip
note.inputText.visible = false;
note.x = mouseX;
note.y = mouseY;
note.addEventListener( MouseEvent.MOUSE_DOWN , drag);
note.addEventListener( MouseEvent.MOUSE_UP , drop);
note.delet.addEventListener( MouseEvent.CLICK , delet);
}
}
function drag(e:MouseEvent):void
{
note.startDrag();
}
function drop(e:MouseEvent):void
{
e.currentTarget.stopDrag();
note.inputText.visible = true;
note.delet.visible = true;
}
function delet(e:MouseEvent):void
{
removeChild(note);
}
any help will be appreciated.
You need to create a new instance of your note class when you drop, copy the location and other variables from the note you were dragging, add your new note to the stage, and return the dragging note to its original position.
Something like:
function drop($e:MouseEvent):void
{
$e.currentTarget.stopDrag();
dropNote($e.currentTarget as Note);
}
var newNote:Note;
function dropNote($note:Note):void
{
newNote = new Note();
// Copy vars:
newNote.x = $note.x;
newNote.y = $note.y;
// etc.
// restore original note.
// You will need to store its original position before you begin dragging:
$note.x = $note.originalX;
$note.y = $note.orgiinalY;
// etc.
// Finally, add your new note to the stage:
addChild(newNote);
}
... this is pseudo-code really, since I don't know if you need to add the new note to a list, or link it to its original note. If you Google ActionScript Drag Drop Duplicate, you will find quite a few more examples.
I think you are not target the drag object in drag function and problem in object instantiation
for (var i:Number = 1; i<numberOfNodes; i++) {
note = new note();
addChild(note);
...
....
}
function drag(e:MouseEvent):void{
(e.target).startDrag();
}
If you are dragging around multiple types of objects (eg. Notes and Images), you could do something like this, rather than hard coding the type of object to be instantiated.
function drop(e:MouseEvent):void{
// Get a reference to the class of the dragged object
var className:String = flash.utils.getQualifiedClassName(e.currentTarget);
var TheClass:Class = flash.utils.getDefinitionByName(className) as Class;
var scope:DisplayObjectContainer = this; // The Drop Target
// Convert the position of the dragged clip to local coordinates
var position:Point = scope.globalToLocal( DisplayObject(e.currentTarget).localToGlobal() );
// Create a new instance of the dragged object
var instance:DisplayObject = new TheClass();
instance.x = position.x;
instance.y = position.y;
scope.addChild(instance);
}

music playing over and over in Actionscript 3

Greeting,
I I developed a website using flash with Actionscript 3.
I included a music as a background for the website and the music will loaded when the site loaded.
but the problem that when I click buttons to move between pages(frames) then go and click button_01 the music will play again so I will have music playing more than one time in the background
and the sound_btn will not work any more so even I click sound_btn the music will not stop.
the code I'm using is listed down.
Please advice me what I should modify to not allow the music play more than one time in the background while moving from one page(frame) to another.
Regards,
stop();
//number that is redefined when the pause button is hit
var pausePoint:Number = 0.00;
//a true or false value that is used to check whether the sound is currently playing
var isPlaying:Boolean;
//think of the soundchannel as a speaker system and the sound as an mp3 player
var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound(new URLRequest("music.mp3"));
//you should set the xstop and xplay values to match the instance names of your stop button and play/pause buttons
//mute_btn.addEventListener(MouseEvent.CLICK, clickStop);
sound_btn.addEventListener(MouseEvent.CLICK, clickPlayPause);
soundChannel = sound.play();
isPlaying = true;
myVideo.stop();
function clickPlayPause(evt:MouseEvent) {
if (isPlaying) {
pausePoint = soundChannel.position;
soundChannel.stop();
isPlaying = false;
} else {
soundChannel = sound.play(pausePoint);
isPlaying = true;
}
}
button_01.addEventListener(MouseEvent.CLICK, onClick1);
button_02.addEventListener(MouseEvent.CLICK, onClick2);
button_03.addEventListener(MouseEvent.CLICK, onClick3);
button_04.addEventListener(MouseEvent.CLICK, onClick4);
button_05.addEventListener(MouseEvent.CLICK, onClick5);
button_06.addEventListener(MouseEvent.CLICK, onClick6);
function onClick1(e:MouseEvent):void
{
gotoAndStop(1);
}
function onClick2(event:MouseEvent):void
{
gotoAndStop(2);
}
function onClick3(event:MouseEvent):void
{
gotoAndStop(3);
}
function onClick4(event:MouseEvent):void
{
gotoAndStop(4);
}
function onClick5(event:MouseEvent):void
{
gotoAndStop(5);
}
function onClick6(event:MouseEvent):void
{
gotoAndStop(6);
}
The problem is your code for the sound is initialized on the frame that you send the timeline to when clicking button_01. It will reinitialize each time you do that. Try initializing your sound code one frame earlier so that you do not land on that frame ever again once your page loads.
You also might find that wrapping your pages into movieclips, and using visible = true/false to change sections might be a better approach than advancing the timeline to change sections. That method would not result in the sound code reinitializing each time you changed sections. something like this:
function onClick1(e:MouseEvent):void
{
hideAll();
section_01.visible = true;
}
function onClick2(event:MouseEvent):void
{
hideAll();
section_02.visible = true;
}
function onClick3(event:MouseEvent):void
{
hideAll();
section_03.visible = true;
}
function onClick4(event:MouseEvent):void
{
hideAll();
section_04.visible = true;
}
function onClick5(event:MouseEvent):void
{
hideAll();
section_05.visible = true;
}
function onClick6(event:MouseEvent):void
{
hideAll();
section_06.visible = true;
}
function hideAll():void
{
section_01.visible = false;
section_02.visible = false;
section_03.visible = false;
section_04.visible = false;
section_05.visible = false;
section_06.visible = false;
}
If you wanted tweened transitions you could use a tweening class to handle the transitions by tweening the current section out in the hide function and then tweening the next section in in its respective onCLick function.