We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › using the <embed> tag over <object> to
Pages: 1 2 
using the <embed> tag over <object> to (Read 2626 times)
Re: using the <embed> tag over <object>
Reply #15 - Nov 22nd, 2008, 4:16pm
 
I though your initial goal was to call a JavaScript function doing the smooth scroll to the given location.
The purpose was to provide a way to call this JS function with a parameter, the location to go to (I haven't looked at the library you indicate).

There is also some problems with your JS:

function DumbTest(message)
{
 function moveWindow (){window.location.hash="bottom";}
}

You define a function in a function... You don't use the parameter. And hash must get a "#bottom" parameter.
Re: using the <embed> tag over <object>
Reply #16 - Nov 22nd, 2008, 4:48pm
 
Thanks for contacting back. Here's the situation - I have anchors in my HTML which I link to with an a href, so there will be an anchor at the bottom of the page called <a name="Bottom"></a> and I will enable a link at the top to that with <a href="#Bottom">

The JavaScript I have (called jscrolls.js) will animate the scroll to the anchor, so instead of a single jutting motion, the screen gently scrolls down. You can see this working here by pressing the lower right button:

http://lovelago.googlepages.com/text_box7.html


What I need is to be able to click a java applet (the recursion one) and this link to an anchor on the same page, just like a normal a href image file would work, in the above example. The problem has been that links from the Java applets open in new windows or if in the same window it refreshes the page and the javascript that makes the page flow gently does not get a chance to work.

So, I  thought that passing a message from the java applet to a javascript hook inside the same page, to link to an anchor, would not refresh the page and then the javascript would then be able to scroll the page gently.

As I understand it what's happened now is that a message comes to the javascript in the html, form the java applet, and it produces a popup box. Instead of that message box, I need the javascript to go to an anchor on the same page. The javascript already there will then scroll the page nicely, hopefully.
Re: using the <embed> tag over <object>
Reply #17 - Nov 22nd, 2008, 5:43pm
 
I think I understood the goal already.

The Java applet calling JS doesn't necessarily produce a popup: it is just the JS routine displaying it with alert(), but you can do something else.

If you need to call the jscroll routine, you should have the Java code:

void mousePressed() {    
   JSObject win = (JSObject) JSObject.getWindow(this);
   String[] arguments = { "thispage.html", "Bottom" };
   win.call("ajaxpage", arguments);
}

and the JS code is already on the page, actually.
Or something like that: you are free to call any JS, with any number of arguments.

If you need to do a classical "jump to anchor", I already gave a solution elsewhere, IIRC.
Re: using the <embed> tag over <object>
Reply #18 - Nov 22nd, 2008, 7:48pm
 
I'm sorry to say but I just don't understand this anymore. Are you telling me I don't need the following because jscrolls is already on the page:

void mousePressed() {    
   JSObject win = (JSObject) JSObject.getWindow(this);
   String[] arguments = { "thispage.html", "Bottom" };
   win.call("ajaxpage", arguments);
}

and that I need this to jump to a link:

void mouseClicked()
{
 if (dist(mouseX, mouseY, width/2, height/2) < radius)
 {
   URL url = getDocumentBase();
//    System.err.println(url);
   try {
     URL anchor = new URL(url, "#2.5");
//      System.err.println(anchor);
     getAppletContext().showDocument(anchor);
   } catch (MalformedURLException e) {}
 }

I remember using that code dind't work for what I wanted, I've tried mashing them together and I don't understand enough about it to make it work. What I have is this and it doesn't work:

void mousePressed() {
 if (ms.isReady() && isMouseInDisk()) {
      JSObject win = (JSObject) JSObject.getWindow(this);
   String[] arguments = { "index.html", "Bottom" };
   win.call("ajaxpage", arguments);
}

in the html I still have the header code, which I probably don't need:

<script type="text/javascript" language="JavaScript">//<![CDATA[
function DumbTest(message)
{
 alert("This is a dumb test with a message:\n" + message);
}
//]]>
</script>


I don't need to call a JS routine do I? But then how to I link to an anchor without leaving the page and having it nicely scroll down. If it get complicated like this I just don't know what to do. Thanks.
Re: using the <embed> tag over <object>
Reply #19 - Nov 23rd, 2008, 10:57am
 
You can drop the DumbTest indeed, as the name implies, it was just for demonstration purposes.

I am sorry, I am too lazy to look into your JS library: does it works by intercepting a regular "jump to anchor" link call (how does it do that?) or, as I thought initially, by calling a JS function?

In the former case, you should indeed use the URL code. (How it "didn't work for what you wanted"?)
In the latter case, use the win.call. I don't the syntax for indicating it should remain on the current page.
Re: using the <embed> tag over <object>
Reply #20 - Nov 23rd, 2008, 8:22pm
 
Thanks for getting back to me, I reviewed the situation my end and realise what you were trying to do with the JavaScript call - to have it execute. When in fact the JavaScript intervenes when a normal anchor link is requested, so executing it would do nothing. I then went back to the earlier examples and decided to try again to get the Java applet linking:

Here's my code for the button:


private static final int WIDTH = 100;
private static final int HEIGHT = 100;
private static final int HWIDTH = (WIDTH / 2);
private static final int HHEIGHT = (HEIGHT / 2);
private static final float LENGTH = (HEIGHT * .6);
 
float theta = 0.0;
float angle = 0.0;

import netscape.javascript.*;
 
void setup() {
 size(WIDTH, HEIGHT);
 smooth();
}
 
void draw() {
 background(255);
 
 // move origin to centre
 translate(HWIDTH, 0);
   
 // theta will oscillate between -1 and 1
 // we want the angle to go from about -45 from vertical to +45 from vertical
 // except we're using radians so -(PI/4) to +(PI/4)
 // ALSO 0 is to the right so add PI/2 to rotate it to the bottom
 // made this .2 * PI
 angle = HALF_PI + (sin(theta) * PI * .1);
   
 // With each cycle, increment theta
 theta += 0.03;
   
 drawCircle(LENGTH, LENGTH - 1);
}

void mousePressed() {
//    URL url = getDocumentBase();
//    System.err.println(url);
//    try {
     link("http://projectmio.com/index.html#frontBottom","_self");    
//      URL anchor = new URL(url, "#frontBottom");
//      System.err.println(anchor);
//      getAppletContext().showDocument(anchor);
//    } catch (MalformedURLException e) {}
}

 
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
 
// Example 13-8: Recursion (modified)
 
void drawCircle(float len, float radius) {
 noFill();
   
 float x = (len) * cos(angle);
 float y = (len) * sin(angle);
 ellipse(x, y, radius, radius);
 if(radius > 2) {
   // drawCircle() calls itself twice, creating a branching effect.
   drawCircle(len + radius / 7, radius / 2);
   drawCircle(len - radius / 1, radius / 2);  
 }
}



I tried two ways, but they both open a new page within the same page, hense you can click back in the browser history and the #frontBottom anchor shows at the end of the URL, which means the JS did not catch it.

void mousePressed() {
     URL url = getDocumentBase();
   System.err.println(url);
   try {
     URL anchor = new URL(url, "#frontBottom");
     System.err.println(anchor);
     getAppletContext().showDocument(anchor);
   } catch (MalformedURLException e) {}
}


AND

     link("http://projectmio.com/index.html#frontBottom","_self");


I am thinking now that maybe I need to create a piece of JS just for the flowing action to the #frontBottom anchor, so that the code you most recently posted will call it and the action will flow to the anchor. Unless there is a way of getting the JS to see the mouseclick when the Java applet is pressed like when the PNG image is pressed within the HTML.

My domain is up now so here is the site: http://www.projectmio.com/

What do you think?

Thank you!
Re: using the <embed> tag over <object>
Reply #21 - Nov 24th, 2008, 2:09pm
 
OK, I finally looked at your JS library... Partly because I was curious how they captured the jump event.
Actually, they don't. They just attach an onclick event on all links leading to an anchor on same page. That's why it cannot work on the Java jump or any other soft jump.

Fortunately, we can call directly their functions. For simplicity sake, I did that from a simple JS function, and let Java call this wrapper:

Processing (Java) side: Code:
   JSObject win = (JSObject) JSObject.getWindow(this);
String[] arguments = { "Bottom" };
win.call("JumpToAnchor", arguments);
Ie. pratically the same code. Note the anchor name is without #

JavaScript side: Code:
<script type="text/javascript" language="JavaScript">//<![CDATA[
function JumpToAnchor(anchorName)
{
SoftScroll.init();
SoftScroll.go(anchorName);
}
//]]>
</script>
Of course, get rid of the DumbTest...
Re: using the <embed> tag over <object>
Reply #22 - Nov 25th, 2008, 6:00pm
 
Ah ha, it does work, great! But, always a but, any reason why the png (http://www.projectmio.com/buttonsettle1a.png), when clicked, does not scroll down with the JavScript as before? I find that when I click that button to go down it jumps down, but pressing the recursion Java applet to go back up scrolls (excellent!) and then when clicking the PNG to go back down it scrolls but not the first time?

The thing is the user clicking down will probably only happen once and up also, I doubt there's going to be a lot of up and down scrolling so its imperative that it work for those first times.

Strange how the PNG doesn't work first time isn't it? But I'm overwhealemd tht the Java applet does, well done, you did it!
Re: using the <embed> tag over <object>
Reply #23 - Dec 1st, 2008, 7:04pm
 
I now have found the answer, I thought that the Javascript took precedence over the HTML anchor call and so I tried turning the a HREF into a JavaScript call like this:

<a href="#Bottom" onclick="JumpToAnchor('Bottom'); return(false);"><img src="image.jpg" /></a>


It works. That's it now, case closed.

Thanks so much PhiLho for all your help.
Pages: 1 2