Difference between revisions of "Putting ACP in a Web Page"

 
Line 227: Line 227:
 
Hopefully these two examples are a clear enough demonstration of how to play a model on a web page on your site by either using an HTML frame or using some Javascript code.  
 
Hopefully these two examples are a clear enough demonstration of how to play a model on a web page on your site by either using an HTML frame or using some Javascript code.  
  
If you have questions, or if something isn’t working, please email us at acp@lumina.com and we will be happy to help you out.
+
If you have questions, or if something isn’t working, please email us at [mailto:acp@lumina.com acp@lumina.com] and we will be happy to help you out.

Latest revision as of 20:52, 22 June 2018

<<back

June 8, 2012
Fred Brunton


Overview

Suppose you want to allow users to play your model from a web page on your web site. With Analytica Cloud Player (ACP) you can do this.

Prerequisite: You must already have an ACP account.

There are a number of approaches, and so far the way we have found the easiest is to just create a page that uses frames on your web site, and then have your model shown in one of those frames.

If for some reason HTML frames are not a viable option, the second example on this page will show another approach of embedding some Javascript code directly into your web page that you want to use for playing models in ACP.

When a new user arrives at your web page with the model embedded, the model will appear and an ACP session credit will be consumed.

If you want to display the model without the banner section of the ACP web page, you can find out how to do it here.

Example 1 - Showing your model in a Frame

Note that this has not yet been implemented in ACP 3 so in order to embed an ACP model on a web page with frames, you would need to have the ACP account set to use ACP 2.

To keep it simple, let’s say you just want to display your header logo and navigation tabs at the top of the parent web page, and then have the ACP model shown below that. I’ll show you an example of how to do this, and hopefully that’s enough for you to get started on playing your own model within a web page on your web site.

In this example, there are two servers.

  1. Your Server, the server where your web site resides. This is the server you are able to upload and edit pages on.
  2. And there’s ACP’s server, AnalyticaCloud.com, which hosts ACP and will contain the web page that plays your model. Since this page is an HTML frame, it will appear the model is being played on your web site.

If you are not familiar with HTML frames, you should probably take a minute to google “HTML Frames Tutorial” and find a one page tutorial on how HTML frames work.

  • Basically, you create a “parent” web page which contains a number of other web pages within it.
  • The subpages which are displayed within the parent frame can be specified to use a certain amount of vertical or horizontal space.
  • The most common way of setting up the frames for displaying a model is by tiling the frames vertically.

Step 1 - Creating the Parent Web Page

The first thing we need to do is to create the parent web page which will contain (in this case) two frames. For the purpose of this example, let’s say you want to display the header of your web site with the logo and navigation tabs at the top of the page. And in the second frame below that you want visitors to your web site to be able to play your model.

  • Create a parent web page 'parent.htm' in a text editor or whatever website software you are using. Here’s the html code for a basic web page:
<html>
<head><title>Your title</title></head>
<frameset rows="100,*" border="0">
<frame noresize="true" src="yourHeader.htm" ></frame>
<frame noresize="true" src=""></frame>
</frameset>
</html>

The web page above contains two frames (pages).

  1. The first yourHeader.htm is your web site’s header and contains UI for navigation of your web site. The parent page says to give this header page the top 100 pixels of the parent web to display the header’s content.
  2. The rest of the parent web page will display the second frame page. This second page is on the AnalyticaCloud.com web server. You cannot author it, but you can “pass in” information using “URL encoding”. The URL encoding will contain the information so ACP knows which model to play among other things.

step 2 - Creating the Link to Play Your Model

