getting web data in flash builder mobile - actionscript-3

I'm making the change from Python to flash builder 4.6 as it seems easier for mobile applications.
My question is this, in Python I would use beautiful soup to get the source code of a web page, but after days of google typing the same question in a million ways i cant seem to find an alternative in flash builder.
Is there a way? I want to save the source of a web page to a string and extract bits from it based on search criteria.

I don't know there are some scraping libraries for AS3.
But anyway you can get the web page data by using HTTPService.
ActionScript
private function btnClick(): void{
hts.url="http://www.foobar.com/foo";
hts.send();
// if you want to pass parameters, use below.
//hts.send({
// "id": "abcde",
// "pages": "2"
//});
}
protected function hts_resultHandler(event:ResultEvent):void{
trace(hts.lastResult.toString());
}
MXML
<fx:Declarations>
<s:HTTPService id="hts" method="GET" resultFormat="text" result="hts_resultHandler(event)"/>
</fx:Declarations>
<s:Button x="20" y="20" label="Get data" click="btnClick()"/>

Related

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

photoshop activeDocument

I am writing a Photoshop plug in in ActionScript 3.
I am having a very confusing and frustrating issue with app.activeDocument. My code works perfectly with Photoshop for Windows but on a Mac I get the "General Photoshop errooccurreded. This Functionality may not be available in this version of Photoshop." error.
To try and get to the root of the issue, I wrote a class just to get the document reference and called it from a test panel. The class call worked perfectly. I then included the same class in my main panel project and it breaks.
This is my class: -
package DocRefGetter
{
import com.adobe.csawlib.photoshop.Photoshop;
import com.adobe.photoshop.*;
public class DocRefPhotoshop
{
public static function getDocRef():Document
{
var app:Application = Photoshop.app;
var thisDoc:Document = app.activeDocument;
//var thisDoc:Document = app.documents.index(0); //Tried this method too
return thisDoc;
}
}
}
For the purpose of posting here, I have simplified things a little, i.e. I have removed things like the "try, catch" statements but essentially this is the code that does not work in the context of my panel. I also tried the equivalent call to JSX code with exactly the same result, worked perfectly for Windows, worked in a test panel on Mac, would not work in my main project on Mac.
As I said, inside a test, this works perfectly. Here is the test mxml code: -
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false">
<mx:Script>
<![CDATA[
import DocRefGetter.DocRefPhotoshop;
import com.adobe.photoshop.Document;
[Bindable]
private var hostName:String = HostObject.mainExtension;
protected function button1_clickHandler(event:MouseEvent):void
{
var thisDocRef:Document = DocRefPhotoshop.getDocRef();
testLabel.text = String(thisDocRef);
}
]]>
</mx:Script>
<mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Button label="Run PS code" click="button1_clickHandler(event)" />
<mx:Label id="testLabel" width="182" text="Label"/>
</mx:VBox>
</mx:Application>
I can't post the main application that it isn't working in as it is extremely large and complicated so what I am asking is has anyone come across a situation before where somehow something is conflicting with this type of document reference? I have been trying to resolve this for over a week now. I have tried many different solutions but nothing has worked. Mac Photoshop just simply doesn't want to see the open document.
Any suggestions are welcome but I am hoping most that someone has come across this exact situation before and has a precise solution.
Many thanks for taking the trouble to take a look at this.
so what I am asking is has anyone come across a situation before where somehow something is conflicting with this type of document reference?
Use one of the following checks:
Is docref null?
Is the document loaded asynchronously?
Is the document large enough to warrant a timeout?
References
Scripting Photoshop: Working with the document model
Adobe Photoshop CS5 Scripting Guide (pdf)
JavaScript development toolkit | Download Adobe ExtendScript Toolkit CC

Flash Builder 4.6 Interface Programming

I'm having a very difficult time finding many resources available for Flash Builder 4.6 geared towards desktop application programming.
I'm trying to accomplish a simple (or at least I think simple) task. I have an application, and in the application is a button. When the user clicks the button, I want a new window to load, but not in the current window as a child; as a completely separate window.
I've managed to accomplish this once, but the code I was using gave a warning (from Adobe Flash Builder 4.6) that told me that it is best practice to use an "interface" as the new window is now a child of the window that opened it. (I have since lost this code as I've been trying other things, like ModuleLoader).
Basically my question is, can someone please provide an example of how to properly implement an interface in the way that 2 separate windowedapplications can be loaded and they can communicate with each other through events?
And as a bonus, if anyone can point me in the direction of a good resource, I'd appreciate that also (book or site). :) I have a Flex 4 book that I've read, and it has helped a lot with my understanding of the basic things, but is not geared towards AIR desktop programming (and had no mentions of interface).
Thank you for your time.
How I solved this problem. This article helped: Dual Monitor Support in Flex Application.
After you have created your project in Adobe Flash Builder 4.6, go to File > New > MXML Component. Type in the details as you see fit best for your application, but under "Based on" field, put "spark.components.Window". Click "Finish" when you are done with all the details.
In your main application, use the following code to pull up the new Window Component you just created into a separate Window. For the purpose of this code, I will assume that your new window is located under "assets.components" and is called CompNewWindow. Replace these details with your own.
<s:Button x="0" y="0" label="Button" click="_loadNewWindow(event)" />
<fx:Script>
<![CDATA[
import assets.components.CompNewWindow;
private var myNewWindow:CompNewWindow;
private function _loadNewWindow(event:MouseEvent):void
{
if (!myNewWindow) {
myNewWindow = new CompNewWindow();
myNewWindow.addEventListener(Event.CLOSE, _onNewWindowClose);
myNewWindow.open();
}
}
private function _onNewWindowClose(event:Event):void
{
myNewWindow.removeEventListener(Event.CLOSE, _onNewWindowClose);
myNewWindow = null;
}
]]>
</fx:Script>

