StageWebView Lack on URLs with target="_blank" - actionscript-3

is there any solution on StageWebView.loadURL(), how I can handle URLs in HTML Pages which have target="_blank"?
It's a mobile Android App. (TabbedViewApplication)
Hope someone can help.
Thx

One option is StageWebViewBridge.
StageWebViewBridge is an extended version of flash.media.StageWebView.
Extends loadString method with AS3 - JS communication.
-Extends Bitmap class, you can modify his x,y,alpha,rotation,visible, etc ( Version 1 Beta )
-Communicates Actionscript with Javascript.
-Communicates Javascript with Actionscript.
-Load local files and resources in a easy way.
-Extends loadString method with AS3 - JS communication.
-Extends loadString method to load local resources.
-Lets you take an SnapShot to use as the bitmapData of the bitmap.
StageWebViewBridge source: https://code.google.com/p/stagewebviewbridge/

I never worked with the StageWebView but I know it's really limited. When using an HTMLLoader, you can set a custom HTMLHost instance that specifies to use current HTMLLoader when opening to _blank. However, I don't think it's possible with StageWebView.
public class MyHTMLHost extends HTMLHost
{
public function MyHTMLHost(defaultBehaviors:Boolean=false)
{
super(defaultBehaviors);
}
override public function createWindow(windowCreateOptions:HTMLWindowCreateOptions):HTMLLoader
{
// all JS calls and HREFs to open a new window should use the existing window
return htmlLoader;
}
}

OK, so the only solution for this problem i could found is to load the page (containing the links) as String with the URLLoader and replace its specified parts. Finally loading it via StageWebView.loadString() method.
Problems occur when the Site is dynamic and contains JavaScript. I had also replace some relative links with absolute pathes.
That's it... but I really hope that adobe makes it possible to load those "_blank" links with the StageWebView.loadURL() method.

If you want to capture when a user clicks on a link inside your StageWebView add an an event listener for location changing event (LocationChangeEvent).
This LocationChangeEvent will include the URL they are going to and target. Then you can prevent the URL from loading, let it continue (by doing nothing) or handle it any other way including loading another URL.
If you want to load another URL first stop the loading with stageWebView.stop(). You should also call event.preventDefault(). You can then attempt to
Note: There is another event called locationChange that may be helpful.

As it was declared as an official bug, adobe QA Owner Sanjay C. added a comment: "Able to reproduce the issue with the attached project. Sending to IRB."
So, hope the next Build will come up with the fix wit it.
Best regards

Related

Play one of a set of audio clips randomly?

So I'm trying to setup a web-page where when you open it, it will play a random piece of music, and when that one finishes, it will play another directly after so you get a constant stream of music, but not in the same order every time. If this goes outside the bounds of HTML and I'm looking at for instance JavaScipt than that's fine.
I know this is probably a rather easy solution, but I'm new to HTML and trying to understand it better.
Thanks in advance if I don't get back to you soon!
This is best solved using JavaScript, which is used to add behavior to a website. HTML is primarily used to structure your site.
We can get a collection of all audio elements with the querySelectorAll function. Then we find a random element with the next line and call the play method.
var audio = document.querySelectorAll("audio");
function playRandom() {
audio[Math.floor(Math.random() * audio.length)].play()
}();
For the second part of your question, you would want to listen for the ended event. Inside the event listener function, you would then call the playRandom() function.
audio.addEventListener("ended", function() {
playRandom();
});

Populate web form using Flex/AS3

