webdevRefinery Forum: Load flash via javascript - webdevRefinery Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rate Topic: -----

User is offline Mack 

  • http://mackgoodstein.com/
  • Group: Members
  • Posts: 2070
  • Joined: 08-March 10
  • Expertise:HTML,CSS,PHP,Javascript

Posted 11 June 2010 - 09:05 PM (#1)

Load flash via javascript


I want to make a function that embeds an swf. Is there a way to have javascript only embed it when the function is called?

I was thinking of using document.write('<embed src="copy.swf" pluginspage="http://www.macromedia.com/shockwave/download/" width="1" height="1" name="copy"><\/embed>');
0


User is offline Daniel15 

  • dan.cx
  • Group: Moderators
  • Posts: 3415
  • Joined: 17-April 10
  • LocationMelbourne, Australia
  • Expertise:HTML,CSS,PHP,Java,Javascript,Node.js,SQL

Posted 11 June 2010 - 09:35 PM (#2)

Don't use document.write, it's deprecated and XHTML doesn't support it at all (if you use it in a proper XHTML file, it will not work :P). You can create an element using the DOM methods, something like:
var flash = document.createElement('embed');
flash.src = 'copy.swf';
flash.width = '1';
flash.height = '1';
flash.name = 'copy';
// To add it inside a container:
document.getElementById('container').appendChild(flash);
// Or to add it to the body at the very bottom:
//document.body.appendChild(flash);


(offtopic, guessing by the name of the Flash file: note that if you're using the Flash file to copy stuff onto the clipboard, due to security restrictions in Flash Player 10 it can't be a hidden Flash file. It has to receive user input to copy stuff, for example a click or keypress. This was added to prevent "bad" hidden Flash files overwriting your clipboard with spyware URLs constantly)
Daniel15! :D
Posted Image

Repeat after me: jQuery is not JavaScript. It is not the answer to every JavaScript-related question. When you have to write some JavaScript, do not instantly react with "Oh, I'll do that with jQuery!"

Spoiler
0


User is offline DarkCoder 

  • Group: Members
  • Posts: 1463
  • Joined: 08-March 10
  • LocationEngland, United Kingdom
  • Expertise:HTML,CSS,PHP,Javascript,SQL

Posted 12 June 2010 - 01:00 AM (#3)

Couldn't you put it in a DIV and then show / hide the DIV?
0


User is offline Mack 

  • http://mackgoodstein.com/
  • Group: Members
  • Posts: 2070
  • Joined: 08-March 10
  • Expertise:HTML,CSS,PHP,Javascript

Posted 13 June 2010 - 03:05 PM (#4)

View PostDaniel15, on 11 June 2010 - 09:35 PM, said:

Don't use document.write, it's deprecated and XHTML doesn't support it at all (if you use it in a proper XHTML file, it will not work :P). You can create an element using the DOM methods, something like:
var flash = document.createElement('embed');
flash.src = 'copy.swf';
flash.width = '1';
flash.height = '1';
flash.name = 'copy';
// To add it inside a container:
document.getElementById('container').appendChild(flash);
// Or to add it to the body at the very bottom:
//document.body.appendChild(flash);


(offtopic, guessing by the name of the Flash file: note that if you're using the Flash file to copy stuff onto the clipboard, due to security restrictions in Flash Player 10 it can't be a hidden Flash file. It has to receive user input to copy stuff, for example a click or keypress. This was added to prevent "bad" hidden Flash files overwriting your clipboard with spyware URLs constantly)


Hmm, can you put the flash in an alert, which they click OK in?


View Postolie122333, on 12 June 2010 - 01:00 AM, said:

Couldn't you put it in a DIV and then show / hide the DIV?


The problem is that I'm making an extension for a browser, and that'd mean having the flash file loaded constantly
0


User is offline elaine 

  • Group: Members
  • Posts: 1
  • Joined: 30-May 12

Posted 30 May 2012 - 12:23 PM (#5)

View PostDaniel15, on 11 June 2010 - 09:35 PM, said:

Don't use document.write, it's deprecated and XHTML doesn't support it at all (if you use it in a proper XHTML file, it will not work :P). You can create an element using the DOM methods, something like:
var flash = document.createElement('embed');
flash.src = 'copy.swf';
flash.width = '1';
flash.height = '1';
flash.name = 'copy';
// To add it inside a container:
document.getElementById('container').appendChild(flash);
// Or to add it to the body at the very bottom:
//document.body.appendChild(flash);


(offtopic, guessing by the name of the Flash file: note that if you're using the Flash file to copy stuff onto the clipboard, due to security restrictions in Flash Player 10 it can't be a hidden Flash file. It has to receive user input to copy stuff, for example a click or keypress. This was added to prevent "bad" hidden Flash files overwriting your clipboard with spyware URLs constantly)


Thank you very much for posting that. I really helped.

I load my movie with an onclick event. When something else in the html page is clicked, I need to swap out the movie.
I've tried document.getElementById('flashContent').removeChild(flash);, but can't make it work.

This is the function I call and pass a name such as "sample.swf".

function buildMovie(movieName) {

// create the flash embed object
var flash = document.createElement('embed');
flash.src = movieName;
flash.width = '720';
flash.height = '478';
flash.name = 'movieName';

// Add it inside the flashContent div

document.getElementById('flashContent').appendChild(flash);
}


Help will be greatly appreciated.
0


User is offline gushort 

  • Group: Members
  • Posts: 452
  • Joined: 05-January 11
  • LocationToronto

Posted 30 May 2012 - 06:20 PM (#6)

Doesn't anyone use swfObject anymore?
1


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Enter your sign in name and password


Sign in options
  Or sign in with these services