Currently, you can use ACP’s Email Invite functionality to create the link which will play your model.

  1. Sign into your ACP account
  2. Ensure the model you want to play in your web page is in the Model folder of ACP - it will need to remain there as long as it is embedded in your web page (deleting it would cause an error message for visitors to your web page that the model can't be found).
  3. Use the radio button to select your model.
    ACP inn a web page 01 - model folder.png
  4. Then click the [Email Invite] button. This starts the email invite creation process and exposes some more UI including the text of the email invite.
  5. Copy the link from this email invite.
    ACP inn a web page 02 - email invite.png
  6. After you copy the link, you press the [Cancel] button since we aren’t sending the invite to anyone.
  7. Go back to parent.htm, and paste the text from this link into the “scr” attribute for the second frame as shown in red below:
    <html>
    <head><title>Your title</title></head>
    <frameset rows="100,*" border="0">
    <frame noresize="true" src="yourHeader.htm" ></frame>
    <frame noresize="true" src="https://www.AnalyticaCloud.com/acp/Client/AcpClient1.aspx?inviteId=21&inviteCode=720970&subName=fredbrunt%40gmail%2Ecom"></frame>
    </frameset>
    </html>
  8. Now save parent.htm to a folder on your hard drive.

Step 3 - Creating yourHeader.htm

In this example, the top frame is your web site’s logo, title and navigation tabs. This content is going to be based on your web site.
For the sake of this example, I will mock up a header which is just an image.

  1. Create the file yourHeader.htm which you will insert into the "src" attribute of the first frame. Here is the code:
    <html>
    <body>
    <img src="yourHeader.png"/>
    </body>
    </html>
  2. Save yourHeader.htm to the same folder as parent.htm. This file just loads the yourHeader.png image, shown below:
    ACP in a web page 03 - yourHeader.png
  3. So now copy this logo and save it as yourHeader.png into the same folder as the other two files.

Step 4 - Finishing the Example

So now we’ve completed making the files. In this example the files you are going to place on your server are parent.htm, yourHeader.htm, and yourHeader.png. Just upload them into a folder, and then load parent.htm in a browser. In this case, the model will play on the web page looking like this:

ACP in a web page 04 - finished frames.png

I’ve uploaded these files onto another one of Lumina’s servers in case you want to test it out.

See http://analyticaonline.com/acpInawebpage/parent.htm to see ACP playing a model within another web page.

Or, if you just want to test this out on your computer, launch a browser, from the File menu select Open, and open parent.htm.

If this example’s approach works for you, then you can skip the next example, which shows how to play your model within a web page without using HTML frames, but requires a wee bit more work.

Example 2 – Look Mom, No Frames – JavaScript

It’s not uncommon to find out that frames are not a viable option; for example because you are using an existing framework that doesn’t support frames, or would require a lot work. Here’s a second approach which may work for you.

Step 1 - Start with Your HTML Page

This approach should work with any HTML page you want to use. You just tweak the existing page by adding a javascript include to the <head> and then paste a block of javascript code into the <body>.

Step 2 - <Head>s up

Let’s start with the <Head> section of your HTML page. Usually ACP is loaded using a popular javascript library called swfObject.js. I’m not going to go into the technical reasons for doing this, but just google “swfObject.js” and you’ll find plenty.

To get started we need a web page, so I’m going to create a blank web page that just contains a title, 'Look at My Model'. Here’s the HTML page we are going to start with:

<html>
<head>
<title>Look at My Model</title>
</head>
<body>
<h1>Look at My Model</h1>
</body>
</html>

This is what this web page initially displays:

ACP in a web page 05 - Look at my model.png

Step 3 - Insert the Source code for the ACP model

So now we are going to add ACP to this page and have it play a model below the title. Similar to Example 1, we will start by creating a link that will open your model using ACP’s Email Invite feature.

  1. Sign into your ACP account
  2. Ensure the model you want to play in your web page is in the Model folder of ACP - it will need to remain there as long as it is embedded in your web page (deleting it would cause an error message for visitors to your web page that the model can't be found).
  3. Use the radio button to select your model.
    ACP inn a web page 01 - model folder.png
  4. Then click the [Email Invite] button. This starts the email invite creation process and exposes some more UI including the text of the email invite.
  5. Copy the link from this email invite.
    ACP inn a web page 02 - email invite.png
  6. After you copy the link, you press the [Cancel] button since we aren’t sending the invite to anyone.
  7. Go to FireFox, paste this link into the address bar and hit enter. This should load your model into the browser.
  8. Click on the address bar (to ensure focus is on the browser window and not the embedded flash player).
    ACP in a web page 06 - Address bar.png
  9. What we are after is the source code, so Press ‘Ctrl+U’ (View source).
  10. In the source code window that appears click on the link shown below to show the source for the html page that contains the code we want to get:
    ACP in a web page 07 - Source code.png
  11. Now the source code for the frame we are interested in is shown. You may need to scroll down a little, then copy the block of text shown below:
    ACP in a web page 08 - Source code2.png
  12. Now I'll paste this source code - shown below in red - into the body of our 'Look at my Model' web page, so the web page will look like this:

<html>
<head>

<title>Look at My Model</title>

</head>
<body>
<h1>Look at My Model</h1>

<div id="flashcontent" align="left">
<h2>&nbsp;Loading Analytica Cloud Player...</h2>
&nbsp;&nbsp;If the ACP fails to start loading in a few seconds<br />
&nbsp;&nbsp;try refreshing the page. E.g. press F5 button.<br />
&nbsp;&nbsp;If that doesn't work, make sure you have Adobe Flash Player 8.0 or higher. <br />
&nbsp;&nbsp;If you are still having problems contact Lumina at acp@lumina.com.
</div>
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("acpClient.2.6.0.32c.swf", "awpClient", "1600", "1008", "8", "FFFFFF");
so.addVariable("goto","invite")
so.addVariable("modId", "Megajoule_Graphing")
so.addVariable("flashWidth",1600)
so.addVariable("flashHeight",1008)
so.addVariable("bgColor","CCCCCC")
so.addVariable("inviteId", "22")
so.addVariable("inviteCode", "784319")
so.addVariable("emailAddressFromCookie", "fredbrunt@gmail.com")
so.addVariable("subscriptionName", "fredbrunt@gmail.com")
so.addVariable("noFrames", "")
so.addVariable("awpPlanType", "") // e.g. group or individual
so.addVariable("authString", "")
so.addVariable("modelToOpenFromUrl", "")
so.addVariable("folderIdFromUrl", "")
so.addVariable("projectFromUrl", "")
so.addVariable("subType", "Model Reviewer")
so.addVariable("acctType", "Manager")
so.addVariable("urlId", "4014155")
so.addVariable("rootUrl", "https://www.analyticacloud.com/acp/")
so.addVariable("warnAboutUnsavedInputs" , "No")
so.write("flashcontent");
// ]]>
</script>

</body>
</html>

Step 4 - A Couple More Tweaks

Now we are getting close to being finished. Just a couple more tweaks.

  1. Add a link to the swfObject.js file in <head> of your html page like so (type/paste the code in red below):
    <head>
    <title>Look at My Model</title>
    <script type="text/javascript"
    src="https://www.analyticacloud.com/acp/client/swfobject.js" ></script>

    </head>

  2. Next, we need to have your web page to load the ACP shockwave file from the ACP server. So we change the following line in the source from:
var so = new SWFObject("acpClient.2.6.0.32c.swf", "awpClient", "1600", "1008", "8", "FFFFFF");

To:

var so = new SWFObject("https://www.analyticacloud.com/acp/client/acpClient.2.6.0.32c.swf", "awpClient", "1600", "1008", "8", "FFFFFF");

You will need to tweak this line to get the current version of ACP when a new revision of ACP is released.

Step 5 - Optional - Set the size for the ACP rectangle on your web page

  1. In the previous line of code you can substitute your desired width and height for the ACP rectangle on your web site e.g.:
    :"1000", "600", to replace the "1600", "1008",
  2. Modify the flashWidth and flashHeight variables to match, e.g.:
    so.addVariable("flashWidth","1000", )
    so.addVariable("flashHeight","600", )
  3. Delete the line defining the emailAddressFromCookie variable.

Step 6 - Time to test it

So now you can try saving the html file and loading this page onto your webserver and then loading the page in a browser window. Hopefully, it will display your model below the page’s title something like this:

ACP in a web page 09 - finished.png

Summary

Hopefully these two examples are a clear enough demonstration of how to play a model on a web page on your site by either using an HTML frame or using some Javascript code.

If you have questions, or if something isn’t working, please email us at acp@lumina.com and we will be happy to help you out.

Comments


You are not allowed to post comments.