[Solved] Why these two codes are not working in js mode ? Difficult debuggin in js mode.

edited May 2014 in JavaScript Mode

Hello, I am trying to run these code in js mode but none of them working. Each of them just show grey color blacnk screen, nothing else.

I found the same problem in so many blogs but everyone has their own different solution for different issue.

In the chrome console I see this error: "Uncaught Processing.js: Unable to execute pjs sketch: TypeError: undefined is not a function "

 //Code 1
PShape MouseShape;
PShape mright;
PShape mleft;
PShape mwheel;
PShape mcursor;
PShape[] Children;
void setup() {
  size(400, 300);
  MouseShape = loadShape("C:/Users/FB-Abhniv/Documents/Processing/SVGtesting/data/bot.svg");
  Children = MouseShape.getChildren();
  mleft    = MouseShape.getChild(Children[0].getName());
  mright   = MouseShape.getChild(Children[1].getName());
  mwheel   = MouseShape.getChild(Children[2].getName());
  mcursor  = MouseShape.getChild(Children[3].getName());

void draw() {
  translate(width/4, 0);
  shape(MouseShape, 0, 0);

  if (Rflag) {
    shape(mright, 0, 0);
  if (Lflag) {
    shape(mleft, 0, 0);
  if (mW>0)fill(#5000FF);
  else if (mW<0)fill(#00FF28);
  else fill(0);
  shape(mwheel, 0, 0);
  shape(mcursor, 0, mW*20);
boolean Lflag, Rflag;
void mousePressed() {
  if (mouseButton==LEFT) Lflag = true;
  else Lflag = false;
  if (mouseButton==RIGHT) Rflag = true;
  else Rflag = false;

void mouseReleased() {
  Rflag = false;
  Lflag = false;
float mW;
void mouseWheel(MouseEvent event) {
  mW = event.getCount();

//Code 2
import ddf.minim.analysis.*;
import ddf.minim.*;

Minim       minim;
FFT         fft;
ArrayList<Float> poop = new ArrayList();
int bufferSize=512;
int highest=0;
float[] sample;
void setup()
  size(800, 300, P3D);
  minim = new Minim(this);
  fft = new FFT( bufferSize,50000); //  FFT(int timeSize,float sampleRate)

void draw()
  sample = new float[poop.size()];
  for (int i=0;i<poop.size();i++) {
    Float f = (float) poop.get(i);
    sample[i] = f;
  if (poop.size()< bufferSize) {
    float t = map(mouseX, 0, width, 0, bufferSize);
  else poop.remove(0);

  line(width/2, 20, mouseX, 20);
  if (sample.length==bufferSize) {
    for (int i = 0; i < fft.specSize(); i++)
      stroke(0, 255, 0);
      float x = map(i, 0, fft.specSize(), 0, width);
      line( x, height, x, height - fft.getBand(i)/50.0);
      //-----------------For getting the highest frequency ----
//      if (fft.getFreq(i) >= fft.getFreq(highest)) {
//        highest=i;
//        float freq = fft.getFreq(highest);
//        println( " Band" + fft.getBand(i) +  " freq" + freq );
//      }
      //-----------------For getting the highest frequency ----
  else   println(poop.size());


  • The second uses the Minim library which is not compatible with JS mode. Not sure about the first one.

    It can be confusing but sketches created in JAVA mode are not always compatible with JavaScript mode.

  • It looks like you're trying things that aren't supported in JS mode.

    1. I don't see a getChildren() in either the Processing or Processing.js references. I'm also not sure about the mousewheel events, I don't see them in the reference either. Does this run in Java mode?

    2. Minim isn't available in JS mode. Although someone has done some work in that direction, the APIs are different (see here for more info).

  • edited May 2014

    @velvetkevorkian Thanks for the reply :) I am sorry but these all are available in processing. Here are the links

    1. mouseWheel()
    2. getChildren()

      Yes these codes run perfectly in java mode.

    About the minim in js mode. I have the same doubt but you can see so many code available on openprocessing.org are using minim library. I dont know how those codes work without any hindrenc.

    @Quark: Thanks again :) You are correct. Minim might not be compatible with js mode but there are so many examples on openprocessing.org uses minim library and they work absolutly fine.

    Here minim in js CODE

  • That's a Java applet, not processing.js.

  • Answer ✓

    All of the sketches that use Minim (including the one you link to) on Open Processing are Applets created in Java mode.

    Java and JavaScript are very, very different programming languages. In fact the biggest similarity is in their names (i.e. both start with Java)

    Because you can swap modes, Processing makes it look like you can create something in Java mode and expect it to work in JavaScript mode, this is not always true.

  • Sadly they are only available in processing not in js mode :(

  • For your first code, if you remove the getChildren() and load individual SVGs instead your code compiles in JS mode. I'm pretty sure that's the issue there.

    If I recall correctly there were a lot of changes to PShape in the move to 2.0, which processing.js isn't up to date with.

  • @Quark: I am really confused. :(( If I want to upload my code in openprocessing the I would have to change the mode in processing to javascript mode and export the web applet and zip it and upload it there. I did that too but no luck. How can I create applet using java mode ?

  • @velvetkevorkian. These are not the individual svg instead these are the chiIdren of main svg file and I called getChildren() becuase I didn't know the id of these children so I used this method. Is there any other way to get the id of the children ?

  • I think you would have to give them IDs inside the SVG file, then use getChild(id) on each one. Not 100% sure though, sorry. Alternatively you can create multiple SVGs and load them in separately.

  • oh that's painful :(( :(( :(( I did that becasue I wanted to avoid doing this. Actually I have create this svg in using illustrator and I dont know how to set the id in the illustrator.

  • edited May 2014

    Okay I got working my first code in js mode. I set the id for each children (googled it) and hacked the mouseWheel event for js mode B-)

    Here it is

    void mouseScrolled()
      if (mouseScroll > 0)
        val++; // positive scroll
        val--; // negative scroll

    But minim mystry is still uncracked :(( :((

  • @Quark Thanks you so much I found my answer in a old post where you have replied the method to get the applet in java mode :) Thanks again


Sign In or Register to comment.