Isaac, 

I wanted to show you, and anyone interested, that your idea of frame label
navigation in conjunction with XML is doable. 

To use this example just start a fresh fla, build out the fla according to
the structure laid out under 'Structure:' in the comment below, then copy
and paste the code into frame 1 of the actions layer. 

/*
 FrameLabelNav.fla Example
 Author: Keith Reinfeld
 FlashPlayer 9, AS3
 Structure:
 Main Timeline:
 Three layers: actions
                   buttons
                   textfields
 actions layer: five blank keyframes
                frame 1: Actionscript (no frame label)
                frame 2: frame label: intro
                frame 3: frame label: labelone
                frame 4: frame label: labeltwo
                frame 5: frame label: labelthree
 buttons layer: two buttons spanning all five frames
                SimpleButton: prevBtn
                SimpleButton: nextBtn
 textfields layer: 
                frame 1: blank keyframe
                frames 2 - 5: 
                        TextField: content_txt spanning last four frames
*/
// Timeline code in frame 1:
stop();

// The order of the XML elements doesn't matter.
// However, each name attribute value must be unique.
var contentXML:XML = <frames>
<frame name="labeltwo" text="This is the frame with the label 'labeltwo'."/>
<frame name="intro" text="This is the frame with the label 'intro'."/>
<frame name="labelthree" text="This is the frame with the label
'labelthree'."/>
<frame name="labelone" text="This is the frame with the label 'labelone'."/>

<frame name="labelnone" text="There is no frame with the label
'labelnone'."/>
</frames>;

// Init vars
var labels:Array = this.currentLabels;
var frameIndex:uint = 0;
var frameMax:uint = labels.length - 1;
var nextLbl:FrameLabel = labels[frameIndex];

// Listeners
prevBtn.addEventListener(MouseEvent.CLICK, navPrev);
nextBtn.addEventListener(MouseEvent.CLICK, navNext);
this.addEventListener(Event.ENTER_FRAME, navTo);

function navPrev(event:MouseEvent):void {
        frameIndex = (frameIndex > 0)? --frameIndex: frameIndex;
        this.addEventListener(Event.ENTER_FRAME, navTo);
}

function navNext(event:MouseEvent):void {
        frameIndex = (frameIndex < frameMax)? ++frameIndex: frameIndex;
        this.addEventListener(Event.ENTER_FRAME, navTo);
}

function navTo(event:Event):void{
        nextLbl = labels[frameIndex];
        this.gotoAndStop(nextLbl.name);
        if(this.content_txt != null){
                this.removeEventListener(Event.ENTER_FRAME, navTo);
                updateTextField();
        }
}

function updateTextField():void{
        this.content_txt.text =
contentText(contentXML,"frame","name",nextLbl.name,"text")+" (Frame:
"+this.currentFrame+")";
}

function
contentText(node:XML,element:String,att1:String,val1:String,att2:String):Str
ing{
        return node.elements(element).(@[att1] == val1)....@[att2];
}

Questions?

HTH

Keith Reinfeld
Home Page: http://keithreinfeld.home.comcast.net


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to