HTMLLoader.window
I'm trying to call a Javascript function via
HTMLLoader.window within the event listener for htmlDOMInitialize
and it says the function does not exist. What am I not
understanding?
import flash.html.*;
var htmlLoader = HTMLLoader.createRootWindow();
htmlLoader.loadString("<html><script
language='Javascript'>function
testFunc(){alert('test')}</script><body><p>Hello
World</p></body></html>");
htmlLoader.addEventListener("htmlDOMInitialize",htmlDOMInitialize);
function htmlDOMInitialize(evt){
trace(evt.target.window); // [object DOMWindow]
evt.target.window.testFunc(); // TypeError: Error #1006:
testFunc is not a function
}
The HTMLDOMInitialize event is dispatched before any objects
have been created in the new HTML window or DOM. This gives you an
opportunity to create and initialize variables that objects in the
new window will use. However, since said objects haven't been
created yet, you can't access them at the time this event is
dispatched.
Similar Messages
-
Stop Sounds in HTMLLoader object
I have an AIR application that has an html loader object
(htmlLoader) within it. The page that the html object loads is a
flash AS2 game. The game has a lot of sounds, some very long that
are embedded in the timeline. We don't have the sources for these
games, therefore we can't change them.
What we did is we had an html page that loads the swf with an
object tag and we give it an ID "swfContent"
I am trying to do something like
htmlLoader.window.swfContent.stopAllSounds() (obviously this
is not an actual line of code, but it explains the logic behind it)
Is there a way to do this?You can wrap the sound in another swf and then supress it by
setting the volume to zero like below. Then you could load that swf
in your html.
var t:SoundTransform = new SoundTransform();
t.volume = 0;
swfContent.soundTransform = t; -
How to access loaded content of HTMLLoader
I have a HTMLLoader and after the content is loaded, I'd like
to access the loaded content. There should be an easy way but I
could not find it ...
And what if the loaded content is PDF?Suppose you have:
var htmlLoader:HTMLLoader = new HTMLLoader();
//Add to display list, load content, etc...
Then you can access the window object of the loaded page
thusly:
htmlLoader.window
If the HTMLLoader loads a PDF file directly, I suspect that
under the covers AIR embeds it in an HTML page. So you could still
access htmlLoader.window and then find the PDF object in the page.
(I haven't tried this myself, though.) -
HTML window in AIR app can't open new window
Hi, By allowing HTML content to be displayed inside our AIR app it's possible for our partner organization to write their own custom features hosted on HTML pages at their site, but for their content to appear integrated seamlessly within our AIR app's container so that it looks like it belongs there...
We've successfully got an HTML window within our AIR app that navigates to content in a sub-folder on a web-hosted domain. Content displays correctly and hyperlinks function within the HTML window as we'd expect apart from three scenarios that appear to be manifestations of the same problem:
A hyperlink on a page shown in-app with a link to a PDF stored on the web server has no action
A hyperlink on a page shown in-app with a link to a video file stored on the web server has no action
A hyperlink on a page shown in-app with a link to another site (target="_blank" parameter) has no action
All three hyperlink scenarios work as we'd wish if we navigate to the page in a standard browser.
How can we code the HTML so that we can display selected content in an HTML window inside the AIR app; but have selected hyperlinks invoke the user's standard web browser, or launch Adobe Reader, or play a video file etc?
Note, we understand how to do those things within AIR itself, but can't figure out how to achieve this from inside the HTML window in the app.Hello,
As to "_blank" links:
this is long-standing lacking feature - as there is no introspection of event of such type - so it goes and could not be prevented. One could either handle all navigation with system browser (all links open in system external browser) or handle them in embedded browser - similar issue is bugging people using phoneGab with jQueryMobile - application eats all external links or none at all). There are solution for that including runtime introspection of DOM object to retrieve all anchor (a) tags in rendered document and attach custom click handler via host object like on complete:
var document:Object = html.htmlLoader.window.document;
if(!document && !document.hasOwnProperty("getElementsByTagName")) return;
var linksArray:Object = document.getElementsByTagName("a");
if(!linksArray) return;
var a:Object = null;
for(var i:Number = 0; i < linksArray.length; i++)
a = linksArray[i];
if(a)
a.onclick = function(event:Object):Boolean
if(event.target.hasOwnProperty("href") && event.target.hasOwnProperty("target"))
if(event.target.target != "_blank") return true;
flash.net.navigateToURL(new URLRequest(event.target.href));
return false;
but if you have control on what content is provided you could take care of handling links depending on runtime feature detection that way in javascript:
<script type="text/javascript">
function handleClick(a)
if(!window.runtime) return true;
if(a.hasAttribute("target") && a.getAttribute("target") == "_blank")
var href = a.getAttribute("href");
var req = new window.runtime.flash.net.URLRequest(href);
if(req) window.runtime.flash.net.navigateToURL(req);
return false;
</script>
<a href="http://www.bbc.co.uk/" target="_blank" onclick="handleClick(this);">BBC</a>
<br />
<a href="http://www.google.com/" onclick="handleClick(this);">Google</a>
(above could be scripted globally with help of jQuery for example for all links without much coding).
In 2.7 there is new event introduced to help with introspection so one could prevent event if link is internal and do whatever is expected in application:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.h tml
If you post some details on how PDF and video content is expected to be shown in html I'm sure someone would share some hints as well,
regards,
Peter Blazejewicz -
Flex Based AIR application & remote HTML
The question is ....from a flex based AIR application do you
always have full access to all of the HTML content loaded from a
remote site via the DOM (htmlLoader.window.document), or is the
'context' of what you can see limited to what the initial url
requested can see - i.e. the context is as if it were javascript
running in the page corresponding to the initial URL.
As far as i can see if i request say the page
http://www.abc.com/page1.htm
and it has content along the lines of
<IFRAME src="
http://www.xyz.com/page3.htm"
id="remoteframe" />
<IFRAME src="
http://www.abs.com/page2.htm"
id="localframe" /?
then using the htmlControl.htmlLoader.window.document i can
successfully navigate the DOM for the initial page loaded and
localframe, but
not remoteframe.
I've seen various comments about sandboxes, bridges and
applicationdomains in the documentation but i don't see how this
can help me.
Can someone please shed some light on this? Can i from the
AIR application access all of the DOM, or am i restricted to the
initially loaded page and pages referenced from the same domain in
the page?
Thanks
JamieHi,
From your AIR application, you can only access "exposed
properties" in remoteframe.
You expose a property by using the sandbox bridge mechanism:
http://livedocs.adobe.com/air/1/devappshtml/help.html?content=security_5.html#1092959 -
Different behaviour air apps running in flex builder or standalone
Hello,
<mx:HTML location="
http://www.google.com"
id="myBrowser">
I try to get the mouse selected text in my browser with the
following javascript bridge :
myBrowser.htmlLoader.window.getSelection().toString()
That work fine when my apps is running throw the flex builder
IDE.
But when it running as a standalone on the same computer, I
get an empty string.
Do you know why ?
Thanks
BenVery helpful! Should be placed in the blazeDS docs!
Chris -
NativeDragManager and canceling a dnd operation
Hi all,
I'm developing an HTML/JavaScript based AIR 2.0.3 desktop application where I want to make use of the File Promises APIs. Here's what my code looks like:
var cb = new air.Clipboard(), promises = [];
for(var i = 0, l = this._urls.length; i < l; i++) {
var fp = new air.URLFilePromise();
fp.request = new air.URLRequest(this._urls[i].url);
fp.relativePath = this._urls[i].fileName;
promises.push(fp);
cb.setData(air.ClipboardFormats.FILE_PROMISE_LIST_FORMAT, promises);
air.NativeDragManager.doDrag(window.htmlLoader, cb);
So, I can pop a few urls into the clipboard and have them download to the local file system when the user drags an few files out of my AIR application.
Here's what I'd like to be able to do though:
While the user is dragging the files out of my AIR application, I'd like to be able to cancel the dnd operation to prevent them from dropping them based on certain criteria. Is there any way to do this? I tried invoking the air.NativeDragManager.dragInitiator.stopDrag method, but no luck there. I tried dispatching a NATIVE_DRAG_COMPLETE event to try to trick the NativeDragManager into thinking that the drag operation had stopped, but no luck there either.
Anyone any ideas on this
Cheers
Sean
Also - is anyone aware of a way to customize the little sprite that appears beside the user's cursor when they start a native drag and drop operation? I'd like to be able to display a thumbnail of the file the user is dragging out of my AIR application beside their cursor instead of the default 'jpeg' avatar/sprite during a drag and drop.Tried the following code in an attempt to fake out an artificial drop:
window.htmlLoader.addEventListener(window.runtime.flash.events.NativeDragEvent.NATIVE_DRAG _START, dojo.hitch(this, function(evt) {
// evt.dataTransfer here is undefined ... cannot use setDragImage() function to style the avatar which appears beside the user's mouse
window.htmlLoader.addEventListener(window.runtime.flash.events.NativeDragEvent.NATIVE_DRAG _ENTER, dojo.hitch(this, function(evt) {
// thought that this would force the drop, but no dice
// air.NativeDragManager.acceptDragDrop(window.htmlLoader);
window.htmlLoader.addEventListener(window.runtime.flash.events.NativeDragEvent.NATIVE_DRAG _UPDATE, function(evt) {
if(aCertainConditionIsMet()) {
// dispatch a drop event which will be caught in the NATIVE_DRAG_ENTER callback above
window.htmlLoader.dispatchEvent(new window.runtime.flash.events.NativeDragEvent(window.runtime.flash.events.NativeDragEvent.N ATIVE_DRAG_DROP));
I get the feeling from the code above that I'm trying to force this functionality - is what I'm trying to achieve advisable/possible with AIR? -
HTML component scrolling (verticalScrollPosition/scrollv)
I'm trying to use an HTML component to do some of the rendering in my application and I need to be able to scroll the content to the bottom as things get added to it. It looks like I should be able to use the verticalScrollPosition property of the HTML component (which should correctly set the scrollV property on the htmlLoader). However, when I do this, I see the scrollbar jump to the bottom go immediately back to the top.
I'm logging the scrollV value of the htmlLoader when I do this and it looks like it's being set correctly (contentHeight - htmlLoader.height). On successive calls to set the verticalScrollPosition property, I can see that scrollV had been set correctly.
Anyone know what might be going wrong or encountered this problem before?So, I think I figured this one out. I was setting the htmlText property of my HTML component when I wanted to add content. However, doing this causes the whole thing to redraw and scroll to the top. Unfortunately, this meant that I had to wait until getting an HTML_RENDER event before I could rescroll to the bottom and that sometimes even then it didn't work.
Instead, I now do everything using functions on the HTML DOM through ActionScript. So, instead of saying:
htmlText += "<p>blah<p>"
I am now using:
var p:* = html.htmlLoader.window.document.createElement('p');
p.innerHTML = 'blah';
html.htmlLoader.window.document.body.appendChild(p);
This keeps the existing html content intact and allows scrolling to work much better. It's just a little more lengthy in terms of amount of code. -
Hey all,
Is it possible to ditch the standard scroller on the right hand side of StageWebView and have a touch scroll instead?
I'm developing an App for a Windows 8 tablet and having the scroll bars seems a little strange when the rest of the OS and App has nice touch scrolls..
ThanksIf this is Windows 8 only, you might as well use the HTMLLoader because that is basically what StageWebView does on desktop computers per the ASDOCs:
"On desktop computers (in the desktop and extended desktop profiles), the StageWebView class uses the system web control provided by the Flash Player plugin. The features available and rendering appearance are the same as those of the HTMLLoader class (without the close integration and script bridging between ActionScript and JavaScript provided by an HTMLLoader instance).".
If you take a look at this method of the HTMLLoader object, you can create a new NativeWindow within your AIR app that contains an HTMLLoader object. The 3rd parameter is a boolean on whether to show or hide the scroll bars. From what I can tell, there isnt any other way with the provided API. If you don't want to go through the hassle of creating a new NativeWindow in your app, you could possibly have the HTMLLoader's width set to be the size of the flash.display.Screen.mainScreen.bounds.width + X, where X is a known width of the Windows 8 scroll bar within the HTMLLoader and that would, in theory, push the scroll bar off the side of the screen so you can't see it. You might also be able to to try to use flash.html.HTMLLoader.window property to access "The global JavaScript object for the content loaded into the HTML control". With that object, you could use JavaScript code to try and hide the scrollbars as well. So there are a few options available to you. Im not sure how well the last one will work but seems like it could be worth trying. If the app can be on Windows 8 computers that don't have touch capability, you may want to check to see if flash.ui.Multitouch.supportsTouchEvents returns true or false to determine if you want to hide the scrollbars or not.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/html/HTMLLoader.h tml#createRootWindow() -
Weird error when calling AS function to switch state from embedded HTML page
Hey everyone,
I'm developing an application that has 5 states in it. The
welcome state is set by default. I wrote a function called
changeState that looks like this:
internal function changeState(sState:String):void
currentState = sState;
Now, inside the registration state, there is an mx:HTML
component named htmlReg with the following attribute:
htmlDOMInitialize="htmlReg.htmlLoader.window.changeState =
changeState;"
Inside the plain handcoded HTML web page that's loaded,
there's a button that looks like this:
<button onClick="changeState('Welcome')">Back to
Welcome</button>
The idea being, when the user clicks the HTML button, it
calls the AS function changeState('Welcome') and the user gets
taken back to the welcome screen.
The good news is that when I click this button, it works
fine, and I'm taken back to the welcome state.
The bad news is that when I then switch to another state
(using an mx:Button in the welcome state), I get the following
error:
TypeError: Error #1009: Cannot access a property or method of
a null object reference.
at flash.html::HTMLLoader/onFocusOut()
I'm having trouble figuring out why this is happening, and
what to do about it.
Two additional data points:
1) If I add an mx:Button to the registration state with a
click="changeState('Welcome')" handler, it works as expected and I
don't get an error. I only get this error when clicking the HTML
button, which calls the same function in the same way.
2) If I move the mx:HTML component out of the registration
state and into the main application, I don't get this error any
more (and the HTML state change button still works as expected).
Anybody have any clues or ideas as to what might be
happening? Or ideas as to what I might try to collect more data
points? Or even workarounds to accomplish the same task in a
different way?
Thanks in advance.Probably what is happening is that when you change states,
the HTML control is removed from the stage. However, the HTMLLoader
(which is wrapped by mx:HTML) does seem to know that it has been
removed, and losing focus, it's internal handler for the focusOut
event access some property that requires it to be on the stage --
hence the null object reference.
You should report this bug at
http://www.adobe.com/go/wish
and provide a sample that demonstrates the issue.
A workaround might be to change the focus to another object
with stage.assignFocus() before you change states. -
Prevent user interaction using mx:html
Hi,
Is there a way to prevent the user interaction when html is loaded inside a panel. The page should not get redirected when the user clicks on any links in the page.The easiest way to do this is by loading the content inside an iframe, and putting a fixed positioned div on top of it, like in "<div id="overlay" style="position: fixed; top:0; left:0; width: 600; height:400"></div>" (you can calculate the size dynamically, of course).
When you want to disable all interactions, you simply set the div's visibility to "visible" (loader.htmlLoader.window.document.getElementById("overlay").style.visibility = "visible";)
When you want to enable the interactions again, you simply hide the div (loader.htmlLoader.window.document.getElementById("overlay").style.visibility = "hidden";) -
HTMLLoader, Flash, Transparent Windows
Try to create a transparent adobe air window, put an
HTMLLoader in it, and try to display a webpage that has flash.
Flash will not show.
Is there a work around for this problem?
does adobe plan in the future to fix this problem?
Pls let me know if you guys know. thankx.A bug is already filed:
http://bugs.adobe.com/jira/browse/SDK-15033
They say they have notified the adobe air team.
HTH. -
New Window, HTMLLoader.loadString image problem
Hello,
I woudl like to load an image into a new window which I create, the image is accessable via the main application e.g. app:/images/notificationbg.png After creating the new window, the text and everything appears fine, but the image fails to load, I have tried not making it a background image and used <img src="images/notificationbg.png"> just to test it but still no luck.
////////////////////// Create Window /////////////////////
var options = new air.NativeWindowInitOptions();
options.transparent = false;
//transparent windows must have the systemChrome set to none
options.systemChrome = air.NativeWindowSystemChrome.NONE;
options.type = air.NativeWindowType.LIGHTWEIGHT;
this.htmlLoader = air.HTMLLoader.createRootWindow(
false, //hidden
options,
false, //no scrollbars
bounds
////////////////////// Load the Image /////////////////////
this.htmlLoader.loadString("<html>" +
"<head><style type=\"text/css\">#notify { background: url('images/notificationbg.png') no-repeat; }</style></head>" +
"<body><div id=\"notify\" style=\"width: 200px; height: 62px; padding-top: 34px; padding-left: 45px;\">"+this.template+"</div></body>"+ "</html>");
Any help would be much appreciated!
Thanks,
AndrewAdd the following code before you call loadString():
htmlLoader.placeLoadStringContentInApplicationSandbox = true;
By default, content added via loadString() is not in the application security sandbox (and it cannot load images from the application directory). By setting this property to true, loadString() content is placed in the application security sandbox.
For more information, see the property's description in the language reference:
http://help.adobe.com/en_US/AIR/1.5/jslr/flash/html/HTMLLoader.html#placeLoadStringContent InApplicationSandbox -
HTMLLoader, main application window and scrollbars
If I instantiate HTMLLoader with "new HTMLLoader.createRootWindow()," scrollbars show up correctly when text overflows the set width and height. I can add it to the stage, but I'm still left with an empty popped up native window
If I instantiate HTMLLoader with simply "new HTMLLoader()," you can add it to the stage, but it doesn't include scrollbars when the window overflows with text.
What I want to do is incredibly simple - create a new HTMLLoader instance, have as part of my main application's stage, and get the benefit of the built-in scrollbars. Why is that so difficult?OK - my problem with the HTML Control is I can't seem to add it to a child custom class.
i.e. - I have my main Air app and a custom class extending UIComponent. I add the custom class to the stage in the main app, and in the custom class, add an HTML Control. I'm also adding a different HTML Control to the main app.
Only the HTML in the main app actually shows up. No errors given. What am I missing here?
Main Air app mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.HTML;
var _myComp:Comp;
private function init():void {
_myComp = new Comp();
_myComp.init();
_myComp.x = 200;
_myComp.y = 200;
addChild(_myComp)
var html:HTML = new HTML();
html.htmlText = "Text on main application window"
addChild(html);
]]>
</mx:Script>
</mx:WindowedApplication>
Comp Class:
package {
import flash.display.Shape;
import mx.controls.HTML;
import mx.core.UIComponent;
public class Comp extends UIComponent {
public function Comp() {
public function init():void {
var shape:Shape = new Shape()
shape.graphics.beginFill(0,1)
shape.graphics.drawRect(0,0,200,400);
shape.graphics.endFill();
addChild(shape)
var html:HTML = new HTML();
html.htmlText = "Text Inside child component";
html.x = 200
this.addChild(html);
trace(html.htmlText) -
Cannot get window object in HtmlLoader
below is my code, it simple, but i don't know why i cannot
visit the html.window. i got result TypeError: No default value in
the introspector widow.
var url = new air.URLRequest("
http://www.google.com/");
var options = new air.NativeWindowInitOptions();
var windowBounds = new air.Rectangle(200,250,300,400);
options.systemChrome = "standard"; options.type = "normal";
var html = air.HTMLLoader.createRootWindow(true, options,
true, windowBounds);
html.load(url);
html.addEventListener(air.Event.COMPLETE,
function(event){air.Introspector.Console.log(html.window);});Try like this:
var url:URLRequest = new URLRequest("
http://www.google.com/");
var options:NativeWindowInitOptions = new
NativeWindowInitOptions();
var windowBounds:Rectangle = new Rectangle(200,250,300,400);
options.systemChrome = "standard"; options.type = "normal";
var html:HTMLLoader = HTMLLoader.createRootWindow(true,
options, true, windowBounds);
html.load(url);
html.addEventListener(Event.COMPLETE,
function(e:Event):void{trace(ObjectUtil.toString(e.target.window));});
Maybe you are looking for
-
Can i use my ipod as hard-drive with pc and mac??
hi ive been using new classic ipod with pc for a while. now i have a new macbook. can i use the ipod as a hard drive to transfer files to macbook?? like say if i download some software onto pc, i put that onto ipod, and then transfer to macbook via i
-
How do I get my gmail account to show up in my emil accounts under mail
I've now opened up a new gmail account since I'm going to possibly change Internet service providers. I've had my current provider for a LONG Time and I'm not looking forward to making changes, but money talks. When open up my mail now all my account
-
ITunes 7.0.2 freezes with new iPod 60GB
Hello everyone Everytime I connect my iPod to my Powerbook G4 laptop, iTunes decides to freeze. This never happened to me before. I connect my Nano all the time and no problem. Is there a way to fix this little problem? I checked some sites where use
-
Windows 7 and Onedrive - Can files be accessd directly without sync
My client is using Office 365 with Onedrive for business. We have mostly Windows 7 machines. I installed the Onedrive app on a Win 7 pro machine. Is there a way to share files directly, not offline, so syncing does not occur and save files locally?
-
Please ignore, posted in wrong section and can't delete.
Intended for Windows Desktop section. Skype crashes upon login and I get a "Skype has stopped working." message. It started after my Win7 computer got a BSOD while skyping someone. First time I uninstalled Skype and reinstalled which got it working.