Load external SWF with parameters in AS3 - javascript

I have a swf file created by EasyPano tourweaver software. the outpout is a swf file with some .bin files to config the swf and other files such as .jpg, .js and so on.
The software create a html file to add the swf but i have to load the swf using flash and AS3. the HTML and JavaScript that the software create is :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mahan</title>
</head>
<body leftMargin="0" topMargin="0" rightMargin="0" bottomMargin="0">
<script type="text/javascript" src="swfobject.js"></script>
<div id="flashcontent">
To view virtual tour properly, Flash Player 9.0.28 or later version is needed.
Please download the latest version of Flash Player and install it on your computer.
</div>
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("twviewer.swf", "sotester", "100%", "100%", "9.0.0", "#000000");
so.addParam("allowNetworking", "all");
so.addParam("allowScriptAccess", "always");
so.addParam("allowFullScreen", "true");
so.addParam("scale", "noscale");
//<!-%% Share Mode %%->
so.addVariable("lwImg", "resources/talarmahan_1_firstpage.jpg");
so.addVariable("lwBgColor", "255,255,255,255");
so.addVariable("lwBarBgColor", "255,232,232,232");
so.addVariable("lwBarColor", "255,153,102,153");
so.addVariable("lwBarBounds", "-156,172,304,8");
so.addVariable("lwlocation", "4");
so.addVariable("lwShowLoadingPercent", "false");
so.addVariable("lwTextColor", "255,0,0,204");
so.addVariable("iniFile", "config_TalarMahan.bin");
so.addVariable("progressType", "0");
so.addVariable("swfFile", "");
so.addVariable("href", location.href);
so.write("flashcontent");
// ]]>
</script>
</body>
</html>
Please Help me!
Thanks

