I've read through what little documentation there is on Google's Swiffy page, and I don't see any way to pass FlashVars data to the HTML5 swiffyobject.
On an old version of a site there is this embed code (which uses SWFobject) to pass a javascript variable to Flash:
var mainmovie = new SWFObject("mainpage.swf", "themovie", "640", "480", "8", "#000099");
mainmovie.addParam("align", "middle");
mainmovie.addParam("wmode", "opaque");
mainmovie.addVariable("PageLayout", layoutCode);
mainmovie.write("target_div");
In other words, the variable PageLayout is passed to the Flash movie from .js
Is there some way to similarly pass javascript variables to swiffyobjects, either through something similar to SWFobject's addVariable, or through the standard FlashVars interface?
Just answering my own question here because I found the answer.
The Swiffy equivalent of FlashVars is:
stage.setFlashVars("VariableName = value");
where "stage" is the Swiffy HTML5 object.
Related
Im using pdfobject along with forcePDFJS which uses pdfjs viewer.js to render pdf's.. Once they are rendered I need to be able to jump to pages without reloading the document.. The documents can be pretty large
I've seen some mentions about using PDFApplicationViewer.pdfview.currentPageNumber. but I haven't seen a good example on how to use it correclty
I've seen two example of using the PDFApplicationViewer
1. PDFApplicationViewer.pdfview.currentPageNumber = pagNum;
2. document.getElementById('mycanvas').contentWindow.PDFApplicationViewer.pdfview.currentPageNumber = pagNum;
Althought the second on make more sense Im not sure where the contentWindow object from the element comes from. Im assuming the pdfobject embeds something that I could get access too but I can't figure it out..
Also, since I couldn't really find alot on this.. Is this even possible..
For time constraint reasons I don't want to have to put together a new viewer using pdfjs.. I like what comes with the viewer.html.. I just need to jump the pages without reloading
PDFObject.embed doesn't return any reference So I looked into the pdfObject code to see how it was embedding the pdf..
for this to work there needs to be a iframe.. So when rendering with pdfobject Im using a configureation as follows:
Notice forcePDFJS=true
if(!pageNum)
pageNum=1;
var options = {
pdfOpenParams: {
view: "FitV",
page: pageNum
},
forcePDFJS: true,
PDFJS_URL: "../pdfjs/web/viewer.html"
};
Here is code that works
var pdfviewer = document.getElementById('pdfviewer');//get the viewer element
var contenttag = pdfviewer.getElementsByTagName("iframe")[0]//got this from pdfobject code
contenttag.contentWindow.PDFViewerApplication.pdfViewer.currentPageNumber = parseInt(pageNum);//change the page
In my case, the pdfviewer id is not available anymore.
PDFObject does return the reference of iframe that it creates. I was using basic HTML + JS so I had to save that reference to global window object to be able to access it from anywhere in the project.
Finally, with the reference we have, we can access the PDFViewerApplication object as below and manipulate the PDF:
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
calling a Flash ExternalInterface with JavaScript
I have a flash file with AS code. I want to run Javascript that will run a function the AS. For example: In the AS I have a function called "loadXML". The object that holds the SWF file called "pawel" (The ID of the object). How can I run a Javascript code that will run on "pawel" the function "loadXML"? I'm using Flash 6 with AS 3.
You should use ExternalInterface.addCallback() method. See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#addCallback() for details.
I suggest you check this http://www.redcodelabs.com/2012/04/calling-actionscript-method-from-javascript/ it has running sample and as3/js code.
I believe the goal here is to send the swf (which has compiled an external .as file) the location of an xml file somewhere on the server so the swf can compile, parse, and create something.
I've done this many times, using flash variables, which may be useful to you as well. When embedding the .swf in your webpage you can send it flash variables via js or html, or dynamically with php. Once i have my fla working perfectly with hardcoded variables (like the xml) i then add the flash variable code to the head and make a few minor adjustments to the fla – which usually breaks the fla from running "properly" within flash (because it's now dependent upon these external variables)
anyways, here's how i do my flash vars (there's other ways, worth a good google search)
import flash.net.*;
var flashVars:Object = new Object();
flashVars = this.loaderInfo.parameters;
var xmlVal;
for (var item:String in flashVars)
{
switch (item)
{
case "xmlLocation" :
xmlVal = String(flashVars[item]);
break;
}
}
Here's the javascript which sends the values:
<script type="text/javascript">
//flashObj
var flashvars = {};
flashvars.xmlLocation = "http://google.com/myXML.xml";
var params = {wmode:"transparent"};
var attributes = {};
swfobject.embedSWF("images/banner.swf", "yourSliderId", "175", "300", "9.0.0", false, flashvars, params, attributes);
</script>
this is using SWFObject (an open API flash embedding js library) to handle the swf embed. I prefer it because if you look at the code above you can read it and understand it, the default way is really hard to read, edit and understand.
If you simply need XML and then you're done, this will work for you. If you still need to say hit the 'next' or 'previous' button using javascript, refer to this web site article, i believe this may help you out further:
http://arrixlive.wordpress.com/2005/03/25/javascript-in-love-with-flash-control-swf-from-javascript/
I am using the swfObject library to dynamically embed a MP3 player i've made in Flash CS5. In the .fla file, i've declared a list of methods that can be called via Javascript (using the flash.external.ExternalInterface flash class).
That's not the problem since all these function work properly when called from Google Chrome's console.
However, swfObject provides a way to invoke javascript API only if the .swf has been statically included (i.e. using swfobject.registerObject() ) but i can't find a way to achieve the same goal when the .swf is dynamically included (i.e. using swfobject.embedSWF() ).
Thanks in advance for your help and contibutions :)
When you are using swfobject.embedSWF, you can specify the ID of the swf object in the attributes parameters :
swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn)
Example :
swfobject.embedSWF(
"YourFlash.swf", "WhereToPlaceThis", "0px", "0px", "10.0.0",
"expressInstall.swf", {}, {}, { id : "IdOfTheSWF" },
function () {
var SWF = document.getElementById("IdOfTheSWF"); // That's your SWF //
SWF.yourFlashFunction(); // And you can invoke function //
}
);
I have to call an ActionScript method via Javascript, but I have a problem accessing the flash object itself. I embed the flash file via the help of swfobject.
Previously, when I use the static publishing approach, I could easily get the flash object by calling these methods:
swfobject.registerObject("flash_object", "9", "expressInstall.swf");
var flash_object = swfobject.getObjectById("flash_object");
For some technical reasons, now I have to use the dynamic publishing approach (using swfobject.embedSWF). But, as mentioned in the documentation, the method getObjectById can only be used if you use static publishing approach.
Now, how can I access the flash object?
Cheers,
Andree
With the good old document.getElementById("flash_object")
Just be sure to do it after page load. You can set it up via the callback function, too:
var mySWF = null;
var flashvars = {};
var params = {};
var attributes = {};
var embedHandler = function (e){
mySWF = e.ref; //e.ref is a pointer to the <object>
//do something with mySWF
};
swfobject.embedSWF("/path/to/file.swf", "flash_object", "550", "400", "9", "/path/to/expressInstall.swf", flashvars, params, attributes, embedHandler);
I would suggest going through the documentation on How to Integrate Flex with Java EE applications.
It explains how to use Flashvars to pass data from javascript to actionscript method. I used it myself and it works just fine.
There is a software product called AnyChart which is great for embedding Flashed based charts in web pages. AnyCharts can also export to PNG file format. Here is an example:
<script type="text/javascript" language="javascript">
//<![CDATA[
var chart = new AnyChart('http://www.mysite.com/swf/AnyChart.swf');
chart.width = 600;
chart.height = 300;
chart.setXMLFile('http://www.mysite.com/anychart.xml');
chart.addEventListener("draw", function() { saveChartAsImage(chart); });
chart.write("content-box");
//]]>
</script>
My ultimate goal is to make a automated service to export the AnyChart charts to PNG format. So I made a service with Indy which calls pages containing the AnyChart javascript. But the problem seems to be that Indy cannot execute the javascript.
Is there a way to enable Indy to execute javascript?
No, Indy does not execute Javascript. You may have also noticed that it doesn't parse or display HTML, and it doesn't run Flash, either. Indy does network protocols.
You could import the Microsoft Script Control ActiveX object and have that run your Javascript. If you need details on that, post a new question.
You don't have to use Indy for this. If you want you can use TWebBrowser.
IHTMLWindow2 interface has execScript function. So may be you can :
var
Doc : IHTMLDocument2;
Win : IHTMLWindow2;
aBrowser : TWebBrowser;
//...
begin
//...
Doc := aBrowser.Document as IHTMLDocument2;
Win := Doc.parentWindow;
Win.execScript('alert(SomeMessage);', 'JavaScript');
end;
Did you try vcl FOR THE web (aka Intraweb atozed) ?
There is a teechart version wich is quite useful, you can also execute "external" javascript code within any of the TiwForms of your web app (the exact same code you are using now).
Post a new question if you need to and I'll be glad to help.