A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: ExternalInterface question

  1. #1
    Senior Member
    Join Date
    May 2005
    Location
    Wisconsin
    Posts
    181

    ExternalInterface question

    How would I call this javascript function and recieve the error code back if any.


    code:

    import flash.external.ExternalInterface;
    ExternalInterface.call("SCOInitialize", My_error );

    function My_error(err:String )
    {
    mytext_txt.text = err;

    }





    My java script function
    Code:
    function SCOInitialize() {
    	var err = true;
    	if (!g_bInitDone) {
    		if ((window.parent) && (window.parent != window)){
    			g_objAPI = FindAPI(window.parent)
    		}
    		if ((g_objAPI == null) && (window.opener != null))	{
    			g_objAPI = FindAPI(window.opener)
    		}
    		if (!APIOK()) {
    			AlertUserOfAPIError(g_strAPINotFound);
    			err = false
    		} else {
    			err = g_objAPI.LMSInitialize("");
    			if (err == "true") {
    				g_bSCOBrowse = (g_objAPI.LMSGetValue("cmi.core.lesson_mode") == "browse");						if (!g_bSCOBrowse) {
    					if (g_objAPI.LMSGetValue("cmi.core.lesson_status") == "not attempted") {
    						err = g_objAPI.LMSSetValue("cmi.core.lesson_status","incomplete")
    					}
    				}
    			} else {
    				AlertUserOfAPIError(g_strAPIInitFailed)
    			}
    		}
    		if (typeof(SCOInitData) != "undefined") {
    			// The SCOInitData function can be defined in another script of the SCO
    			SCOInitData()
    		}
    		g_dtmInitialized = new Date();
    	}
    	g_bInitDone = true;
    	return (err + "") // Force type to string
    }
    Josh
    Multimedia Programmer
    flashmajic.com

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Code:
    import flash.external.ExternalInterface;
    
    var err:String = ExternalInterface.call("SCOInitialize");
    
    My_error(err);
    
    function My_error(err:String ):void{
    	mytext_txt.text = err;
    }
    SCOInitialize does not take any arguments, but you were trying to pass My_error as one. The return value of SCOInitialize was being thrown away, but that's what you wanted to pass to My_error.

  3. #3
    Senior Member
    Join Date
    May 2005
    Location
    Wisconsin
    Posts
    181
    Your correct i don't want to pass anything to sco initialize. Thanks for correcting my code.
    Its throwing an error and the swf will not run now though

    TypeError: Error #2007: Parameter text must be non-null.
    at flash.text::TextField/set text()
    at simple_fla::MainTimeline/My_error()
    at simple_fla::MainTimeline/frame1()
    Josh
    Multimedia Programmer
    flashmajic.com

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Looks like the return value from the javascript was null. You'll need to check for that in your function.

  5. #5
    Senior Member
    Join Date
    May 2005
    Location
    Wisconsin
    Posts
    181
    Thanks I got it corrected now.
    Josh
    Multimedia Programmer
    flashmajic.com

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