The answer is URLVariables passed to the URLRequest feed into load method of Loader:)
example:
var loader:Loader = new Loader();
var flashvars:URLVariables = new URLVariables()
flashvars["lwImg"] = "resources/talarmahan_1_firstpage.jpg";
flashvars["lwBgColor"] = "255,255,255,255";
flashvars["lwBarBgColor"] = "255,232,232,232";
flashvars["lwBarColor"] = "255,153,102,153";
flashvars["lwBarBounds"] = "-156,172,304,8";
flashvars["lwlocation"] = "4";
flashvars["lwShowLoadingPercent"] = "false";
flashvars["lwTextColor"] = "255,0,0,204";
flashvars["iniFile"] = "config_TalarMahan.bin";
flashvars["progressType"] = "0";
flashvars["swfFile"] = "";
flashvars["href"] = this.loaderInfo.url;
var request:URLRequest = new URLRequest("twviewer.swf");
request.data = flashvars;
loader.load(request);
addChild(loader);
also with following helper method you can get main SWF parameters (from it's html wrapper) and pass it to the loaded SWF:
public function getFlashVars(li:LoaderInfo):URLVariables
{
var vars:URLVariables = new URLVariables();
try
{
var params:Object = li.parameters;
var key:String;
for(key in params)
{
vars[key] = String(params[key]);
}
}
catch(e:Error)
{
}
return vars;
}
then
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest("twviewer.swf");
request.data = getFlashVars(this.loaderInfo);
loader.load(request);
addChild(loader);
For SecurityError: Error#2000 and here - there are many reasons behind this error

Related

URL assigned to iframe by Javascript does not load properly

What I am trying to achieve
I am trying to load a cookie from Website A in the background as a 1 x 1 pixel followed by redirecting users to Website B.
Problem
In the code below, users are redirected to Website B. However, it does not appear that Website A was loading in the background as I could not see the Website A cookie in the browser.
How can I solve this?
Thank you
<html>
<META name="description" HTTP-EQUIV="Refresh" CONTENT="">
<iframe id="MyFrame" style="width: 1px; height: 1px;"></iframe>
</html>
<script>
document.addEventListener("DOMContentLoaded", function(){
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
var tidParameter = urlParams.get("tid");
var offerParameter = urlParams.get("offer");
console.log (offerParameter);
if (offerParameter == "bb") {
var address = "www.websiteA.com/?tid=";
var combined = address + tidParameter;
var iframeSrcValue = document.getElementById("MyFrame").src;
document.getElementById('MyFrame').setAttribute("src", combined);
document.querySelector('meta[name="description"]').setAttribute("content", "5;url=www.websiteB.com");
}
else if (offerParameter == "bd") {
document.querySelector('meta[name="description"]').setAttribute("content", "5;url=https://www.google.com");
}
else {
document.querySelector('meta[name="description"]').setAttribute("content", "5;url=https://www.hotmail.com");
}
});
</script>
What confuses me
When I try the code in this manner, it works (ie. redirects to Website B and cookie from Website A loads). Unclear to me why the addition of the if, else if causes the problem?
<html>
<META HTTP-EQUIV="Refresh" CONTENT="5;url=www.websiteB.com">
<iframe id="MyFrame" style="width: 1px; height: 1px;"></iframe>
</html>
<script>
document.addEventListener("DOMContentLoaded", function(){
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
var mainParameter = urlParams.get('tid');
var address = "www.websiteA.com/?tid=";
var combined = address + mainParameter;
console.log(combined);
var iframeSrcValue = document.getElementById("MyFrame").src;
document.getElementById('MyFrame').setAttribute("src", combined);
});
<script>

Upload files from Local Folder using Dynamic WebTwain Cab file

I am very new to Dynamic WebTwain therefore apologies in advance If I am asking something to basic.
I currently have scanning functionality available in my Dynamic WebTwain but I need to implement Uploading functionality as well. For that I need to use ActiveX Object and DynamicTwain Cab Files. I am reading the documentation of WebTwain but there they are not using ActiveX or Cab files.
Currently, I am using below method for uploading,
DWObject.LoadImageEx("",1);
However, I do not want to upload the images in designated image viewer of Dynamosoft. I want to upload images in a custom Image viewer. For that, I am assuming that I will need to get the object of selected image for it to load in the custom image viewer. How can I do that?
Looking for guidance.
The LoadImageEx method is used to load local images to the Dynamic Web TWAIN image viewer, not for uploading images. To load images to a custom viewer, you just need to use the input element and FileReader.
For example:
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<input type="file" name="document" id="document" accept="image/*">
<div id='customviewer'></div>
<script>
var input = document.querySelector('input[type=file]');
input.onchange = function () {
var file = input.files[0];
var fileReader = new FileReader();
fileReader.onload = function (e) {
var dataURL = e.target.result, img = new Image();
img.src = dataURL;
$("#customviewer").append(img);
}
fileReader.readAsDataURL(file);
}
</script>
</body>
</html>
Using LoadImageEx:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://unpkg.com/dwt#17.1.1/dist/dynamsoft.webtwain.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<input class="button" type="button" value="Load Images" onclick="loadFile()" />
<div id='customviewer'></div>
<script type="text/javascript">
var element = document.createElement('div');
var dwtObj = null;
Dynamsoft.DWT.CreateDWTObjectEx({
WebTwainId: '1'
},
function (obj) {
dwtObj = obj;
dwtObj.Viewer.bind(element);
},
function (err) {
console.log(err);
}
);
function loadFile() {
if (dwtObj) {
dwtObj.LoadImageEx('', 5,
function () {
dwtObj.ConvertToBlob(
[dwtObj.CurrentImageIndexInBuffer],
Dynamsoft.DWT.EnumDWT_ImageType.IT_PNG,
function (result, indices, type) {
var urlCreator = window.URL || window.webkitURL;
var dataURL = urlCreator.createObjectURL(result);
var img = new Image();
img.src = dataURL;
$("#customviewer").append(img);
},
function (errorCode, errorString) {
}
);
},
function (errCode, error) {
}
);
}
}
</script>
</body>
</html>

everytime i try to print pdf using this method it will always produce blank pdf

so i want to print pdf using button and javascript but it will always produce blank pdf/empty pdf. i want something like https://imgur.com/a/PsRqeBR, but i got this instead https://imgur.com/a/J7rzlSq
i try using window.open and then window.print but it still produce blank pdf, i also tried to put url inside window.open instead of declaring it first but that didn't work
HTML
<button type="button" onclick="printme()">click me...</button>
JavaScript
function printme(){
var URL = "https://www.detik.com/";
var W = window.open(URL);
W.window.print();
}
you need to do window.print() instead of w.window.print()
function printme(){
var URL = "https://www.detik.com/";
var W = window.open(URL);
window.print();
}
The source of the following code is Print an external page without opening it
which was mentioned in one of the answers here Printing a web page using just url and without opening new window?
I only modified the link to include your website address:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MDN Example</title>
<script type="text/javascript">
function closePrint() {
document.body.removeChild(this.__container__);
}
function setPrint() {
this.contentWindow.__container__ = this;
this.contentWindow.onbeforeunload = closePrint;
this.contentWindow.onafterprint = closePrint;
this.contentWindow.focus(); // Required for IE
this.contentWindow.print();
}
function printPage(sURL) {
var oHiddFrame = document.createElement("iframe");
oHiddFrame.onload = setPrint;
oHiddFrame.style.position = "fixed";
oHiddFrame.style.right = "0";
oHiddFrame.style.bottom = "0";
oHiddFrame.style.width = "0";
oHiddFrame.style.height = "0";
oHiddFrame.style.border = "0";
oHiddFrame.src = sURL;
document.body.appendChild(oHiddFrame);
}
</script>
</head>
<body>
<p><span onclick="printPage('https://www.detik.com');" style="cursor:pointer;text-decoration:underline;color:#0000ff;">Print external page!</span></p>
</body>
</html>

SAPUI5 and dynamic URL for OData service

I am doing sample example using sapui5. I want to pass URL service dynamically and load ODATA service, but I really new with sapui5 and I don’t know how to do it.
This code below is what i tried to do but it is not working. Thanks a lot for your help.
createContent : function(oController) {
var oLayout = new sap.ui.commons.layout.AbsoluteLayout({width:"340px",height:"150px"});
oLayout.addStyleClass("CustomStyle"); //Add some additional styling for the border
var oLabel = new sap.ui.commons.Label({text:"Service Url"});
var oUrlInput = new sap.ui.commons.TextField({width:"190px"});
oLabel.setLabelFor(oUrlInput);
oLayout.addContent(oLabel, {right:"248px",top:"20px"});
oLayout.addContent(oUrlInput, {left:"110px",top:"20px"});
var oLabel = new sap.ui.commons.Label({text:"Service"});
var oSvcInput = new sap.ui.commons.TextField({width:"190px"});
oLabel.setLabelFor(oSvcInput);
oLayout.addContent(oLabel, {right:"248px",top:"62px"});
oLayout.addContent(oSvcInput, {left:"110px",top:"62px"});
var loadData =new sap.ui.commons.Button({
text : "load",
width:"133px",
press: function() {
oController.load();
}});
oLayout.addContent(loadData, {left:"110px",top:"104px"});
return oLayout;
}
// Controller
load: function(oEvent){
var url = sap.ui.getControl("oUrlInput").getValue();
var svc = sap.ui.getControl("oSvcInput").getValue();
var oModel = new sap.ui.model.odata.OdataModel(url + "/" + svc ,false);
var mylist = new sap.ui.model.ListBinding(oModel);
return mylist;
}
// index.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<script src="resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.ux3"
data-sap-ui-theme="sap_bluecrystal">
</script>
<!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required -->
<script>
sap.ui.localResources("simpleform");
var view = sap.ui.view({id:"idsimpleForm1", viewName:"simpleform.simpleForm", type:sap.ui.core.mvc.ViewType.JS});
view.placeAt("content");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
You have to give your controls an id to access them in the controller. Like this:
// create controls with id
var oLabel = new sap.ui.commons.Label("oLabelId", {text:"Service Url"});
var oUrlInput = new sap.ui.commons.TextField("oUrlInputId", {width:"190px"});
// then to get reference to the control later
var oLabel = sap.ui.getCore().byId("oLabelId");
var oUrlInput = sap.ui.getCore().byId("oUrlInputId");
Make sure, that you use the right Url:
var oModel = new sap.ui.model.odata.OdataModel("/sap/opu/odata/sap/" + svc ,false);
Make sure following.
Change the case of odataModel to ODataModel
Ensure the Service URL also correct
Obtain the reference of the control As described by kjokinen
Regards

Can't get Javascript to interact with Flash

I can't get my Javascript to affect my SWF object.
The object is rendered correctly in the browser but I cannot call the "fill" method that I exposed to the ExternalInterface.
The ready function "flashReady" is not called. Directly calling it from the console says that the flash object does not have the function "fill". Waiting for a while then calling the function does not help.
The error is TypeError: Object HTMLObjectElement has no method 'fill'
Actionscript code:
public class Main extends Sprite
{
public function Main() {
graphics.beginFill(0xff0000);
graphics.drawRect(0, 0, 200, 100);
graphics.endFill();
Security.allowDomain("*");
ExternalInterface.addCallback("fill", fill);
ExternalInterface.call("flashReady");
}
public function fill():void {
graphics.beginFill(0x00ff00);
graphics.drawRect(0, 0, 200, 100);
graphics.endFill();
}
}
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>
Flash UI Demo
</title>
<script type="text/javascript" src="swfobject.js">
</script>
<script type="text/javascript">
function flashReady() {
document.getElementById('AddCallbackExample').fill();
}
var swfVersionStr = "0";
var xiSwfUrlStr = "";
var flashvars = {};
var params = {};
params.quality = "high";
params.bgcolor = "#ffffff";
params.allowscriptaccess = "always";
var attributes = {};
attributes.id = "AddCallbackExample";
attributes.name = "AddCallbackExample";
attributes.align = "middle";
swfobject.embedSWF(
"http://localhost:8001/swf", "flash",
"100%", "100%",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
</script>
</head>
<body>
<div id="flash" />
</body>
</html>
Ok I figured it out, my version of the library didn't support allowDomain to take in "*" as an argument. I replaced it with "localhost" and it worked.

Categories

Resources