I need to load a page within a Flex based AIR desktop app, then populate certain fields on the page. I am trying to use an HTML control to load the page, but I can't figure out how to interact with DOM elements. Is there another way to do this?
Any pointers or help would be most appreciated!
Thanks,
rw
I've had success with passing parameters from the Flex / Air app as url variables then in the HTML page (loaded with stagewebview in as3) retrieve those individual data elements using a server side technology (php, asp, etc.) then use javascript to take those values and set them as values for specific fields on the page.
I've used it both ways so for instance the html page can invoke url calls that are monitored by the flex / air app and in as3 I can watch for specific url variables (i.e. when url change is detected) that can trigger any type of action I want to happen in as3, and in the other direction the flex / air app can send data and commands/triggers to the HTML page as well.
AS3 StageWebViewBridge looks really powerful, but I havent pushed myself to get to all the benefits of it yet, I've just used standard StageWebView to suit my needs. Good luck with your project and let me know if you have any other questions with this.
Thanks for your answers - sorry for the late response, I didn't get notified via email, which I am sure is my bad....
So, I have gotten this working. Specifically, I am opening a page, populating fields in a form, submitting the form, then collecting the results. This needs much fleshing out, but the basic concept works:
<fx:Script>
<![CDATA[
private function init(e:Event):void
{
htmlCont.addEventListener(Event.COMPLETE, htmlComplete);
htmlCont.location="https://www.targetsite.com/pagewithform.html"
}
private function htmlComplete(event:Event):void
{
htmlCont.domWindow.document.getElementById("fieldToFill01").value = textInput.text;
htmlCont.removeEventListener(Event.COMPLETE, htmlComplete);
//After new page is loaded, trigger function to get data
htmlCont.addEventListener(Event.COMPLETE, getResult);
//Use htmlElement.htmlLoader to access DOM click() function.
htmlCont.htmlLoader.window.document.getElementById("ButtonID").click();
}
private function getResult(e:Event):void
{
//Getting all <p> tags for example
var returnedArray = htmlCont.htmlLoader.window.document.getElementsByTagName("p");
//Different grabs of the content of a <p> tag.
trace(returnedArray[0].innerHTML);
trace(returnedArray[0].innerText);
trace(returnedArray[0].textContent);
}
</fx:Script>
<!-- Inside your Application somewhere -->
<mx:HTML id="htmlCont" width="100%" height="100%" y="100"/>
Again, there is a lot more to be done with this, and I think I will have some regex questions soon as the formatting of my html target page leaves a lot to be desired!
Thanks for the input, sorry again for bad form in not responding.
rw

Actionscript works when tested in flash, but not on html page?

I am trying to create an ad for a website. When someone clicks on the ad, it is supposed to redirect them to a website, and register the click with google analytics.
I have done this with the following script:
import flash.external.ExternalInterface;
movieClip_3.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void {
trace("hi");
ExternalInterface.call("console.log", "test");
//ExternalInterface.call("_gaq._trackPageview", "/vpv/annoncer/[firmanavn.dk]");
navigateToURL(new URLRequest("http://www.google.com"), "_blank");
}
When i run this using preview->flash and i click on the surface, (where there is a big red square called movieClip_3) It opens the webpage. However when i try to publish as html, the big red square shows, but nothing happens on click. Not even console.log. I have tried setting allowscriptaccess = always but that does not change anything.
Can you guys help me? Any help is appreciated.
Security problems?
Developers should validate all URLs before passing them to this
function.
For local content running in a browser, calls to the navigateToURL()
method that specify a "javascript:" pseudo-protocol (via a URLRequest
object passed as the first parameter) are only permitted if the SWF
file and the containing web page (if there is one) are in the
local-trusted security sandbox. Some browsers do not support using the
javascript protocol with the navigateToURL() method. Instead, consider
using the call() method of the ExternalInterface API to invoke
JavaScript methods within the enclosing HTML page.
source: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/package.html#navigateToURL()
EDIT:
Since javascript is not permitted out of the sandbox, you can try with ExternalInterface:
ExternalInterface.call("javascript_functionname", "mypage.html");
In the parameters for publishing:
'allowScriptAccess', 'always',
You can only test this on your server not locally.
I'd suggest double checking the security settings (right click on flash container->Global Settings-> Advanced -> Trusted Location Settings). Also make sure your html file contains the javascript function you're trying to execute and look for blocked pop-up notifications in the browser. Maybe you just don't allow pop-ups to run.

deep linking from xml to open function in Actionscript

I have general text in CDATA in my xml which is pulling in content into Flash. This is working well and I am able to add images this way too. What I need though is to wrap that image in an tag which, when clicked on will fire off a function in my Actionscript 2 to launch a video.
Could someone please tell me how I would go about this? Is there a better way than the way I am thinking right now?
Thanks.
I recently did this in AS3 but I found the AS2 way.
Tested it:
function myFunc(arg:String):Void
{
trace ("You clicked me!Argument was "+arg);
}
myTextField.htmlText ='Click Me!';
You just use a href that is set to asfunction with a function name and something to pass along.
See:
http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary073.html
Just to give credit I found the initial code at: blog.activepoison.com/?p=25.

How to submit HTML and receive a bitmap?

I have an app that allows a user to use JQuery and Javascript to add images and position them in a div dynamically.
I would like to be able to submit the div with all the HTML to a WebService and receive back an image so we have a bitmap of the result of the end user's work.
I would prefer a solution in .Net as this is what I am most familiar with but am open to pretty much anything?
I would like to be able to submit the div with all the HTML to a WebService and receive back an image
Try http://browsershots.org!
Browsershots makes screenshots of your web design in different operating systems and browsers. It is a free open-source online web application providing developers a convenient way to test their website's browser compatibility in one place.
How about this. You load the html into a webbrowser control and then use the DrawToBitmap method. It doesn't show up on intellisense and this is probably not the best solution, but it works. Observe the DocumentCompleted event and add the following code:
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var bmp = new Bitmap(100, 100);
var rect = new Rectangle(webBrowser.Location.X, webBrowser.Location.Y, webBrowser.Width, webBrowser.Height);
webBrowser.DrawToBitmap(bmp, rect);
bmp.Save("test.jpg", ImageFormat.Jpeg);
}
You'll probably want to change the width and height of that bitmap object (do it in some smart way or something). Hope this helps.
EDIT: I see now that you are using a webservice for this, hence this solution probably won't work. I'll leave it here just for information's sake.
I was not able to figure out how to do this by submitting the html and receiving an image but I was able to create and ASHX handler that returns a png file based on this blog post
which was good enough for my scenario.
He uses CutyCapt to take a screen shot of an existing web page, write the image to a folder on the webserver and return it.