Search code examples
migrationopenlaszlolzx

Migrating code from OpenLaszlo 3.3 to 5.0: TypeError #1007 Instantiation attempted on a non-constructor.


I ported some parts of the code from OL 3.3 to OL 5.0 recently. I thought that everything will work but when i try to run it using the ant script i have I am getting this error.

 [echo] C:\Program Files\OpenLaszlo Server 5.0.x\Server\lps-5.0.x/WEB-INF/lps/server/bin/lzc.bat
 [exec] Compiling: C:\Workspace\application\client\src\TestClient.lzx to TestClient.swf10.swf
 [exec] compiler output is Loading configuration file C:\Program Files\OpenLaszlo Server 5.0.x\Server\lps-5.0.x\WEB-INF\frameworks\flex-config.xml
 [exec] C:\Documents and Settings\310773\Local Settings\Temp\lzswf9\Workspace\application\client\src\build\TestClient\app.swf (289808 bytes)

So, I took the folder and i compiled it directly in Laszlo. It's not showing any error but when the swf is about to load the main page I am getting this error. Any idea why?

TypeError: Error #1007: Instantiation attempted on a non-constructor.
    at $lzc$class__mvz/$mvx()
    at LzNode/__LZresolveReferences()
    at LzNode/__LZcallInit()
    at LzCanvas/__LZcallInit()
    at LzCanvas/__LZinstantiationDone()
    at LzInstantiatorService/makeSomeViews()
    at LzInstantiatorService/checkQ()
    at Function/http://adobe.com/AS3/2006/builtin::call()
    at LzEvent/sendEvent()
    at LzIdleKernel$/__update()

Solution

  • That's the error message you get when you try to instantiate a class which is not defined. Here is an example:

    <canvas>
    
      <class name="myclass">
        <handler name="oninit">
          // Instantiate a class which is not defined
          var x = new lz.missingclass();
        </handler>
      </class>
    
      <myclass />
    
    </canvas>
    

    Check for missing <includes> of classes which are being instantiated through scripts. You can always check the list of Adoboe Flash Run-Time Errors as well, sometimes there is useful information contained here.

    Edit: Solution to problem added
    This commment pointed to the problem:

    I found that this line is causing the problem. <attribute name="dp" value="$once{new lz.Datapointer()}" />. Any idea why?

    If you check the OpenLaszlo reference for 5.0, you will see that the class names (on the left side in the class browser) use different case; some classes use camel case (lz.Browser, lz.DataElement), others use all lowercase (lz.view, lz.datapointer). In your case, you should have used lz.datapointer instead of lz.Datapointer.

    Therefore this code will compile and run without any problems:

    <canvas>
    
      <class name="my_class" extends="node">
          <attribute name="dp" value="$once{new lz.datapointer()}" />
      </class>
    
      <my_class oninit="Debug.inspect(this.dp)" />
    
    </canvas>
    

    A good way to test for the correct name of a class is to use the JavaScript in console in DHTML runtime, where you have auto-completion for lz.??? classnames:

    Auto-completion for LZX class names in the browser JavaScript console

    Debugging SWF #1007 errors in OpenLaszlo
    If you run into a #1007 error in the SWF runtime, I would compile the application for DHTML with the debugger disabled and the JavaScript error console open. Try this:

    1. Change the line of with the $once{} constraint to

      <attribute name="dp" value="$once{new lz.Datapointer()}" />

    2. Compile the app in Chrome using DHTML runtime and debug=false. You should see the following error in the JavaScript console:

    Error for undefined class in JavaScript console

    1. Click on the right side on error-1007.lzx:3, and you'll see the generated JavaScript code with the line causing the error

    JavaScript error in code generated by the OpenLaszlo compiler

    This line fails:

    this.setAttribute("dp",new (lz.Datapointer)())
    

    and you can even reproduce the error by typing new (lz.Datapointer) into the console.