This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-04-28 06:44:01

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

embedding not working

I tried embedding a scratch program as an applet using

<applet id="ProjectApplet" style="display:block" code="ScratchApplet"                                                                         
        codebase="http://scratch.mit.edu/static/misc/" archive="ScratchApplet.jar"                                                           
        height="387" width="482">                                                                                                             
   <param name="project" value="http://www.soe.ucsc.edu/~karplus/scratch_programs/Sliding_slug.sb">                                           
   <h3>Your browser needs java to view projects</h3>                                                                                         
</applet>   

but I just got the blank "loading" progress bar.
I also tried using just "Sliding_slug.sb" as the value of project, where that would have been a correct relative URL, but that didn't work either.

I'm using
Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3

and the similar applet calls on the scratch.mit.edu web site seem to be working.

What am I doing wrong?

Offline

 

#2 2007-04-29 16:48:37

pkimelma
Scratcher
Registered: 2007-04-10
Posts: 33

Re: embedding not working

I also  am seeing embedding not working. I enabled the Java console and it is a null pointer error.  The problem seems to be that it does not like the URL of the .sb file being somewhere other than their own server (../ type relative reference).
I tried moving the .jar file to my own server and it fails with access violation errors (meaning a thrown exception due to trying to access something via a TCP/IP request invalidly). I cannot tell what it is, since the Java console will not show me the path it was trying. My guess is that it is trying to run Squeak on their server and is being refused from an outside server (mine). So, without knowing what setup I need, I cannot run it on my machine.
I was not able to diagnose locally, since the .jar file takes a fault on load. I may try loading into Eclipse if we do not hear back as what the issue is.
By the way, if you are wondering why I want to run it this way - the school will not allow access to sites that are "open" (with forums and all). So, I want to allow the students to see their work via browser using a school internet server. I have a download PHP page for them, so it is only about getting the embed to work using the JAR file on your server or  on mine.

Last edited by pkimelma (2007-04-29 16:53:59)

Offline

 

#3 2007-04-30 11:38:13

andresmh
Scratch Team at MIT
Registered: 2007-03-05
Posts: 1000+

Re: embedding not working

Please try the embedding instructions I posted here: http://scratch.mit.edu/pages/embed
and let me know if they work.

pkimelma, thanks for explaining why your school doesn't allow access to our site. I hope they don't block all connections to scratch.mit.edu otherwise the embedding won't work for you.

You can always download the JAR file and run it locally.

If you have experience setting up PHP, MySQL and Apache, I can share the ode that runs this website and you can setup an internal website. However, it will be sad not to have the kids of your school participate in this on-line community.


Andres Monroy-Hernandez | Scratch Team at the MIT Media Lab
on identi.ca and  twitter

Offline

 

#4 2007-04-30 12:25:27

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: embedding not working

I started with the instructions at
http://scratch.mit.edu/pages/embed

They didn't work, so I tried other things.
I suspect that the problem is that "codebase" forces everything to be looking on the MIT website.  Have you tried the embedding instructions when the .sb file is coming from a different host than the .jar file?

Offline

 

#5 2007-05-01 01:14:44

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: embedding not working

I got embedding to work, but only by downloading the ScratchApplet.jar file.

Then

<applet id="ProjectApplet" style="display:block" code="ScratchApplet"                                                                         
        archive="ScratchApplet.jar"                                                                                                           
        height="387" width="482">                                                                                                             
   <param name="project" value="print_number.sb">                                                                                             
   <h3>Your browser needs java to view projects</h3>                                                                                         
</applet>                                                 

worked as expected (modulo any bugs in the jar implementation).

I downloaded from http://scratch.mit.edu/static/misc/ScratchApplet.jar
which seems to be the version used on the project web pages.

The main downside of this approach is that I'll have to download a new jar file every time there is a bugfix.

Offline

 

#6 2007-05-04 11:32:24

pkimelma
Scratcher
Registered: 2007-04-10
Posts: 33

Re: embedding not working

Hi. Kevin had the solution. I had the .jar on my server, but the problem was the "codebase" line from the appnote. Once I removed it (I had it pointing to my own location), it all works fine now.
Andres, the firewalling that they do is pretty harsh. The URL controls inspect incoming HTML and inspect all HTTP URIs, so they cannot get to any open systems, and yours is open (anyone can post there).
My local mechanism works fine now that the .jar is on a local server (and I got rid of the codebase attribute to the tag). At this time, I see no reason to setup a full version of your website. I have enough for them to share their files using my PHP page, although they cannot use your one-button push, that is not a real concern at this point. They can download and upload files and now they can see them in action on a web page, which is great.
The kids can access your site from home (as long as their parents are OK with it), and I have explained that to them via a letter. I know some have looked at projects on the site, and I have pointed them to some interesting ones.
Thanks for all the help.

