PDA

Click to See Complete Forum and Search --> : Embedding swf after page load?


tZ
03-18-2008, 01:54 AM
Currently I'm working on site that navigates to new pages without reloading the pages using a ajax and php framework. However, this site uses flash on some of the pages and I am finding it tough to embed a swf on a page without reloading the page. is this possible or can items only be embedded when the page first loads– such as a swf file? – thanks

The reason I ask is because I am working on a multiple pages(2) that have a flash player on them. This flash player is a video player. On each of these pages there are x amount of links that load new movies into the player using the ExternalInterface class. My current solution is a but messy but, when a user first enters the site the movie play is added and hidden(display: none) unless the page is a movie page. Any other ideas? – being I can't reload the page?

tZ
03-18-2008, 01:35 PM
No one has any ideas here?

Currently, I'm using the swfobject to embed the movie on the page like so:

html and javascript

<div id="flash-module">
<div id="video-player">
<script type="text/javascript">
// <![CDATA[
function SWFSetUp() {
var so = new SWFObject("videoDemo_final.swf", "videoplayerajax", "550", "420", "8", "#ffffff");
//so.addVariable("vid", "");
so.write("flashcontent");
return so;
}
// ]]>
</script>
</div> <!-- end of div#video-player -->
</div> <!-- flash-module -->


This code is on every page of the website even though the player only shows up on two pages. So how I currently have resolved this by extracting the url of all my links and looking for the correct id:

javascript

function View(a,c) {
var controller = c;
var model = a;

this.update = update;
function update() {
//alert(a.getElement());
checkVid();
document.getElementById(a.getElement()).innerHTML = a.getHttpRequest().responseText;
a.resetRequest();
//alert(a.getElement());
c.updateListeners(a.getElement());
}

function checkVid() {
var qc = c.getQuerySet();
for(var x in qc) {
if(qc[x].match(/id=1/) || qc[x].match(/id=2/)) {
if(c.getVideoPlayer()) { c.changeMovie(a.getHttpRequest().responseText); } else { c.createPlayer(); }
break;
}
if(c.getVideoPlayer()) { c.removePlayer(); }
}
}

var noChange=true;
var firstChange=false;
}


Function checkVid manages the movie player. Based on whether an id == 2 or id == 3 exist the movie is changed, player is created or removed.

The below code shows some of the methods of the controller that correlate to handling the movie controls directly(removing, changing the movie and creating the player)

javascript

this.createPlayer = createPlayer;
function createPlayer() {
//alert('create player!');
document.getElementById('flash-module').style.display="block";
SWFSetUp();
videoplayer = true;
}

this.changeMovie = changeMovie;
function changeMovie(x) {
for(i in querySet) {
if(querySet[i].match(/thumb/)) {
document.getElementById('videoplayerajax').movieSw ap(x);
}
}
}

this.removePlayer = removePlayer;
function removePlayer() {
//so=null;
document.getElementById('flash-module').style.display="none";
videoplayer=false;
}


So when a user first enters the site css hides the #flash-module containing the movie player. However, the first instance they navigate to a video player page the function is called to create the player and display the div containing it. Then the second they click off this page to a none player page the #flash-module div is hidden – hiding the flash move but not removing it.

What I would like to do is be able to remove the player completely and then be able to add it without reloading the page. This is because under best of circumstances the entire navigation is handled through ajax. Basically, the site never needs to reload with the way I have set it up. Therefore, I need to find a way to remove and add the player dynamically, without hurting the performance of the site. Since, I'm assuming by just hiding the player and not fully removing it on pages its uneeded(contact, home, ect) I'm hurting the performance of the site. So if anyone has any ideas that would great.

Eventually, I'm going to need to separate out the video player managing into a separate class. However, for now I would just like to be able to add and remove the player without the need to reload the page – if possible…

thanks

DesignVHL
03-18-2008, 06:31 PM
talking to YOURSELF again eh? lol :p i wish I could help you! I just started using swfobject!

Maybe the ajax forum would be more helpful in this case?

tZ
03-18-2008, 08:12 PM
I'm stumped on this one.

Part of the problem is that I know very little about the the way javascript handles flash movies and the methods or properties made available to manipulate them using javascript. However, I'm coming short of finding things about that also on the web.

JPnyc
03-18-2008, 08:14 PM
Here's (http://board.flashkit.com/board/index.php) where you want to ask a question like that. I've never done this, but offhand I would say you have to write the object tags just like any other element added to an existing page load.

DesignVHL
03-18-2008, 08:18 PM
yep....flashkit is great. Funny, that was probably one of the VERY first web forums I participated on YEARS ago!

Oooh also, I wonder if you could fix this directly with IN your flash movie using some actionscript. I'd look into that too. That way you don't even need to include extra scripting for each page you use a flash movie. Perhaps an if/else ? idk..

tZ
04-04-2008, 01:56 PM
future reference:

Calling the write method of swfObject writes the object to the page. Thus, the call can be placed anywhere within the js file such as as a collaborator of the handler of event listener. This allows the flash movie to written to the page asynchronously.

DesignVHL
04-04-2008, 06:43 PM
^^ahhh yes that makes sense^^

fatherlyy
04-09-2008, 06:23 PM
thanks for codes :)