Forum

Problem with anchors

24 September 2016 16:31 #12060
Hey guys, I have a question

I try to put a custom html object on an anchors for a empty object.

problem is when I try this on an bundled style project it works fine no problem
But in a non bundled external project as soon as I have a HTML element with the good ID the scene stop loading.
Any idea why? what am I missing here?

here are the code for the bundled project :
"use strict"

// register the application module
b4w.register("test", function(exports, require) {

// import modules used by the app
var m_app       = require("app");
var m_data      = require("data");

/**
 * export the method to initialize the app (called at the bottom of this file)
 */
exports.init = function() {
    m_app.init({
        canvas_container_id: "main_canvas_container",
        callback: init_cb,
        show_fps: true,
        console_verbose: true,
        autoresize: true
    });
}

/**
 * callback executed when the app is initialized 
 */
function init_cb(canvas_elem, success) {

    if (!success) {
        console.log("b4w init failure");
        return;
    }

    // ignore right-click on the canvas element
    canvas_elem.oncontextmenu = function(e) {
        e.preventDefault();
        e.stopPropagation();
        return false;
    };

    load();
}

/**
 * load the scene data
 */
function load() {
	
	    var torus_text = document.createElement("span");
    torus_text.id = "buttonPlay";
    torus_text.style.position = "absolute";
    torus_text.style.padding = "5px";
    torus_text.style.visibility = "hidden";
		var torus_img = document.createElement("img");
	torus_img.src = "Images/B_play.png";
	torus_img.atl = "the button";
	torus_img.height = "42";
	torus_img.width = "75";
	torus_text.appendChild(torus_img);

    document.body.appendChild(torus_text);
	
    m_data.load("test.json", load_cb);
}

/**
 * callback executed when the scene is loaded
 */
function load_cb(data_id) {
    m_app.enable_camera_controls();

    // place your code here

}


});

// import the app module and start the app by calling the init method
b4w.require("test").init();


and the one for the non bundled external project :
"use strict"


// register the application module
b4w.register("JumboConf", function(exports, require) {

// import modules used by the app
var m_app       = require("app");
var m_cfg       = require("config");
var m_data      = require("data");
var m_preloader = require("preloader");
var m_ver       = require("version");



// detect application mode
var DEBUG = (m_ver.type() == "DEBUG");

// automatically detect assets path
var APP_ASSETS_PATH = m_cfg.get_std_assets_path() + "JumboConf/";

/**
 * export the method to initialize the app (called at the bottom of this file)
 */
exports.init = function() {
    m_app.init({
        canvas_container_id: "main_canvas_container",
        callback: init_cb,
        show_fps: DEBUG,
        console_verbose: DEBUG,
        autoresize: true
    });
}

/**My function
*/
function CreateBt(id, source, hgt, wht, altern) {
	
	var btText = document.createElement("div");
        btText.id = id;
        btText.style.position = "absolute";
        btText.style.padding = "5px";
	btText.style.visibility = "hidden";
	var btImage = document.createElement("img");
	btImage.src = "/Images/"+source;
	btImage.atl = altern;
	btImage.height = hgt;
	btImage.width = wht;
	btText.appendChild(btImage);
    document.body.appendChild(btText);
	
}

function IdeCration(){
	CreateBt("RotBts","Bt_choix.png","42","72","bt_play.png");
}	

 
/**
 * callback executed when the app is initialized 
 */
function init_cb(canvas_elem, success) {

    if (!success) {
        console.log("b4w init failure");
        return;
    }

    m_preloader.create_preloader();

    // ignore right-click on the canvas element
    canvas_elem.oncontextmenu = function(e) {
        e.preventDefault();
        e.stopPropagation();
        return false;
    };

    load();
}

/**
 * load the scene data
 */
function load() {
	IdeCration();
	m_data.load(APP_ASSETS_PATH + "JumboConf.json", load_cb, preloader_cb);

}

/**
 * update the app's preloader
 */
function preloader_cb(percentage) {
    m_preloader.update_preloader(percentage);
}

/**
 * callback executed when the scene data is loaded
 */
function load_cb(data_id, success) {

    if (!success) {
        console.log("b4w load failure");
        return;
    }

    m_app.enable_camera_controls();

    // place your code here

}


});

// import the app module and start the app by calling the init method
b4w.require("JumboConf").init();
26 September 2016 17:25 #12107
Hi,

what is printed in the browser console? Press F12
Development Lead | Twitter
26 September 2016 18:08 #12114
Hi, it says :
NS_ERROR_DOM_BAD_URI: Access to restricted URI denied
26 September 2016 18:14 #12115
Try running your app via a local webserver. Or better use Blend4Web's Project Manager to create and run apps.
https://www.blend4web.com/doc/en/project_manager.html
Development Lead | Twitter
26 September 2016 20:04 #12120
I tried on a local webserver an used the project manager to create the apps, still, does not work. even if i manually put an HTML object with one of the anchors ID in the HTML doc it freeze, a soon as I remove the object, everything works fine
26 September 2016 20:07 #12121
In fact if I create an object lse as ID it work, even in JS. It just stops when that is the ID of one of an anchors. anD everything works if all the file HTML, CSS JS and JSON are in the same directory..
 
Please register or log in to leave a reply.