Offline

 

#7 2007-05-04 12:44:29

andresmh
Scratch Team at MIT
Registered: 2007-03-05
Posts: 1000+

Re: embedding not working

kevin_karplus, thanks for your debugging.

when it was not working, you said:

I suspect that the problem is that "codebase" forces everything to be looking on the MIT website. Have you tried the embedding instructions when the .sb file is coming from a different host than the .jar file?

Does that mean you had the .sb file in a different host than the .jar? If so, why?


Andres Monroy-Hernandez | Scratch Team at the MIT Media Lab
on identi.ca and  twitter

Offline

 

#8 2007-05-04 13:20:59

pkimelma
Scratcher
Registered: 2007-04-10
Posts: 33

Re: embedding not working

Does that mean you had the .sb file in a different host than the .jar? If so, why?

No. I was using it because I was not sure if your .jar file required this to run its classes properly. That is, I had your .jar in a subdirectory via code and so used codebase to refer to the base directory (where the .php file is). Since applet went away in XHTML, I am not used to it (I use object normally), I just followed the "rules". Note that I had codebase set to my directory. In any case, I moved the .jar back down to the same place as the .php file and removed codebase and made code just the jar name, and all is fine. So, there is some oddity in how you handle relative paths I think. As I said, I was getting an access thrown exception from Java doing a check against my URI.

Offline

 

#9 2007-05-04 14:23:23

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: embedding not working

Well, I originally had the .sb files on my website and was trying to get the jar file from the MIT website, since I did not want to have to keep re-downloading the jar file for all the bug fixes I hope are going to happen.  I never did get that to work, and just switched to having my own copy of the jar file.  I'm not interested enough in applets to read up on the *right* way to reference them from an HTML page, but the example you give should at least work. If people have to download the jar file to their own sites, you should say so in the instructions.  If there is a way that they can use the MIT jar file  with sb files from their own site, you should give an example of doing that which works.

Offline

 

#10 2007-05-04 14:29:47

pkimelma
Scratcher
Registered: 2007-04-10
Posts: 33

Re: embedding not working

You can only use the .jar file on the MIT server if the .sb is also on the MIT server. This works if you are referencing projects on their website. The reason is that the Java code is looking only for local files (local to the URL it was started from). It has a bug if not - instead of reporting an error, it gets a NULL check because the path is left NULL.
So, copying to your server is the only option. I added a bit of code to my PHP file which checks the mit copy of the .jar file to see if newer. I do this only once per day at most (I have a drop file locally). This makes it easier and safe.

Offline

 

#11 2007-05-04 21:00:50

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: embedding not working

Could you share the PHP code for copying the jar file?  I'm too lazy to learn PHP myself (well, too busy really), and I *know* I'm going to be dilatory in picking up updates from MIT.

Offline

 

#12 2007-05-04 22:33:34

pkimelma
Scratcher
Registered: 2007-04-10
Posts: 33

Re: embedding not working

The problem is that this forum will not let me insert the content nor attach as far as I can see.
Well, if the forum will fight me, I will work around it. You can get it from my site:
  http://www.nikoosha.com/class/testupd.php.txt
This will show the php source but without the angle ? php part (I cannot even write it here).
Just insert into your file (php) or a function. At most it will check the remote file once every 24 hours (depending on when someone uses your page). When it does, it gets the mod time of their file and compares to your local copy. We use a temp file for last check date.
Oh, one note. I did not bother with error checking (but it will not fail to make a page); this is because there is nothing to do if there is an error, it is a silent loader. This means that you should delete the local .jar file to make sure it works. Unless you have a very old PHP or missing URL wrappers, it should work fine.

Regards, Paul

Last edited by pkimelma (2007-05-04 23:38:44)

Offline

 

#13 2007-05-05 12:32:49

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: embedding not working

Thanks, Paul!

