Swap a swf on the html page using javascript?

113 views
Skip to first unread message

jim holmes

unread,
Aug 12, 2009, 7:20:38 AM8/12/09
to SWFObject
This is all I want to do - it seems ( like a lot of things ) a
relatively simple task, but 2 hours later I'm no further forward. One
site recommended swfobject to do this, but I can find no reference to
doing this anyway on this site?
Am I looking to do something that can't be done?

cheers
Jim

Vincent Polite

unread,
Aug 12, 2009, 7:32:05 AM8/12/09
to swfo...@googlegroups.com
SWFObject is a javascript object that allows people to embed .swf files in their web pages.  Among other things, there is a method called .embedSWF that takes arguments and puts a specific .swf file that you specify, swapping it for a designated div.  There's nothing stopping you from calling that function more than once.  So depending on what you are using to trigger the action, it would be code on the order of:

if (action1) {
     swfObject.embedSWF(...)
} else {
     swfObject.embedSWF(...)
}

I would just be sure you are including the right version of the swfObject.js script (version 2.x) and that should do the trick.  However, the embed method depending on how you do it may reload the flash movie each time (not cached), which might be laggy and undesirable.

If I were doing something like this, I would define 2 divs in your HTML page, one with an id="version1" and another with id="version2"
If I needed any of these divs on page, I would define my style sheet to show it where it needed to be shown.  If one or both of the divs need to be hidden, then I would define the style on that div so that the x and y coordinates are off screen (like using huge negative numbers).

Then you write some script that would "move" the div onto the visible part of the page where you want it.  You can simulate a Flash swap that way.

A lot depends on what you're trying to do.  Using the method I described works perfectly fine for 2 flash movies, but it might not work so well if you had say 30...

Hope this points you in the right direction.  If you do some google searching, there was a post a day or so ago that discussed swapping a Flash movie using the technique I described.

Vincent

Aran Rhee

unread,
Aug 12, 2009, 7:38:53 AM8/12/09
to swfo...@googlegroups.com
If you are wanting to swap flash movies within the same dic, yuou can check out Philip's tutorial on the subject:
 
(section "Using an 'onclick' event to replace a loaded SWF with another SWF")
 
 
Cheers,
Aran

jim holmes

unread,
Aug 12, 2009, 8:16:48 AM8/12/09
to SWFObject
Thanks guys - much appreciated - will take a look at Phillip's tute as
that sounds like it could be what I need -

cheers,
Jim
> > On Wed, Aug 12, 2009 at 4:20 AM, jim holmes <madhous...@googlemail.com>wrote:
>
> >> This is all I want to do - it seems ( like a lot of things ) a
> >> relatively simple task, but 2 hours later I'm no further forward. One
> >> site recommended swfobject to do this, but I can find no reference to
> >> doing this anyway on this site?
> >> Am I looking to do something that can't be done?
>
> >> cheers
> >> Jim- Hide quoted text -
>
> - Show quoted text -

jim holmes

unread,
Aug 12, 2009, 8:23:28 AM8/12/09
to SWFObject
Hi - have gone through Phillips tutorial, but the section that I need
( Using an 'onclick' event to replace a loaded SWF with another SWF )
- isn't explained very well - there's a bunch of code but no guidance
on where it goes / how it is implemented.

cheers
Jim

On Aug 12, 12:38 pm, Aran Rhee <aran.r...@gmail.com> wrote:
> > On Wed, Aug 12, 2009 at 4:20 AM, jim holmes <madhous...@googlemail.com>wrote:
>
> >> This is all I want to do - it seems ( like a lot of things ) a
> >> relatively simple task, but 2 hours later I'm no further forward. One
> >> site recommended swfobject to do this, but I can find no reference to
> >> doing this anyway on this site?
> >> Am I looking to do something that can't be done?
>
> >> cheers

Vincent Polite

unread,
Aug 12, 2009, 12:48:04 PM8/12/09
to swfo...@googlegroups.com
Although keep in mind that that tutorial does what I warn about, which is destroying a flash movie and replacing it with another, invoking the load time for both every time you do a swap, I believe.  Whereas if you use a method where you prefetch the movies and use dynamic positioning to move the movie offscreen, then you will get much better user "snappiness" on the swap.

Your mileage will of course vary depending on whether or not you have only 2 movies you are swapping vs. 100 and how you are doing the swapping specifically.  It also lets you avoid the whole removeSWF/recreate div problem that SWFObject 2.x introduces --- which STILL confuses me as to why that convention was changed from the old, "just shove the object INSIDE the div identified as the container" method.... please bring it back?  :)

VP
Reply all
Reply to author
Forward
0 new messages