Copy link to clipboard
Copied
Hello All,
First off I'm very new at this so bare with me if I'm not using the correct terminaology...
Ok so I'm modifying an existing Flash Program that someone here created a while back with Actionscript 1.0 and rewriting to
Actionscript 3.0. The Flash program reads in some XML Data using XMLSocket and I collect the data and save some of it into string variables.
Now when a certain piece of string data comes in from the XML Data, which contains the name of a specific "Frame" to display, I use
a switch statement to decide which of the 5 frames to display.
The "Movie" is called "WBDMovie"....
So lets say I receive the string that tells me to display "Frame 1". So I issue this command below to go to that Frame:
WBDMovie.gotoAndStop(1);
This command takes me to "Frame 1" and stops. Now in Frame 1 there are 5 "Text Fields" in this area all set to "Dynamic Text". Now, I'm
trying to write a string variable to one of these Txt Fields in this Frame but I keep getting an error for undefined variable. See the Error below:
*The "Text Field" is called "F1_agentsReady".
*The "String Variable" is called "agentsReady".
Line w/ Error: F1_agentsReady.appendText("Agents Ready = " + agentsReady);
ReferenceError: Error #1065: Variable F1_agentsReady is not defined.
at CSRBoard2013_fla::MainTimeline/dataHandler()[CSRBoard2013_fla.MainTimeline::frame1:104]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::XMLSocket/scanAndSendEvent()
So to write to this particular Text Field do I need to reference to the specific Frame that the Text Field is in?
I'm kinda confused how I was able to create another Text Field called "msgArea" which I placed in the Movie and can write to it (and its visible)
no matter what frame I'm currently displaying..?
Any suggestions would be much appreciated!
Thanks in Advance,
Matt
you need to wait until that frame in that movieclip is rendered before you can reference objects created in that frame:
stage.invalidate();
WBDMovie.addEventListener(Event.RENDER,renderF);
WBDMovie.gotoAndStop(1);
function renderF(e:Event):void{
// you can now reference objects created in frame 1 of WBDMovie
}
Copy link to clipboard
Copied
you need to wait until that frame in that movieclip is rendered before you can reference objects created in that frame:
stage.invalidate();
WBDMovie.addEventListener(Event.RENDER,renderF);
WBDMovie.gotoAndStop(1);
function renderF(e:Event):void{
// you can now reference objects created in frame 1 of WBDMovie
}
Copy link to clipboard
Copied
Hey kglad, thanks for the reply!
Ok cool... I'll give that a try and post back with my results.
Thanks for the info!
Thanks Again,
Matt
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Hey kglad, awesome, I got it to print to the Text Field now...! Thanks alot!
So does the following code look setup correctly to you?
Basically the Flash program will receive the XML Data using the XMLSocket Class. Then when the XML data is received the "dataHandler()" function gets called, then I capture the XML Data's "nodes" into a couple different String Variables inside the "dataHandler()" function. Then inside my "datahandler()" Function I have your line of code that declares a listener for the frame renderer function. After that I have a "switch" statement which checks the XML Data for the Node that tells us which Frame to display (*variable --> "screenToDisplay").
Does the line that declares the EventListener for the RenderF() Function need to be in a certain location? Or should I keep it in the "dataHandler()" Function, which is where it is now? *See code below...
Here is my Actionscript Code:
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.events.DataEvent;
import flash.text.TextField;
//Declare Some String Variables to capture each 'node' from the XML Data:
var screenToDisplay:String, agentsReady:String, unavailableAgents:String, talkingAgents:String;
var totalCalls:String, callsHandled:String, ABDRate:String;
// Create new XMLSocket Object:
var socket = new XMLSocket();
// Declare Event Listeners:
socket.addEventListener(Event.CONNECT, connectHandler);
socket.addEventListener(Event.CLOSE, closeHandler);
socket.addEventListener(DataEvent.DATA, dataHandler);
socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
socket.addEventListener(ProgressEvent.PROGRESS, progressHandler);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
//Frame 5 is the "Welcome/Home" Screen: (*Go to Welcome screen and Stop...)
WBDMovie.gotoAndStop(5);
//Establish a Socket Connection with the server pushing out the XML Data:
var success = socket.connect('csrboard.domain.local',3004);
//Write to the "msgArea" Text Field, whether or NOT the Connection was successful
if (success) {
msgArea.appendText("Page_Load: OK --- " + success + "\n");
}
else {
msgArea.appendText("Page_Load: NOT-OK --- " + success + "\n");
}
//FUNCTION: closeHandle() - Listener for when the Connection is CLOSED:
function closeHandler()
{
msgArea.appendText("closeHandler(): CLOSE HANDLER\n");
}
//FUNCTION: connectHandler() - Listener for when a Connection is made:
function connectHandler(success) {
if (success) {
msgArea.appendText("connectHandler(): CONNECTION HANDLER SUCCESS\n");
}
else {
msgArea.appendText("connectHandler(): CONNECTION HANDLER FAILED\n");
}
}
//FUNCTION: dataHandler() - Listener for incoming XML Data:
// *This Function will be executed everytime new data is received on port 3004
function dataHandler(e: DataEvent):void
{
//Create NEW XML Variable Type called 'xml':
var xml:XML = XML(e.data);
//If the Socket is connected, then capture the XML Data into some string variables:
if (socket.connected)
{
// Capture the XML Data and set them to the String Variables declared at start of script:
screenToDisplay = xml.MESSAGE[0].@TEXT;
agentsReady = xml.MESSAGE[1].@TEXT;
unavailableAgents = xml.MESSAGE[2].@TEXT;
talkingAgents = xml.MESSAGE[3].@TEXT;
totalCalls = xml.MESSAGE[4].@TEXT;
callsHandled = xml.MESSAGE[5].@TEXT;
ABDRate = xml.MESSAGE[6].@TEXT;
// Call the "invalidate()" method, which I think tells Flash that the current Frame/Stage is now "invalid" and
// that we need to "re-render" it...?
stage.invalidate();
// Add the EventListener for when a new Frame is Rendered...??
WBDMovie.addEventListener(Event.RENDER,renderF);
// Read the 'screenToDisplay' string and execute the correct case below:
switch (screenToDisplay){
case "showFrame_1":
// Since the "screenToDisplay" == "showFrame_1", Go To Frame 1 and STOP:
WBDMovie.gotoAndStop(1);
trace("IN SWITCH: Found the Screen to Display is 'showFrame_1'");
break;
case "showFrame_2":
// Since the "screenToDisplay" == "showFrame_2", Go To Frame 2 and STOP:
WBDMovie.gotoAndStop(2);
trace("IN SWITCH: Found the Screen to Display is 'showFrame_2'");
break;
}
}
}
//FUNCTION: renderF() - Listener for Frame Rendering:
function renderF(e:Event):void
{
// Tell me in the "Output Window" if this function is being called...
trace("IN Function 'renderF'...");
// Write the "agentsReady" String Variable to the Text Field with Instance Name "F1_agentsReady":
WBDMovie.F1_agentsReady.text = agentsReady;
}
//FUNCTION: ioErrorHandler() - Listener for I/O Errors:
function ioErrorHandler(event:IOErrorEvent) {
msgArea.htmlText += "ioErrorHandler(): " + event + "\n";
}
//FUNCTION: progressHandler() - Listener for Progress:
function progressHandler(event:ProgressEvent) {
msgArea.htmlText += "progressHandler() loaded:" + event.bytesLoaded + " total: " + event.bytesTotal + "\n";
}
//FUNCTION: securityErrorHandler() - Listener for Security Errors:
function securityErrorHandler(event:SecurityErrorEvent):void {
msgArea.htmlText += "securityErrorHandler(): " + event + "\n";
}
So in the code above does that look "setup" correctly to you?
Also, what "event" actually causes the "renderF()" function to execute? Does it execute after the "WBDMovie.gotoAndStop(1);" line is executed?
AGAIN, thank you for the info, very much appreciated!
Thanks Again,
Matt
Copy link to clipboard
Copied
add the render listener whenever you want.
invalidate the stage just prior to the goto statement.
flash player does not normally dispatch render events because they use resources (often unnecessarily). when you invalidate() the stage, flash player will dispatch render events for all display objects on the next clock cycle (ie, after the next enterframe loop ~~ 1000seconds/fps).
if you invalidate the stage more than once, remove unneeded render event listeners.
Copy link to clipboard
Copied
Hey kglad, thanks again for the reply.
Sorry for the delayed response, I had to deal with some other pressing issues here at work, so I kinda had to put this off for a bit, but I'm back...
Ok so, since you said to make sure the "invalidate()" is issued just prior to the "gotoAndStop()" command does that mean in the example below that I should issue "invalidate()" within each "case" or is it ok to just issue "invalidate()" once just before the "switch" statement?
//Function to handle Event when the XML data is received:
function dataHandler(e: DataEvent):void
{
// Issue "invalidate()" ONLY once before the switch statement???
// *The switch statement controls what screen/frame we want to display...
stage.invalidate();
switch (screenToDisplay) {
case "CSQ_1":
WBDMovie.gotoAndStop(1);
trace("Found 'CSQ_1', so display Frame 1");
break;
case "CSQ_2":
WBDMovie.gotoAndStop(2);
trace("Found 'CSQ_2', so display Frame 2");
break;
:
:.....etc..... more cases.....
}
}
// END: dataHandler() EventListener
// Render Event Listener:
function renderF(e:Event):void
{
trace("IN Function 'renderF'...");
// you can now reference objects created in frame 1 of WBDMovie.
// *Print to Text Field in Frame 1
WBDMovie.F1_agentsReady.text = agentsReady;
}
Thanks again for the replies!
Thanks Again,
Matt
Copy link to clipboard
Copied
once before the switch statement (like you showed) is good.
Copy link to clipboard
Copied
Ok, good...
Thanks Again,
Matt
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now