PDA

View Full Version : Newbie: Getting Display To Update from setInterval function callback. (First Post)


KShapiro
05-05-2006, 09:56 PM
Hi All,

Please forgive me. I am completely new to this stuff, and I am going to post several questions over the next week or so. Unfortunately, I am trying to do some things in areas of several new technologies for me. I am new to Windows, C#, .Net, Flash, and ActionScript, and the project that the company I work for has me working on right now uses all of those technologies.

I will try to break my questions into small chunks so that they are as simple as I think I can make them in order to post the questions. I thank you for your tolerance, and assistance. :o

In the example below I have one frame and some actionscript on an actions layer located on frame 1. I have a couple of dynamic text fields with different instance names, and I am trying to write text into those fields.


(Code for buttons not included, since I don't believe they will make any difference in helping. If you need them, please let me know).
I have two buttons and handlers for them that when called, increment a number and that number is then inserted into one of the dynamic text fields. That seems to work, and the value increases and decreases as necessary.

The problem comes in the setInterval callback. I created a function that increments a counter, and takes the value of that counter and places it into the other dynamic text field. That function is then installed into a setInterval call. However, the textfield never seems to update to the new values. I even included a call to something I read would force the display to update from setInterval calls, but that doesn't work either.

I would appreciate any assistance I can get. I have several of these kinds of problems that I believe are probably easy for someone else to answer, but I don't know the answers to. I look forward to my experiences on this board, and if there is anything I can answer for others, please know I will. Please find my code listed just below.

Just as an FYI, I am including the FlashPlayer control on a panel inside a C# program which I am creating with Visual Studio .Net. I am communicating between ActionScript and C# .Net using the ExternalInterface API. I don't have that working well yet, but a simple single function is working. This will be important information when I eventually post my other questions.



import flash.external.ExternalInterface;

// See if the Container even offers an External Interface.
var bIsExternalInterfaceAvail = ExternalInterface.available;
// Register all the externally available functions
var bIsRegSetBetVal:Boolean = ExternalInterface.addCallback( "SetBetVal", this, SetBetVal );
var bIsRegDisplayScrnStartup:Boolean = ExternalInterface.addCallback( "DisplayScrnStartup", this, DisplayScrnStartup );

var iIntervalCnt01:Number = ( 0 );


trace("We Entered Our Movie.");
trace("Start SetInterval Function.");
setInterval( DisplayScrnStartup, 5000 );
trace("Finished SetInterval Function.");
trace("Start Call to RequestInitialBetAmount Function.");

// Kept out for now since debugger seems to not work
// after the call.
//ExternalInterface.call( "RequestInitialBetAmount" );

trace("Finished Call to RequestInitialBetAmount Function.");
Mouse.hide(); // Hides the Mouse from the Screen. (We are using TouchScreen).
stop(); // I understand this to mean playhead stops, not Actionscript code.
trace("Finished Frame 1.");


// Sets the Text in a Dynamic Field to be a Value.
// This function works, and the screen display is updated.
function SetBetVal( a_CurBetVal:Number ):Void
{
trace("Setting the Bet Value to " + a_CurBetVal + " value." );
this.sampleField.text = ( a_CurBetVal.toString() );
}


// This function tells the system to display the StartUp Screen.
// For now this function just tries to update another dynamic text
// box on screen. Though this doesn't work.
function DisplayScrnStartup()
{
trace("Inside DisplayScrnStartup.");
// this.gotoAndStop( "Scrn_Startup" );
this.iIntervalCnt01 = ( this.iIntervalCnt01 + 1 );
var szIntervalCnt:String = this.iIntervalCnt01.toString();
this.SetIntervalCnt01.text = ( szIntervalCnt );

/*
I even tried updating the other Dynamic Text field that was
working and being updated just to see if that one would update
and this one wouldn't. However, now both wouldn't update.
*/
//this.sampleField.text = ( szIntervalCnt );

// Tell the system to update the display since this function
// inside a setInterval callback, updated display items.
updateAfterEvent();
}



Also, in the future, would it be easier or better or both for me to simply attach a .zip file with the code file?

Thanks.

Sincerely,
Kevin Shapiro