Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Contributor
Posts: 3
Registered: ‎04-27-2011
My Device: Any
My Carrier: Maybe

Web Worker in BlackBerry

Hi, I have tree text boxes. I want that when the two first recieve input, my worker checks if those input are numerics. If yes, it turn them into a string and send them to the main page as the value of the third one. But I don't know why it's not working. Both are writen in different file: I mean no java script in the html markup.

Here are.

FUNCTION executed by the worker

 

// JScript source code
/* Code that will be run by the worker */
function applyChanges(radius, size) {
    // check if those are numerics
    if (!isNaN(radius) && !isNaN(size)) {
        // verify that the won't hide more the 1/4 of the circle.
        if (radius >= size / Math.SQRT2) {
            // since we are going to test scrolling and zooming, we are not going to  set max values of radius and size.
            return radius + "," + size;
        }
        else {
            alert("The radius must not be less that: size/sqrt(2)");
        }
    }
    else {
        alert("Required numeric type!");
    }
}
/*
Add an event listener to the worker, this will be called when      
the worker receives a message from the main page.
*/
this.onmessage = function(event) {
    var data = event.data;
    // Message sent by the worker to the main page.
    postMessage(applyChanges(data.radius, data.size));
}

 

// JScript source code
/* Code that will be run by the worker */
function applyChanges(radius, size) {    // check if those are numerics    if (!isNaN(radius) && !isNaN(size)) {        // verify that the won't hide more the 1/4 of the circle.        if (radius >= size / Math.SQRT2) {            // since we are going to test scrolling and zooming, we are not going to  set max values of radius and size.

            return radius + "," + size;
        }        else {            alert("The radius must not be less that: size/sqrt(2)");        }    }    else {        alert("Required numeric type!");    }}
/*Add an event listener to the worker, this will be called when      the worker receives a message from the main page.*/this.onmessage = function(event) {    var data = event.data;
    // Message sent by the worker to the main page.    postMessage(applyChanges(data.radius, data.size));}

 

WORKER

 

// JScript source code

 

/* Worker's code */

 

// Create a new worker

var myWorker = new Worker("workerScript.js");

/*

Add a event listener to the worker, this will be called whenever the worker posts any message.

*/

myWorker.onmessage = function(event) {

    document.getElementById().value = event.data;

};

 

// Register events for button.

document.getElementById("button").onclick = function() {

    var circle = document.getElementById("tcircle");

    var square = document.getElementById("tsquare");

    var radius = circle.value;

    var size = square.value;

 

 

            message = { "tcircle": radius, "tsize": size };

 

            // Message sent by the main page to the worker.

            myWorker.postMessage(message);

}

 

// Terminate the worker.

myWorker.terminate();