Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Embed problem!


Go to End
Reply


22 Posts   3859 Views

Avatar
LostBalloon

Community Member, 16 Posts

12 April 2011 at 1:52pm

I am trying to add the Unity3D (www.unity3d.com) web player into my site with SS 2.4.5. What seems to happen is that SS is dynamically removing my code that contains the web player. It leaves a closing div tag.

it is really simple for a simple static page to embed the web player. You need the following code and it works perfectly.
HTML:

<script type="text/javascript" src="http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js"></script>
      <script type="text/javascript">
      <!--
//gets the unityPlayer div and replaces the content with an embed tag which is the web player made by Unity (it works outside of SS.)
      function GetUnity() {
         if (typeof unityObject != "undefined") {
            return unityObject.getObjectById("unityPlayer");
         }
         return null;
      }
//sets the parameters of the web player
      if (typeof unityObject != "undefined") {
         unityObject.embedUnity("unityPlayer", "MazePuzzle.unity3d", 720, 450);
         
      }
      -->
      </script>

<div id="unityPlayer">
            <div class="missing">
               <a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
                  <img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
               </a>
            </div>
         </div>

Avatar
martimiz

Forum Moderator, 1132 Posts

13 April 2011 at 3:03am

From where are you trying to add this code? From within the TinyMCE editor, or from somewhere in your SilverStripe templates/code

Avatar
LostBalloon

Community Member, 16 Posts

13 April 2011 at 1:55pm

From directly within the *.ss page

Thing is that the code you see within the <div id="unityPlayer"> is automatically replaced by an <embed ...> tag which contains the game
It swaps the link to download the plugin to the embedding of the plugin if it is installed, otherwise you see the download link.

Avatar
martimiz

Forum Moderator, 1132 Posts

13 April 2011 at 9:34pm

Edited: 13/04/2011 9:35pm

Placing a <script> tag directly into your template doen't always work as you'd expect it to. The 'SilverStripe way' would be using the Requirements class to add custom javascript. I ususally do this from within my init() function. Have a look at this link

http://doc.silverstripe.org/sapphire/en/reference/requirements#custom-inline-scripts

Avatar
LostBalloon

Community Member, 16 Posts

14 April 2011 at 6:24am

I did that, the code works, and is actually already integrated with the SS Requirements tag.
I did not place a <script> tag for it.

The issue is that when the <embed> tag is to be added dynamically to the page code, for some reason silverstripe prevents it from happening.
I know this is the issue, but i dont know what to change in SS to stop it from happening.

I know the javascript code executes since it does remove the content already inside the <div> for the case when the plugin is not found.

Avatar
martimiz

Forum Moderator, 1132 Posts

14 April 2011 at 7:31pm

OK, took some time for me to really get this :-( What you're saying is something is interfering with the execution of your JavaScript. Looks like it starts replacing the content of your div as it should, and then fails.

Did you try Firebug to track for JavaScript errors? does your page source contain more JavaScript that might be conflicting?

Avatar
LostBalloon

Community Member, 16 Posts

16 April 2011 at 3:39am

Hey,

thanks for the suggestion.
It seems that i have problems with the css, but the weird thing is i did not even touch that part of the code...

<head>
      <% base_tag %>
      $MetaTags
      <link rel="stylesheet" type="text/css" href="tutorial/css/layout.css" />
      <link rel="stylesheet" type="text/css" href="tutorial/css/typography.css" />
      <link rel="stylesheet" type="text/css" href="tutorial/css/form.css" />
   </head>

thats what's in the page.ss file by default. (I get 404: not found messages for all 3 css files)
i tried changing it to:

<head>
      <% base_tag %>
      $MetaTags
      <link rel="stylesheet" type="text/css" href="theme/tutorial/css/layout.css" />
      <link rel="stylesheet" type="text/css" href="theme/tutorial/css/typography.css" />
      <link rel="stylesheet" type="text/css" href="theme/tutorial/css/form.css" />
   </head>

to fix the location of the files, but i still get "404-not found" for the css files.
(My plugin for the game depends on some css tags as well, so this might just be the issue)

the thing that i dont understand is that the CSS still seems to properly apply to the webpage, well the theme seems to apply...

Avatar
LostBalloon

Community Member, 16 Posts

16 April 2011 at 3:46am

nevermind my last post. Fixed that stupid issue, figured the css code was redundant as they had put it in the page.php as well...

And i use google chrome, and in the dev tools, i dont get any error messages coming from the javascript nor from the page structure.

Go to Top