I had to rename my .html files to be .php files, and I used a php-style include for the updating script.  I also added an if(!file_exists("ScratchApplet.jar") test at the beginning to force a download if the jar file was missing.

It seems to work ok, though I'll know better if the MIT folk update their jar file.

Offline

 

#14 2007-05-05 12:38:00

pkimelma
Scratcher
Registered: 2007-04-10
Posts: 33

Re: embedding not working

Hi Kevin. You should not need the file_exists test. The mod-time will come back as False if the file is missing, which reads as 0 for comparison tests. So, it should have concluded that their jar file was newer than your missing one. Anyway, glad it is useful for you.

Offline

 

#15 2007-05-22 06:30:30

andresmh
Scratch Team at MIT
Registered: 2007-03-05
Posts: 1000+

Re: embedding not working

This is an example of someone who was able to get embedding working on his own home page: http://xyxzer.bravehost.com/scratchpad/Use%20Online.html


Andres Monroy-Hernandez | Scratch Team at the MIT Media Lab
on identi.ca and  twitter

Offline

 

#16 2007-05-22 10:31:17

pkimelma
Scratcher
Registered: 2007-04-10
Posts: 33

Re: embedding not working

This is an example of someone who was able to get embedding working on his own home page:

Andres, this is just an example where the project is on ***your*** site. The point was embedding where the .sb file is on the local site. The trick is that one has to have the .jar file and the .sb file on the same server, because you are opening as a local file.

I added some php code to make sure that the latest JAR file is on my server.

Regards, Paul

Offline

 

#17 2007-05-22 13:06:28

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: embedding not working

I modified Paul's code slightly and am using it also.  I checked, and it did pick up the newest Scratch.jar file automatically, without needing manual intervention.  (That was hard to test when the jar file was not changing.)

Offline

 

#18 2007-05-23 22:52:49

andresmh
Scratch Team at MIT
Registered: 2007-03-05
Posts: 1000+

Re: embedding not working

kevin, it would be really cool if you could write step by step instructions on how you got the embedding to work while hosting the .sb and .jar locally. I would prefer if people host their Scratch project on the on-line community but I understand some people might have reasons to host it locally. You seem to be the one that came up with the most complete answer for this. If you post the instructions I would like to add them to our FAQ or to http://scratch.mit.edu/pages/embed

Thanks a lot for being such an active Scratcher! :-)


Andres Monroy-Hernandez | Scratch Team at the MIT Media Lab
on identi.ca and  twitter

Offline

 

#19 2007-05-23 23:11:20

pkimelma
Scratcher
Registered: 2007-04-10
Posts: 33

Re: embedding not working

Andres, there are two parts. If you put the .sb file and .jar file on the same server, you just use:
<applet id="ScratchShow" style="display:block" code="ScratchApplet"
            archive="ScratchApplet.jar"  "height="387" width="482">
   <param name="project" value="$scratch">
</applet>

This is in your .html or .php file. Note that $scratch is replaced with the name of the .sb file. This all works fine.

Further, I have put a file on my server with the PHP code to keep the .jar file up to date on the local server. You just call it and it updates when needed. That file is:

  http://www.nikoosha.com/class/testupd.php.txt

Anyone can place in their own .php file. They can also just rename a .html file to .php and use with this addition (as long as their server supports PHP).

Offline

 

#20 2007-05-24 14:43:39

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: embedding not working

What pkimelma said.

People can look at
http://www.soe.ucsc.edu/~karplus/scratch_programs/
particularly
http://www.soe.ucsc.edu/~karplus/scratch_programs/check-jardate.txt
(which has to be called check-jardate.php to work)
and
http://www.soe.ucsc.edu/~karplus/scratch_programs/Simon.txt
(which also has to be called Simon.php to work)

Offline

 

#21 2007-07-30 03:45:53

bomquangia
Scratcher
Registered: 2007-07-30
Posts: 3

Re: embedding not working

How can i post it to my blog?

Offline

 

#22 2007-07-30 03:47:13

bomquangia
Scratcher
Registered: 2007-07-30
Posts: 3

Re: embedding not working

My blog ís in Yahoo!360

Offline

 

#23 2007-07-31 15:18:22

andresmh
Scratch Team at MIT
Registered: 2007-03-05
Posts: 1000+

Re: embedding not working

bomquangia: can you put pictures with links on them on Yahoo!360? If so, just follow the instructions here: http://scratch.mit.edu/pages/embed


Andres Monroy-Hernandez | Scratch Team at the MIT Media Lab
on identi.ca and  twitter

Offline

 

#24 2008-05-27 12:51:32

vikaros
Scratcher
Registered: 2007-06-04
Posts: 100

Re: embedding not working

I've noticed this confusion.  There are two DIFFERENT ways of embedding Scratch projects being discussed here. 

Java Applets are locked down by design to prevent them from accessing files on any computer other than the web server where they originated.  So if you want to copy your .sb file to a CD or into the FTP files of your own web page you have to include the ScratchApplet.jar with it.  You cannot have your file on your webhost and try to use the ScratchApplet.jar from MIT at the same time!  (see http://scratch.mit.edu/forums/viewtopic.php?id=191)

The other approach that is build into the embedding feature on our site allows you to embed by linking back to the Scratch site.  In this case both your project file and the Applet remain on MIT's servers. 

Both work, but give you different levels of control over where your project is hosted and if its shared with Scratch's community.

Hope that helps!

Offline

 

Board footer