[Flashcoders] a function tells to move to a frame and then update content in that frame

2009-08-28 Thread Isaac Alves
Hello!

In the following code, i tell the Flash runtime to go to frame2 and
update the content of this frame.

The problem is that, the first time this function runs it throws the error:

TypeError: Error #1009:

I believe that happens because it tries to update container._tit
before render the screen, so it will be still in frame 1. It goes to
frame 2 but doesn't update the _tit textfield.

I've tried to solve it this way: instead of using gotoAndStop(2) i've
called another functiion with that statement and updateAfterEvent();

but it seems that it is not a method of the Event class.

Any solution ??
thanks in advance!!



function updateContent(e:Event):void {

gotoAndStop(2);

link = String(e.target.frameLink);
counter = 0;

if (content[link].tit != undefined)
{
container._tit.text = content[link].tit;
counter ++;
}
else
{
container._tit.text = ;
}
etc...
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] a function tells to move to a frame and then update content in that frame

2009-08-28 Thread Keith Reinfeld
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