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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Embed problem!


Go to End


22 Posts   6932 Views

Avatar
LostBalloon

Community Member, 16 Posts

16 April 2011 at 8:59am

ok,
I've tried to put the <embed> code directly in the Page.ss and when i loaded the page in the browser, it did the same thing.
it removed it.

<div id="unityPlayer" style="width: 720px; height: 450px; visibility: visible; ">
          <embed type="application/vnd.unity" style="display: block; width: 100%; height: 100%; " width="720" height="450" firstframecallback="unityObject.firstFrameCallback();" src="http://localhost:8888/SilverStripe-v2.4.5/assets/Uploads/MazePuzzle.unity3d">
          </embed>
</div>

When i inspect the code that the browser shows using Chrome's dev tools, this whole portion is removed...

Avatar
martimiz

Forum Moderator, 1391 Posts

16 April 2011 at 9:13pm

Ok, so I don't have the game and I have no idea what it looks like, but I had no problems installing it in SilverStripe anyway :-)

On a clean install, with no other javascript files loaded, in your Page_Controller:

function init() {

	parent::init();

	Requirements::javascript('http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js');

	Requirements::customScript(<<<JS
		//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);
		}
JS
	);
}

(make sure there's no whitespace before the closing 'JS' !!!)

in your template somewhere:

        <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>

Do a ?flush=1

Now in my html (firebug) I see the div tag replaced:

<div style="width: 720px; height: 450px; visibility: visible;" id="unityPlayer"><embed src="MazePuzzle.unity3d" firstframecallback="unityObject.firstFrameCallback();" style="display: block; width: 100%; height: 100%;" type="application/vnd.unity" width="720" height="450"></div>

One more tip: make sure your html validates - maybe some forgotten closing </div> might cause the problem...

Avatar
LostBalloon

Community Member, 16 Posts

17 April 2011 at 3:43am

Hey, i've tried adding the init function you described in my page's controller, but now i can't even access the page. Its giving me the error that the "website might be down for maintenance or configured incorrectly", when i remove that part of the code, works right back.

I've attached both the PHP file as well as the SS file.

Attached Files
Avatar
LostBalloon

Community Member, 16 Posts

17 April 2011 at 4:06am

And if you notice, that error that SS generates you is due to the fact that the <embed> tag is not properly closed by the unity plugin.

Avatar
martimiz

Forum Moderator, 1391 Posts

17 April 2011 at 11:37pm

For now, I narrowed it down to your Page header - so it's not SilverStripe after all :-) :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >

Removing the first line will at least make it work:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >

One more thing: php started complaining about a unexpected t_sl error - due to the fact that there are extra whitespaces following <<<JS in your Page.php (removing them will get rid of the error - if you have it, that is...

Avatar
LostBalloon

Community Member, 16 Posts

18 April 2011 at 3:20am

thanks :) i was blind to that first line thing!
and thanks for the whitespace info, it would've taken me forever to figure it out :)

now i just need to figure how to get rid of the:
GET http://localhost:8888/SilverStripe-v2.4.5/assets/Uploads/MazePuzzle.unity3d 403 (Forbidden)

I found how to allow the file to be uploaded through the cms, but apparently its not enough to allow it
to be accessed by the website.

anyways, thanks for the great help! :)

Avatar
martimiz

Forum Moderator, 1391 Posts

18 April 2011 at 6:41am

Edited: 18/04/2011 6:42am

if it's not a rights issue, then did you add the file extension to the list in web.config file in the /assets/ directory? I read that SilverStripe restricts access to files that are not represented there(haven't tested)

Avatar
LostBalloon

Community Member, 16 Posts

18 April 2011 at 7:24am

Nop, tried it, didn't help.

I'm able to "upload" it but when i come to access it (from the embed tag) it finds the file, but i get a 403 error in my javascript console.
the error:
GET http://localhost:8888/SilverStripe-v2.4.5/assets/Uploads/MazePuzzle.unity3d 403 (Forbidden)

i've tried both a regular flush & a /dev/build just in case, but i still get the error