Handle ExternalInterface Call, comming from local swf file, in Adobe Air 3.4 Actionscript 3 application

So We got a playlist with various swf files, some old as2 animations, some newer.
We download them to a local folder, and can play them fullscreen. all with one AIR (actionscript) application. Now we know that in the newer files there are ExternalInterface.Call(some arguments) calls. And we need to handle them in the hosting AIR application. So far we have a class inherrited from MovieClip, with the following constructor:
public function FlashClip()
{
ExternalInterface.addCallback("FlashPlayerControl1FlashCall",FlashPlayerControl1FlashCall);
}
when we run the application whe got the following error:
Error: Error #2067: The ExternalInterface is not available in this container. ExternalInterface requires Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime.
at Error$/throwError()
at flash.external::ExternalInterface$/addCallback()
at Video::FlashClip()[C:\Users\Daan\Adobe Flash Builder 4.6\TINS-v2-1\TINSV2\src\Video\FlashClip.as:12]
at Video::FlashPlayer/BestandOpend()[C:\Users\Daan\Adobe Flash Builder 4.6\TINS-v2-1\TINSV2\src\Video\FlashPlayer.as:43]
On the following line:(FlashPlayer.as:43)
var clip:FlashClip = new FlashClip();
So, My question is this. Is what we are trying to do even possible. Or do we need tot embed a javascript container in the actionscript AIR application? Or does anyone know how we are going to get this to work?? Note: We cannot alter the existing swf files. we dont even have the original .fla's
The documentation says what you are trying to do is not possible:
In Adobe AIR, the ExternalInterface class can be used to communicate
between JavaScript in an HTML page loaded in the HTMLLoader control
and ActionScript in SWF content embedded in that HTML page.
For ExternalInterface to work, it needs to communicate w/a Javascript "layer" that the browsers provide. You won't get this functionality in AIR, unless you load an HTML page that has your SWF content embedded in it.
I've linked to the docs for HTMLLoader which would allow you to do this.
[Edit]
Appending a simple AIR app (note it's Flex 3.6, sorry that's what my client uses) that loads a web page, in case it helps.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="800" height="600"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
private function onCreationComplete():void
{
var loader:HTMLLoader = new HTMLLoader();
var request:URLRequest = new URLRequest("http://www.adobe.com");
loader.width = 800;
loader.height = 600;
loader.load(request);
var uic:UIComponent = new UIComponent();
uic.addChild(loader);
addChild(uic);
}
]]>
</mx:Script>
</mx:WindowedApplication>

learning flex 4 facing problem with namespaces

I am trying to learn flex4 from adobe document and I am very confused while using three namespaces.. there is no way i can keep track of when to use what often ending up using fx inside mx or s or similarly making some stupid goofed up combinations of {fx,mx,s}.
Adobe document is huge and i am looking for some good starting point for learning flex .
Your question is quite large; however, some basic explanation about the 3 namespaces you've cited:
<fx> tags are typically programmatic functionality and not visual display objects. You'd use it for declaring a script block in a MXML document or defining variables in a declarative way.
<fx:Script>
<![CDATA[
[Bindable]
public var myVariable:String = "Hello, World!";
]]>
</fx:Script>
<fx:Declarations>
<fx:Object id="variableName"
property1="myCustomProperty"
property2="anotherCustomProperty" />
</fx:Declarations>
When declaring visual elements and UIComponents on the display list, you'll typically want Spark architecture; therefore, you'd use the Spark namespace.
<s:Group />
MX architecture is important, but is generally deprecated by Spark. If a component is available as Spark, you should use that implementation.
<mx:Box />
All are just packages of the framework, and really no difference than importing packages in ActionScript. Your custom components will use their package name as a namespace, or you declare a namespace for your Flex MXML library.
If you're using an IDE like Flash Builder, you usually don't have to worry about the namespaces.
In an MXML file, enter the start tag (ie: <), skip the namespace and start typing the class you're after. In the above examples, I'd hit <s for "script" and the intellisense will show you completion options that will insert the namespace for you.
If the auto completion options do not appear, hit [ctrl]+[space-bar].
Let Flash Builder help with namespaces by completing them for you.
Probably doesn't go far to helping you out, but hopefully this helps a little.
Have you tried http://www.adobe.com/devnet/flex.html especially Getting Started part?