calling a javascript function from flash - javascript

Greetings,
I am trying to make my flash button to execute a javascript function. I already did alot of searching and came to a conclusion to use ExternalInterface.call. I also make the allowScriptAccess" to "always" but still it doesn't work.
Here is my flash call:
import flash.external.*;
......................
function rpress() {
ExternalInterface.call("showMessage");
}
And this is how I embedded the flash file to my html: (sorry for the length already)
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>harita</title>
<script language="javascript">AC_FL_RunContent = 0;
function showMessage(){
alert("hey");
}
</script>
<script src="AC_RunActiveContent.js" language="javascript"></script>
</head>
<body bgcolor="#18658c">
<!--url's used in the movie-->
<!--text used in the movie-->
<!-- saved from url=(0013)about:internet -->
<script language="javascript">
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0',
'width', '750',
'height', '420',
'src', 'harita',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'harita',
'bgcolor', '#18658c',
'name', 'harita',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','always',
'movie', 'harita',
'salign', ''
); //end AC code
}
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="750" height="420" id="harita" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="harita.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#18658c" /> <embed src="harita.swf" quality="high" bgcolor="#18658c" width="750" height="420" name="harita" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</noscript>
</body>
</html>

Try changing
'allowScriptAccess','always',
to
'allowscriptaccess','always',
If that doesn't work, try skipping the use of AC_RunActiveContent.js and test with the code in the <noscript> tags. Sometimes I've seen AC_RunActiveContent munch on tags

Related

Not able to click on a flash object

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.

How can i make an image so i can click on it and it plays a sound

I'm trying to make a picture that plays a .wav file once i click on it sort of like this http://www.nooooooooooooooo.com/
(Please excuse the meme)
Here is my current setup
<!doctype html>
<html>
<head>
<title>xxx</title>
<meta charset="utf-8">
<link href="main.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<nav>
<h1> My Projects </h1>
<ul>
<li>Home</li>
<li>Memes</li>
</ul>
</nav>
</header>
<main>
<p>This is a page for Dank Memes.</p>
<img src="meme1.jpg" width="600" height="420" alt=""/> <img src="meme2.jpg" width="500" height="390" alt=""/>
<img src="meme3.jpg" width="600" height="420" alt=""/> <img src="meme4.jpg" width="600" height="432" alt=""/>
<img src="tupac.png" width="600" height="420" alt=""/>
<script>
</script>
</main>
<footer>
<p> Made By xxx </p>
</footer>
</body>
</html>
Thanks for any help you can give.
You what you are looking for is this bit of the code:
var a = document.createElement('audio');
canAudio = !!(a.canPlayType && (a.canPlayType('audio/mpeg;') || a.canPlayType('audio/ogg;') || a.canPlayType('audio/mp4;')));
if (!canAudio)
document.getElementById('no-button').style.display = 'none';
document.getElementById('no-button').onclick = function() {
document.getElementById('nooo').play();
}
It is what handles the playing the sound, it also checks if playing tracks in that browser is supported.
I have simplified that snippet it to make it a easier to read and understand:
var audio = document.createElement("audio");
canPlayAudio = !!(audio.canPlayType && (audio.canPlayType("audio/mpeg;") || audio.canPlayType("audio/ogg;") || audio.canPlayType("audio/mp4;")));
if (!canPlayAudio) {
document.getElementById("no-button").style.display = "none";
}
document.getElementById("no-button").onclick = function() {
document.getElementById("nooo").play();
};
Hope it helps, all the best & good luck.
The answer is in this snippet of their source code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="darthvadernobutton">
<audio id="nooo">
<source src="nooo.ogg" type="audio/ogg">
<source src="nooo.mp3" type="audio/mpeg">
<source src="nooo.mp4" type="audio/mp4">
<script language="javascript">
if(AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '550',
'height', '400',
'src', 'button',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'button',
'bgcolor', '#ffffff',
'name', 'button',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'button',
'salign', ''
); // end AC code
}
</script>
<noscript>
<object align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" height="400" id="button" width="550">
<param name="allowScriptAccess" value="sameDomain">
<param name="allowFullScreen" value="false">
<param name="movie" value="button.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#ffffff">
<embed allowfullscreen="false" height="400" src="button.swf" type="application/x-shockwave-flash" width="550">
</object>
</noscript>
</audio>
<div>
<button id="no-button"></button>
<script>
var a = document.createElement('audio');
canAudio = !!(a.canPlayType && (a.canPlayType('audio/mpeg;') || a.canPlayType('audio/ogg;') || a.canPlayType('audio/mp4;')));
if(!canAudio) {
document.getElementById('no-button').style.display = 'none';
}
document.getElementById('no-button').onclick = function(){
document.getElementById('nooo').play();
}
</script>
</div>
</div>
</body>
</html>
This is the snippet you are looking for:
<div>
<button id="no-button"></button>
<script>
var a = document.createElement('audio');
canAudio = !!(a.canPlayType && (a.canPlayType('audio/mpeg;') || a.canPlayType('audio/ogg;') || a.canPlayType('audio/mp4;')));
if(!canAudio)
document.getElementById('no-button').style.display = 'none';
document.getElementById('no-button').onclick = function(){
document.getElementById('nooo').play();
};
</script>
</div>

