A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [F8] Wait Until a Function Completes Processing

  1. #1
    Junior Member
    Join Date
    May 2007
    Posts
    8

    [F8] Wait Until a Function Completes Processing

    Hi all,

    I’ve got two functions that need to process. I need the second one “nowGoDoSomeMoreStuff” to wait until the first one “goDoABunchOfStuff” is done processing. goDoABunchOfStuff’s processing time can vary from half a second to about 30 seconds so I can’t do a simple timed delay. Anyone know how to do it? Thanks…


    Code:
    goDoABunchOfStuff();
    //I need flash to wait until the first function completes processing
    nowGoDoSomeMoreStuff();
    
    function goDoABunchOfStuff()
    	{
    		ABunchOfStuff
    	}
    
    function nowGoDoSomeMoreStuff()
    	{
    		SomeMoreStuff
    	}

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    depends on the stuff it you can somehow send a signal that the last stuff has been done, you can call the second function in the else of the first.

    gparis

  3. #3
    Junior Member
    Join Date
    May 2007
    Posts
    8
    I guess it does. Here is what I'm doing:
    Code:
    sayHiToVbNet();
    /////////////////////////////////////////////////////////////////////////////
    function sayHiToVbNet()
    {
    	var assignmentString = "Monday,0015a4cd124a"
    	getURL("FSCommand:sending", assignmentString);
    	keepWaitingForResponse(); // call the flash function
    } // End of the function
    /////////////////////////////////////////////////////////////////////////////
    // this function doesn’t go ahead until the VBCalling is set from VB
    function keepWaitingForResponse() {
    	intervalID = setInterval(
    		function () { // this function is called every 100 ms until the intervalID is cleared
    		if (VBCalling != _level0.VBCalling) {
    			VariableReturned(VBCalling);
    		}
    	}, 100);
    }
    /////////////////////////////////////////////////////////////////////////////
    // this function is called only after the variable is set from VB
    function VariableReturned(value) {
    	clearInterval(intervalID); // clear the interval and stop the looping
    	VBDone();
    }
    /////////////////////////////////////////////////////////////////////////////
    function VBDone(){
    						
    	fidelity = l1.text
    	procMon = l2.text
    	maxInterval = l3.text
    	minInterval = l4.text
    	abSecant = l5.text
    	abCos = l6.text
    	delta = l7.text
    		
    	tSpan = maxInterval - minInterval
    	trace(tSpan)
    }
    The flash file is hosted by a VB.NET Windows form. When the flash file loads it sends it's name and identity to VB. From there VB makes a call to a few databases, does a few calculations, and then sets the value of a textbox in Flash called VBCalling once VB is done processing. That all works. VB sets the value of VBCalling, and the values of a few other text boxes, in Flash and the looping stops. I can see the values set in the textboxes in flash. The problem lies with not being able to get Flash to do anything useful with the data once it has it (e.g., nothing in the function "VBDone()" will execute). Maybe I'm not clearing the interval properly? Not sure. Any help is appreciated...

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    can you use LoadVars instead of getURL(). The onLoad of LoadVars only triggers when vars have loaded successfully.

    gparis

  5. #5
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Hi,

    You can call the second function inside the first..

    Regarding the code in your 2nd post: maybe try to execute directly the contents of "VariableReturned" function and not use at all this function, I mean:
    PHP Code:
    sayHiToVbNet();
    /////////////////////////////////////////////////////////////////////////////
    function sayHiToVbNet()
    {
        var 
    assignmentString "Monday,0015a4cd124a"
        
    getURL("FSCommand:sending"assignmentString);
        
    keepWaitingForResponse(); // call the flash function
    // End of the function
    /////////////////////////////////////////////////////////////////////////////

    // this function doesn’t go ahead until the VBCalling is set from VB
    function keepWaitingForResponse() {
        
    intervalID setInterval(
            function () { 
    // this function is called every 100 ms until the intervalID is cleared
            
    if (VBCalling != _level0.VBCalling) {
                
    clearInterval(intervalID); // clear the interval and stop the looping
                
    VBDone();
                
    //VariableReturned(VBCalling);
            
    }
        }, 
    100);
    }
    /////////////////////////////////////////////////////////////////////////////



    /////////////////////////////////////////////////////////////////////////////
    function VBDone(){
                            
        
    fidelity l1.text
        procMon 
    l2.text
        maxInterval 
    l3.text
        minInterval 
    l4.text
        abSecant 
    l5.text
        abCos 
    l6.text
        delta 
    l7.text
            
        tSpan 
    maxInterval minInterval
        trace
    (tSpan)

    This is just a variation, as your code seems to be OK in general..
    (I did'nt see your code very detailed and don't know details of your VBnet, so maybe the problem is anything else)..

    Kostas
    K. Zotos online portfolio: http://www.in3d.eu

  6. #6
    Junior Member
    Join Date
    May 2007
    Posts
    8

    Sending and Receiving VB C# J# Flash

    I got everything working and I'm including the following text: sending and receiving VB C# J# Flash AxShockwaveFlash SetVariable
    if it will help anyone dealing with this problem (nightmare).

    Here's how I got Flash to talk to VB and VB to talk to Flash:

    First add a textbox to Flash called VBCalling
    Then copy and paste what you need from below
    Code:
    <<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
    <<<<<<<<<<<<<<<<Flash Script>>>>>>>>>>>>>>>>>>>>>>>>>>
    <<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
    
    VBCalling.text = "NoVBYet"
    sayHiToVbNet();
    /////////////////////////////////////////////////////////////////////////////
    function sayHiToVbNet()
    {
    	var assignmentString = "Monday"
    	getURL("FSCommand:sending", assignmentString);
    	keepWaitingForResponse(); // call the flash function
    } // End of the function
    /////////////////////////////////////////////////////////////////////////////
    // this function doesn’t go ahead until the VBCalling is set from VB
    function keepWaitingForResponse() {
    	intervalID = setInterval(
    		function () { // this function is called every 100 ms until the intervalID is cleared
    		if (VBCalling.text != "NoVBYet") {
    			VariableReturned(VBCalling);
    		}
    	}, 100);
    }
    /////////////////////////////////////////////////////////////////////////////
    // this function is called only after the variable is set from VB
    function VariableReturned(value) {
    	clearInterval(intervalID); // clear the interval and stop the looping
    	VBDone();
    }
    /////////////////////////////////////////////////////////////////////////////
    function VBDone(){
    						
    	fidelity = l1.text
    	procMon = l2.text
    	maxInterval = l3.text
    	minInterval = l4.text
    	abSecant = l5.text
    	abCos = l6.text
    	delta = l7.text
    		
    	tSpan = maxInterval - minInterval
    	trace(tSpan)
    }
    Code:
    <<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
    <<<<<<<<<<<<<<<<VB Script>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    <<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
    Private Sub AxShockwaveFlash1_FSCommand(ByVal sender As Object, ByVal e As AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEvent) Handles AxShockwaveFlash1.FSCommand
            If e.command = "sending" Then
                If e.args = "Monday" Then
                    mondayQuery(e.args)
                End If
            End If
        End Sub
    
    Public Function mondayQuery(ByVal dayIn As String)
            Dim day As String = dayIn
    
            Dim fidelity As String = "60"
            Dim procMon As String = "alpha2"
            Dim maxInterval As String = "100"
            Dim minInterval As String = "9"
            Dim abSecant As String = "17.0"
            Dim abCos As String = "1.2"
            Dim delta As String = "1"
    
            Call AxShockwaveFlash1.SetVariable("l1.text", fidelity)
            Call AxShockwaveFlash1.SetVariable("l2.text", procMon)
            Call AxShockwaveFlash1.SetVariable("l3.text", maxInterval)
            Call AxShockwaveFlash1.SetVariable("l4.text", minInterval)
            Call AxShockwaveFlash1.SetVariable("l5.text", abSecant)
            Call AxShockwaveFlash1.SetVariable("l6.text", abCos)
            Call AxShockwaveFlash1.SetVariable("l7.text", delta)
            Call AxShockwaveFlash1.SetVariable("VBCalling", "Hi Flash")
    
            Return day
        End Function
    VB changes the text value of VBCalling from NoVBYet to Hi Flash, the loop terminates, flash has the focus of control again, and flash has all the variables from VB to work with.

  7. #7
    Junior Member
    Join Date
    May 2007
    Posts
    8
    Thanks gparis and Kostas Zotos

  8. #8
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Your welcome!

    Is it possible to tell us the Browser, OS , and flash player version where you have test it ?

    (I am saying that because it is not completely clear if the "SetVariable" method and even the fscommand is working in a broad number of OS/Browsers/FlashPlayer versions)

    I know cases with old code based on "SetVariable", fscommand in which there are problems when comes to pass data from script languages back to flash, especially in non IE browsers..


    Thank you in any case!

    Kostas
    K. Zotos online portfolio: http://www.in3d.eu

  9. #9
    Junior Member
    Join Date
    May 2007
    Posts
    8
    Yes, that is important. The motivation behind this is to create attractive and powerful GUIs that use VB on the back end for data handling. No browsers are involved yet. The host is a Windows form in Visual Studio 2005. The OS is Windows XP Pro. Macromedia Flash is version 8. Flash Player version uses Flash9d.ocx. The version of the ocx is important, because I could not get VS2005 to work with the current version that comes with flash player. Some people have been able to get it working in VS2005 but I'll distribute with Flash9d. If I have any further troubles/successes I'll post back here...

    Hope that helps,
    Jeff

  10. #10
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    OK,

    Thanks for the detailed report!

    From my tests, the "SetVariable" method not work with Flash Player 9 (in Netscape, Mozilla and Opera) in Windows
    Also in Flash Player 8 not work in Opera too..

    I think is not a "reliable" method for passing data from script languages in browsers back to Flash.. and the external Interface alternative is not also a cross browsers/platform solution yet..

    Bye!
    K. Zotos online portfolio: http://www.in3d.eu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center