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>
Related
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
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
Our project is a MMORPG, using scaleform to render UI. Now we use Flash CS5 to create UI panels with scaleform CLIK. With the development of this project, we encountered some problems:
CLIK is not skinned, we have to create separate symbols for each component with different disappearance, so we have PushButton1, PushButton2, RadioButton1, RadioButton2...
Flash CS5 is not a What You See is What You Get tool. For instance, we have a shared component named Window, it has a close button as it's child. In a fla, we first pull a Window on the stage, and modify its size, the close button will be scaled in the stage.
We can constrain the close button in as code, but artists have to see the right result in Gfx Player on runtime.
We have some common components fla like common_button.fla with most of button components in it. Common components are runtime shared in different fla. In a UI fla (e.g. friendpanel.fla), when we need a common component, we copy it from common_xxx.fla and paste it in the new fla library. If a panel is complex, it's library will be confused and not easily managed. If the common one is not satisfying requirement, we will double-click the pasted component and modify it in the local fla, and this caused more resource management troubles.
So I consider if we should create a skinned UI component lib and an UI editor to handle this problems. Does any one has similar experience?
These are common workflow problems reported by many Flash IDE users unfortunately. Certainly, creating your own tool to solve these problems is a good option, but a costly one. The Scaleform team is investigating possible solutions to these types of issues for future versions of the SDK. In the meantime, there's not much that can be done to remedy these issues that I am aware of.
Does anyone know of a decent guide to create a UI without MXML?
I royally dislike mxml for programming and would like to go any other way possible. (Pure Actionscript or Flash Professional for UI)
You can use Flex and never write any MXML. However, you may find that becomes counter productive. I create views/skins declaratively in MXML and do everything else in Actionscript.
Creating views, populating them with child objects, adding listeners, setting styles, all of this is done in a few simple lines of MXML. Doing the same tasks with Actionscript statements means a lot more typing. The MXML code is more concise, and that gives it a lot more clarity/maintainability in my opinion:
MXML:
<s:Group width="100%">
<s:Button label="button" click="onButtonClick()" paddingTop="0"/>
</s:Group>
AS3:
var g:Group = new Group();
g.percentWidth = 100;
var b:Button = new Buton();
b.label = "button";
b.addEventListener(MouseEvent.CLICK, onButtonClick);
b.setStyle("paddingTop", 0);
g.addChild(b);
I often create custom components (that I re-use in app views) in pure AS3. I implement the Flex life cycle methods, and then composite these components into an MXML view.
I do prefer to write everything in pure Actionscript. The one place I will not do it, however, is in creating views/skins for my applications. I think it's a fair trade off.
You can use Flash Builder to edit the Actionscript part of a Flash Pro project. There's a huge discussion about techniques with example files and everything here.
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?