javascript page load position

We moved an old site to a new server for hosting purposes before we build a new site.
Once moved the site now loads at the bottom of the page. I've tried all sorts of adjustments to the javascript and html but I'm at a loss to what is causing it to load at the bottom. Any help in identifying the problem would be greatly appreciated...
Current site location:
http://eversighthosting.info/artstow/Artspg1.htm
The page code:
<script language="javascript">
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0',
'width', '100%',
'height', '100%',
'src', 'Arts',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'Arts',
'bgcolor', '#ffffff',
'name', 'Arts',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'Arts',
'salign', ''
); //end AC code
}
</script><embed src="Artspg1_files/Arts.swf" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer" play="true"
loop="true" scale="showall" wmode="window" devicefont="false" bgcolor="#ffffff"
name="Arts" menu="true" allowfullscreen="false" allowscriptaccess="sameDomain"
salign="" type="application/x-shockwave-flash" align="middle" height="100%"
width="100%">
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash
swflash.cab#version=5,0,0,0" width="100%" height="100%" id="Arts"
align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="Arts.swf" /><param name="quality"
value="high" /><param name="bgcolor" value="#ffffff" /> <embed
src="Arts.swf" quality="high" bgcolor="#ffffff" width="100%"
height="100%" name="Arts" align="middle"
allowScriptAccess="sameDomain" allowFullScreen="false"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</noscript>
The direct reason, though I can't go so far as to explain why this is, is that Arts.swf appears twice in the page. The higher, blank version appears to originate from the <noscript> tag, although I don't really have an idea of why that's being loaded instead of ignored on a JS-capable browser. I would be pretty surprised if any browsers running without JavaScript have flash loaded, so I would just take that content out and replace it with a warning that says "You need Flash to view this site"

Close html page after flash (swf) animation ends

I have published my flash file to a html page. How would I automatically close this page once the flash animation ends. I can tell flash via actionscript to stop, but I need the whole page to automatically close.
Just tried to use javascript to tell website to close after 5 seconds (time of animation). Didn't want to work. Time of close does NOT matter just as long as it closes after animation. Here is code:
<html>
<head>
<meta charset="UTF-8">
<title>Splashload</title>
<style type="text/css" media="screen">
html, body { height:100%; background-color: #ffffff;}
body { margin:0; padding:0; overflow:hidden; }
#flashContent { width:100%; height:100%; }
</style>
</head>
<script>
function loaded()
{
window.setTimeout(CloseMe, 500);
}
function CloseMe()
{
window.close();
}
</script>
<body>
<div align="center" id="flashContent">
<object type="application/x-shockwave-flash" data="Splashload.swf" width="766" height="750" id="Splashload" style="float: none; vertical-align:middle">
<param name="movie" value="Splashload.swf" onLoad="loaded()" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<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>
</object>
</div>
</body>
</html>
For testing purposes, here is the SWF fie
http://www.megafileupload.com/en/file/512654/Splashload-swf.html
You can call CloseMe function via ExternalInterface.call(functionName, param); when animation is complete

Insert transparent flash file on page

I have an animation transparent flash file, this file should be full screen,
In this animation I have a bird which should fly from left to right, this action is on flash file and I published the flash file in transparent mode,
Now I should insert this SWF file on top of all layers.
I can do this by div and position but when I click everywhere of this page I will get default flash menu.
How can I limit the flash menu to just visible area ?
UPDATE:
I mean was full width,
the HTML code which Flash created for me is this :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Untitled-1</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
html, body { height:100%; background-color: #ffffff;}
body { margin:0; padding:0; overflow:hidden; }
#flashContent { width:100%; height:100%; }
</style>
</head>
<body>
TEST
<div id="flashContent">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="1280" height="853" id="Untitled-1" align="middle">
<param name="movie" value="Untitled-1.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="false" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="Untitled-1.swf" width="1280" height="853">
<param name="movie" value="Untitled-1.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="false" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--<![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>
</div>
</body>
</html>
Well, I if you want your menu to be disabled then you can't do that wit html or js but you can do that in your flash file using actionscript like this:
Stage.showMenu=false;
Or you can disable right click on your webpage like this:
<script language="javascript">
document.onmousedown=disableclick;
function disableclick(e)
{
if(event.button==2)
{
return false;
}
}
</script>
AND
<body oncontextmenu="return false">
...
</body>
The problem is the Flash is tranparent , but it is on top of the HTML. Clicking will generate a click event on the Flash element, blocking the other things on your website.
With jQuery it's easy to get around this.
You will need to get the coördinates of the click event and then trigger a click on the page HTML element which has the same coördinates.
$('#flashContent').click(function(e){
evt = e || window.event;
// make flash disappear
$('#flashContent').hide();
// get element at point of click
starter = document.elementFromPoint(evt.clientX, evt.clientY);
// send click to element at finger point
$(starter).click();
// bring back the flash
$('#flashContent').show();
});
This will work in most cases. Remember to include the jQuery library in the headsection and wrap this function within document.ready function if you aren't using jQuery allready.
Note: For right clicking you should make a similar function to this one. Instead it will listen for a right click event.
Hope it helped you out.

Categories

Resources