FlashBuilder 4.6 mx.controls.Button missing? - actionscript-3

Im writing my first application in Flash Builder but I have much experience with Flash. I and trying to use the button class in flash builder but my error says "the imports button could not be found". I tried importing flash.display, flash.ui to see it Button was hidden somewhere else. The point is to dynamically load buttons and their labels via xml. Any help is appreciated. Thanks!
<fx:Script>
<![CDATA[
import flash.events.*;
import mx.controls.Button;
private function doAdd(e:Event):void {
var buttonList:XMLList = new XMLList(cutsXML.cut.#name);
for(var i=0; i<buttonList.length(); i++){
var btn:Button = new Button();
btn.label = buttonList[i];
buttonBox.addElement(btn);
}
}
]]>
</fx:Script>
<s:VGroup left="30" right="30" top="50" bottom="30" id="buttonBox">
</s:VGroup>

Im guessing you are creating a mobile app? As mx components are not available (by default) in mobile apps.
You can either use the spark button - spark.components.Button - or manually include the mx components by importing the mx.swc library (found within flex sdk)

Add the mx.swc to your project, that'll do.
In Flash Builder 6.0, do the following:
Right-click on the project in the Package Explorer perspective
Properties...
Flex Build Path (in the left side navigation pane)
Click Add SWC...
Find the mx.swc on your box. On OSX at the time of this writing it was:
/Applications/Adobe Flash Builder 4.6/sdks/4.6.0/frameworks/libs/mx/mx.swc
Click OK
Rebuild your project

Related

Flash compiled with Flex SDK very big file size

I had a simple flash video player I was compiling using Adobe Flash Builder , but now I am compiling it using Flex SDK 4.6 . Flash filesize was 20KB when I was compiling with FB . Now it's 280KB . I know that it adds some swc files to swf build , I have disabled debug etc instructions provided here http://livedocs.adobe.com/flex/3/html/help.html?content=performance_06.html . Is it possible to somehow convert fla components without using mxml ?
Here is my mxml code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application backgroundColor="#000000" xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" minWidth="320" minHeight="240" creationComplete="initApp()">
<fx:Script>
public function initApp():void{
var p = new video_player(uic);
}
</fx:Script>
<mx:UIComponent id="uic" />
</mx:Application>
video_player.as
....Import statements
public class video_player{
private var uic:UIComponent
var fullScreen:Image;
var rtmpApplication:String;
var streamName:String;
public function video_player(_uic:UIComponent) {
uic=_uic;
if (FlexGlobals.topLevelApplication.parameters.hasOwnProperty("applicationName")) {
rtmpApplication=FlexGlobals.topLevelApplication.parameters.applicationName;
}
if (FlexGlobals.topLevelApplication.parameters.hasOwnProperty("streamName")) {
streamName=FlexGlobals.topLevelApplication.parameters.streamName;
}
vPlayer=new Video(playerwidth,playerheight);
uic.addChild(vPlayer);
init();
}
public function init(){
//add fullscreen image in flash top right , and event handler
//Code to connect to live application and play video using NetConnection and NetStream
}
}
Is there any way around this?
Also I have added option -static-link-runtime-shared-libraries=true so it wont download anything runtime . Without that flash size is 49KB
By setting the above option, you have told the compiler to include all of the Flex framework classes (that are used by your application) in the application SWF. So your SWF grows from 49KB to 280KB.
This is the "RSL" thing (runtime shared library) that #Reboog711 and I were talking about. If you use the Flex RSL's, then all of that Flex framework code is not included in your application SWF. The Flex framework RSL's are signed by Adobe and can be cached by the Flash Player. So using them is always preferable. (Note: I'm assuming this all still works with Apache Flex)
Finally, I wish to reiterate that in Flash Builder there are two basic kind of projects you can create: Flex project, Actionscript project. I'm ignoring the mobile options, but the same applies to them:
An Actionscript project will, in general, result in a smaller SWF because you are not relying on any of the Flex framework classes. It sounds like you could make your video player app even smaller (closer to the 20KB size you originally had) if you were to create an Actionscript project.

How to make a slider using only as3

I am trying to make a slider in flash builder not using the Flash Professional API, but i dont know how to do it. Is there a class I could call like var sider:Slider?
Please someone help.
You have to add a slider to your library first. Go to window, then components and drag a slider in to your library.
You can create a new slider in code by creating a slider-object.
import fl.controls.Slider;
var sliderObj:Slider = new Slider();
addChild(sliderObj);
You need to go to this url :
http://apdevblog.com/update-using-flvideo-package-w-eclipse-and-fdt3/
Download the fl_package.swc on that page and add that .swc to your flash builder project.
You can add the swc via the Flash Builder menu system like this :
Project/Properties/Actionscript Build Path -- > click the Add SWC button and browse to the location of the fl_package.swc to add it.
Now you can use the Slider class by first adding this line to your imports wherever you want to us it :
import fl.controls.Slider
and then you can create an instance in your code and add it to the stage like this :
var mySlider:Slider = new Slider();
addChild(mySlider);

How to create an Alert Dialog in Actionscript 3 without the Flex Framework in a standalone AIR application designed to run on Windows

I've got a project, written in Actionscript 3, built using Flash CS5. In it, there are sections that require a microphone to be plugged in and the programmer who preceded me notified the user of the lack of microphone by throwing an Error. This causes the program to stop running, a behavior which in undesirable.
The question: How to create a popup alert dialog in as pure as possible Actionscript. I've found the Alert class in mx.controls, but I can't find a way to add it to the project. I found the Yahoo AlertManager class, but couldn't get it to work properly and it looks like the framework around it is larger than I need.
This is deployed on touchscreens as a standalone application on a Windows 7 Environment using AIR 2.5, Flash CS5, Actionscript 3.0. I use FlashDevelop as the AS editor.
You'll have to make your own alert box, either by making NativeWindow instance and editing it, or (what I would recommend) making your own custom class that extends NativeWindow.
This is a simple generalized version of one that I made for one of my apps:
package
{
import flash.display.*;
import flash.geom.*;
public class AlertWindow extends NativeWindow
{
public function AlertWindow(owningWindow:NativeWindow, windowTitle:String)
{
var initOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
initOptions.maximizable = false;
initOptions.minimizable = false;
initOptions.resizable = false;
initOptions.owner = owningWindow;
initOptions.type = NativeWindowType.UTILITY;
super(initOptions);
title = windowTitle;
alwaysInFront = true;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
bounds = new Rectangle(owner.x + owner.width - (owner.width / 2) - 125, owner.y + owner.height - (owner.height / 2) - 75, 250, 150);
}
}
}
I whipped it up fairly quickly so it might not be as clean or efficient as it could be but it should be a good base to start on. Obviously you can add stuff like messages, buttons, event listeners, and anything else.
If you don't understand all of the code you should check out the NativeWindow and NativeWindowInitOptions documentation.

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>