Loading local libraries


I’m trying to load a library from a webfile, but get the error;

Failed to load resource: the server responded with a status of 404 (OK)

The code in the Open event is: (I know I should make wf a shared property, but for the sake of this problem, I left it like this)

  dim f as FolderItem
  dim wf as WebFile
  #if DebugBuild
    f = GetFolderItem("").Parent.Child("createjs-2013.12.12.min.js")
    f = GetFolderItem("").Child("createjs-2013.12.12.min.js")
  if f.Exists then
    wf = WebFile.Open(f)
    LoadLibraries("setTimeout(XojoCustom.alwaysbusy.abwebcanvas.init('"+ self.controlID + "'),10);", wf.URL)
  end if
  RaiseEvent Open()

The following code, using the http:// works fine:

LoadLibraries("setTimeout(XojoCustom.alwaysbusy.abwebcanvas.init('"+ self.controlID + "'),10);", "http://code.createjs.com/createjs-2013.12.12.min.js")

This is my SetupJavascriptFramwork:

  Dim s() as String
  //               Created by alain on 25/09/2014.
  s.Append ""
  s.Append "var stage, w, h;"
  s.Append "var controlID;"
  s.Append ""
  s.Append "XojoCustom.alwaysbusy.abwebcanvas.init = function init(cControlID) {"
  s.Append "    if (window.top != window) {"
  s.Append "        document.getElementById('header').style.display = 'none';"
  s.Append "    }"
  s.Append ""
  s.Append "    controlID=cControlID;"
  s.Append ""
  s.Append "    stage = new createjs.Stage(controlID);"
  s.Append ""
  //                  grab canvas width and height for later calculations:
  s.Append "    w = stage.canvas.width;"
  s.Append "    h = stage.canvas.height;"
  s.Append "    console.log(w + 'x' + h);"
  s.Append "};"
  Return Join(s, "")

I’ve tried putting createjs-2013.12.12.min.js next to the exe and in the resources folder. If it’s next to the exe, the GetFolderItem("").Parent.Child(“createjs-2013.12.12.min.js”) works, wf = WebFile.Open(f) gives no error but loadlibraries gives the above error in the browser.

Thanks again in advance!


Your WebFile is going out of scope before the framework has a chance to use it. Make it a shared property like you were going to.

You have to be kidding me :slight_smile: Skipping some steps to do some quick tests is never good. Thought this was just needed for multiple sessions.

Thanks again Greg! It is quite a step coming from pure javascript/php/html to Xojo’s logic for me, but I’m getting the hang it :slight_smile:

Hi Greg,

maybe your suggestion will solve my current problem same with Alain.
Kindly please share me a sample snippet of how to have “shared property” that you mentioned above?

I do believe xojo20xxrx/Extras/WebSDK/Examples/LoadingLibraries.xojo_binary_project implements a webfile in a shared property to load a JS library.

Thanks Daniel.

I will look into it.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.