I have two flash banners (.swf) and i want to show them randomly on page refresh.
I can do it with image files (using javascript), but with flash it's not working
For image files i can do this.
<script type='text/javascript'>
var HeaderImage= new Array()
HeaderImage[0]="URL-OF-HEADER-IMAGE-1";
HeaderImage[1]="URL-OF-HEADER-IMAGE-2";
var random=Math.round(2*Math.random());
document.write("<style>");
document.write("#header-wrapper {");
document.write(' background:url("' + HeaderImage[random] + '") no-repeat left TOP;');
document.write(" }");
document.write("</style>");
</script>
You can use SWFObject to embed the flash file and then randomly pick up the name of the file:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
function getRandomFilename()
{
var names = ['myFile1.swf', 'myFile2.swf', 'myFile3.swf'];
var r = Math.floor(Math.random() * names.length);
return names[r];
}
var flashvars = {};
var params = {};
var attributes = {};
swfobject.embedSWF(getRandomFilename(), "myFlashContent", "800", "60", "9.0.0", false, flashvars, params, attributes);
</script>
</head>
<body>
<div id="myFlashContent">
</div>
</body>
If you can do it with image files, you can do it with flash. Embedding flash is a bit different, however, than with image files.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="movie_name" align="middle">
<param name="movie" value="movie_name.swf"/>
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="movie_name.swf" width="550" height="400">
<param name="movie" value="movie_name.swf"/>
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflash">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"/>
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
That is the embed code for flash apps. One alternative is you can use javascript to change the parameters in there. However, you could just as easily use iframes.
<iframe id="mov" src="movie.swf"></iframe>
Then, just use javascript to change the src value to the path to your flash movie.
Related
How to click flash object inside a frame. HTML code is given below.
I found many related topics but none of them resolved my issue. So I am posting my HTML code here. I am new to selenium so please bear with me.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Visualizer Plugin</title>
<link href="../../plugins/Visualizer/resources/css/mystyle.css" rel="stylesheet" type="text/css">
<script src="../../plugins/Visualizer/resources/javascript/flex.js" type="text/javascript">
</script>
<script src="../../plugins/Visualizer/resources/javascript/PluginSupport.js?server=blt05574004" type="text/javascript">
</script>
<script src="../../plugins/Visualizer/resources/javascript/BaseController.js" type="text/javascript">
</script>
<script src="../../plugins/Visualizer/resources/javascript/Setup.js" type="text/javascript">
</script>
<style type="text/css" media="screen">
body {
margin: 0px;
overflow: hidden
}
</style>
</head>
<body scroll="no" style="background-color: transparent;" onload="initSetupScript();">
<div align="center">
<div id="flashcontent">
<object width="100%" height="100%" id="Visualizer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
<param name="allowFullScreen" value="true">
<param name="align" value="middle">
<param name="quality" value="high">
<param name="wmode" value="transparent">
<param name="allowScriptAccess" value="sameDomain">
<param name="type" value="application/x-shockwave-flash">
<param name="src" value="../../plugins/Visualizer/resources/swf/../../plugins/Visualizer/resources/swf/Visualizer.swf?r=7.5.00">
<param name="flashvars" value="bridgeName=Visualizer">
</object>
</div>
</div>
<script language="JavaScript" type="text/javascript">
var src = "../../plugins/Visualizer/resources/swf/Visualizer";
var id = "Visualizer";
var uri = "../../plugins/Visualizer/resources/swf/";
var flashvars = "";
var release = "7.5.00";
createSWF(src, id, uri, release, flashvars);
</script>
</body>
</html>
So you need flashcontent it not flash exactly. You can use below XPATH
//div[#id='flashcontent']//param[#name='quality']
Above xpath will return the value as quality element
Note : If above element is comes under any frame then you need to switch it first
If Selenium can't operate on Flash content. You need to use another framework for automating the Flash content like : Sikuli
Refer :
http://www.softwaretestinghelp.com/sikuli-tutorial-part-1/
http://www.sikuli.org/testimonials.html
Hope it will help you.
I have no HTML knowledge, I just have a simple task that I can't seem to grasp the concept of doing.
I want to take a url parameter and pass it to a swf object. I've figured out getting the parameter via javascript, but getting that return string to the object is my issue.
<!DOCTYPE html>
<html>
<body>
<script>
function myFunction() {
return "http://www.Twitch.tv/swflibs/TwitchPlayer.swf?channel=twitch";
}
</script>
Link Example
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="800" height="600" id="mymoviename">
<embed src="#" onload="this.src=myFunction()" quality="high" bgcolor="#ffffff"
width="800" height="600"
name="mymoviename" align="" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>
</body>
</html>
Markup based on Suggested answer(still does not work)
<!DOCTYPE html>
<html>
<body>
Link Example
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
width="800" height="600" id="mymoviename">
<embed src="#" quality="high" bgcolor="#ffffff" width="800" height="600"
name="mymoviename" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>
<script>
function myFunction() {
return "http://www.Twitch.tv/swflibs/TwitchPlayer.swf?channel=twitch";
}
document.getElementById('mymoviename').src = myFunction();
</script>
</body>
</html>
You can do it by following the following steps.
Move your <script> to just before </body>
And add the below code in <script>:
Code:
function myFunction() {
return "http://www.Twitch.tv/swflibs/TwitchPlayer.swf?channel=twitch";
}
document.getElementById('mymoviename').src = myFunction();
I found this article:
http://www.permadi.com/tutorial/flashVars/
Instead of passing the javascript variable to html markup, just write the markup with the script itself. Here is the working code:
<HTML><HEAD><TITLE>Example</TITLE></HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
var myQueryString=document.location.search;
// remove the '?' sign if exists
if (myQueryString[0]='?')
{
myQueryString=myQueryString.substr(3, myQueryString.length-1);
}
document.write(
'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://macromedia.com/cabs/swflash.cab#version=6,0,0,0" WIDTH="250" HEIGHT="250" id="flaMovie1"> <embed src="'+myQueryString+'" quality="high" bgcolor="#ffffff" width="800" height="600" name="mymoviename" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">\n'+
'</embed>\n'+
'</OBJECT>');
</SCRIPT>
</BODY>
</HTML>
I'm attempting to creating a music player that plays a random song by choose a random item from an array and setting it and other things, via concatenation, as the embed's src.
<script type="text/javascript">
//Playlist
var musicArray = ['b.mp3', 'b2.mp3', 'b3.mp3'];
//src vars
var first = 'niftyplayer.swf?file=';
var last = '&as=1';
// Shuffle
var mid = musicArray[Math.floor(Math.random() * myArray.length)];
//Set src
getElementById("embed").src='first+mid+last';
getElementById("param").value='first+mid+last';
</script>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0, 0" width="165" height="38" id="niftyPlayer1" align="">
<param id="param" name=movie value="">
<param name=quality value=high>
<param name=bgcolor value=#FFFFFF>
<embed id="embed" src="" quality=high bgcolor=#FFFFFF width="165" height="38" name="niftyPlayer1" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>
<script type="text/javascript" language="javascript" src="niftyplayer.js"></script>
However, my script does not work.
JSFiddle of niftyplayer.js
In this case, load js after html.
Then, fix your 'embed' and 'param'.
-- code below.
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0, 0" width="165" height="38" id="niftyPlayer1" align="">
<param id="param" name=movie value="">
<param name=quality value=high>
<param name=bgcolor value=#FFFFFF>
<embed id="embed" src="" quality=high bgcolor=#FFFFFF width="165" height="38" name="niftyPlayer1" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>
<script type="text/javascript" language="javascript" src="niftyplayer.js"></script>
<script type="text/javascript">
//Playlist
var musicArray = ['b.mp3', 'b2.mp3', 'b3.mp3'];
//src vars
var first = 'niftyplayer.swf?file=';
var last = '&as=1';
// Shuffle
var mid = musicArray[Math.floor(Math.random() * myArray.length)];
//Set src
getElementById("embed").src = first + mid + last;
getElementById("param").value = first + mid + last;
</script>
Put the javascript code after html, and remove quotes from below lines 'first+mid+last'
getElementById("embed").src= first+mid+last;
getElementById("param").value= first+mid+last;
I'm trying to call a function in an action script using the ExternalInterface.addCallback API, but I can't seem to get it to work. Here's what I have:
ActionScript:
//MyClass.as
package {
import flash.display.Sprite;
import flash.external.ExternalInterface;
public class MyClass extends Sprite
{
public function MyClass()
{
ExternalInterface.addCallback('getStringJS', getStringAS);
}
public function getStringAS():String
{
return "Hello World!";
}
}
}
NOTE: I'm compiling this into an swf using the flex mxmlc compiler if that matters.
HTML/Javascript:
<!doctype html>
<html>
<head>
<title>User Identification</title>
<head>
<body>
<object id="MyClass" name="MyClass" type="application/x-shockwave-flash" data="MyClass.swf" width="1" height="1">
<param name="movie" value="MyClass.swf">
<embed src="MyClass.swf" width="1" height="1">
</object>
<script type="text/javascript">
var flash = document.getElementById("MyClass");
var str = flash.getStringJS();
alert(str);
</script>
</body>
</html>
The error I'm getting is:
Uncaught TypeError: Object #<HTMLObjectElement> has no method 'getStringJS'
I also tried adding in a timeout in case the swf file wasn't loading, but I didn't have any success with that method either.
Any thoughts?
Cheers,
Mike
I figured it out. The key way to signal the javascipt through ExternalInterface.call so we know for sure that the swf is loaded. The most "Universal" way to do this is as follows:
MyClass.as
//MyClass.as
package {
import flash.display.Sprite;
import flash.external.ExternalInterface;
public class MyClass extends Sprite
{
public function MyClass()
{
ExternalInterface.addCallback('getStringJS', getStringAS);
if (ExternalInterface.available) {
ExternalInterface.call("isConnectedFlex");
}
}
public function getStringAS():String
{
return "Hello World!";
}
}
}
index.html
<!doctype html>
<html>
<head>
<title>User Identification</title>
<head>
<body>
<object id="MyClass" name="MyClass" type="application/x-shockwave-flash" data="MyClass.swf" width="1" height="1">
<param name="movie" value="MyClass.swf">
<embed src="MyClass.swf" width="1" height="1">
</object>
<script type="text/javascript">
var flash = document.getElementById("MyClass");
function isConnectedFlex() {
var str = flash.getStringJS();
alert(str);
}
</script>
</body>
</html>
I think the issue is a matter of the flash not being loaded. I tried your code using the window.onload event and it worked for me:
The flash is the same...
HTML/JS :
<!doctype html>
<html>
<head>
<title>User Identification</title>
<head>
<body>
<object id="MyClass" name="MyClass" type="application/x-shockwave-flash" data="MyClass.swf" width="1" height="1">
<param name="movie" value="MyClass.swf">
<embed src="MyClass.swf" width="1" height="1">
</object>
<script>
window.onload = function() {
var flash = document.getElementById("MyClass");
var test = flash.getStringJS("test");
alert(test); //pops up with "Hello World!" on Firefox
};
</script>
</body>
</html>
Does that help?
Is there a Flash MP3 player that would allow me to do following to pass URL to mp3 file and get it automatically played. To help out with answer - here is detailed code that describes what I would like to do:
<object id="mp3PlayerSwf" type="application/x-shockwave-flash" data="mp3Player.swf">
<param name="movie" value="mp3Player.swf">
</object>
<input type="button" id="soundPlay1" value="Sound Play 1" />
<script type="text/javascript">
function eventHandler1(sender) {
var mp3Player = document.getElementById("mp3PlayerSwf");
mp3Player.playSound("http://myUrl.com/my.mp3");
}
var soundPlay1 = document.getElementById('soundPlay1');
if (soundPlay1.addEventListener) {
soundPlay1.addEventListener('click', eventHandler1, false);
}
// IE
else if (soundPlay1.attachEvent) {
soundPlay1.attachEvent('onclick', eventHandler1);
}
</script>
Constraint is that I can't use libraries that have JavaScript initialization - like for example SoundManager2 - http://www.schillmania.com/content/projects/soundmanager2/
Thanks for any help!
Try dewplayer: http://www.alsacreations.fr/dewplayer-en
You can use it like this (sample code taken from the link):
<object type="application/x-shockwave-flash" data="dewplayer.swf" width="200" height="20" id="dewplayer" name="dewplayer">
<param name="movie" value="dewplayer.swf" />
<param name="flashvars" value="mp3=test.mp3" />
<param name="wmode" value="transparent" />
</object>
Another player would be http://musicplayer.sourceforge.net