I got a strange problem.
Just using Flash Builder 4.5 and trying to use the Alert Popup for some user messages.
But when i use it, it told me :
"Importation not found" (with a ? logo)
Here is the code :
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
Sounds like you only included the Spark component set. Alert is only available in the MX component set. You need to include it as well in your project.
Right click on your project and choose Properties. Choose Flex Build Path from the left menu. You should see an option for Component set. Make sure to set it to MX + Spark (or MX only if you don't need Spark).
Is your project a Flex Mobile Project? If so the mx components are not available.... There are crazy ways around this, but its pretty difficult
Related
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7d9b.html#WS2db454920e96a9e51e63e3d11c0bf63b33-7fd3
Shows that mx:DateChooser control can be used in Flash Builder 4.6
I cannot find it in the codehint.
Please advise on how do I have a DateChooser control for use in Flash Builder 4.6
Update:
I really cannot find datechooser as seen in this screenshot.
http://cl.ly/EJKp
definitely I am using sdk4.6 for flex also shown here.
http://cl.ly/EJT0
make sure your script header contains things as following:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
If the Flash Builder project settings have the Flex Build Path configured with a component set of "Spark only" then MX components like <mx:DateChooser> will not be available. One way to fix this is to change the component set to "MX + Spark".
However, a trade-off of this approach is that the project will be able to compile a web application but not a mobile application. Another solution is to use a spark only DatePicker (actually, DateChooser and DateField). For example, here is an open source DateChooser component.
I wanna use Alert dialog box instead of skinnable container in my mobile application. I imported Alert class like:
import mx.controls.Alert;
and then I wrote the code below in my button click handler:
Alert.show("example","Error!",Alert.OK);
but when I wrote this code I got lots of errors whose codes are 1120 and 1172, e.g.,
"Access of undefined property ButtonSkin".
If I do not write this code, there is no problem. My application works fully.
Any idea about this error?
Thanks.
Alert is not available in a mobile project; how did you import it w/o a compiler error? [I suspect it was one of the many errors you said you got]
You'll probably want to look into using the PopUpManager to position a SkinnablePopUpContainer.
http://www.adobe.com/devnet/flex/articles/flex-mobile-development-tips-tricks-pt4.html
This would be an easier solution, It has skinned Alerts and normal Alerts which can be used in a mobile project.
I used this code on Flex 3.5 SDK with Flash Builder 4 inside a function that is being called on creationComplete of the MXML app.
var myButton:Button = new Button;
myButton.label = "test";
addChild(myButton);
Alert.show("Button Created");
It works fine however, when I use it on the same Flash Builder 4 only this time, under Flex 4.0 SDK, nothing's happening. The Alert.show() isn't even showing which means it doesn't even get to that point.
So my question is, what's wrong? Am I missing something?
P.S.
I need to be able to create / remove MXML components on the fly (while the app is running). This is just a test script and I'm failing miserably at achieving what I need.
In Spark you need to use addElement instead of addChild
var b:Button = new Button();
addElement(b);
I'm not sure why your alert isn't working :\
Usually you create the UI in MXML, but in some cases you do need to create UI elements on the fly, and as the other poster mentioned, addElement() is the key with Flex 4 Spark containers.
When adding components to MX containers (from Flex 3), you still use addChild() in Flex 4. You only need to use addElement() when adding to Spark containers.
Of course, Adobe recommends you use the Spark containers when there is a somewhat comparable MX container.
Its better that you do it in the flex way.
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private function alert():void
{
Alert.show("Button added to stage");
}
]]>
</fx:Script>
<s:Button id="myButton" label="test" addedToStage="alert()"/>
You can't add a button using mere addChild in flex. First you need to create an UIComponent and then add the button to the UIComponent. Its a bit different from the flash way.
I have used Flash to make skins, which I import and apply to Flex components.
But how can I create a component in Flash, with properties and methods. And make it able to be added to the displayList in a Flex app?
I installed the Flex component kit for flash. Created my component in flash (it extends MovieClip). Did Command->Convert to flex Component, did File->Published, which gave me a .swc, dropped the .sec file into my Flex project. Now when I create a new var the class "FlashFlexComponentTest" pops up in the new class hint box, so flex sees it. But afterwards I get the error:
Type was not found or was not a
compile-time constant: FlashFlexComponentTest
I feel like I must be missing a step?
Thanks!
UPDATE
I added the .swc via project build path -> add SWC.
I no longer have a compile-time error but I am getting a runtime error:
Type Coercion failed: cannot convert FlashFlexClassTest#9089129 to mx.core.IUIComponent
The base class for all flex components, UIComponent, allows you to add Sprites that don't implement the IUIComponent interface.
An example :
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="init();">
<mx:Script>
<![CDATA[
private function init():void
{
var component:FlashFlexClassTest = new FlashFlexClassTest();
container.addChild(component);
}
]]>
</mx:Script>
<mx:UIComponent id="container" width="100%" height="100%"/>
</mx:Application>
There's a good video tutorial on this at Linda.com by David something. I did a lot of this a year or so ago, and that was the best resource I found. Doesn't cover absolutely every possible angle, but does a great job of covering what you need to know.
I'm guessing there's just some small linkage detail that you're missing. The tutorial should get you straight, if that's the case. It was worth the $20, or whatever, for a monthly subscription for me.
Sorry, that's the best I can do... haven't built Flex components in Flash since last year.
basically there are step what need to do:
open Flash
drag a component you need to stage
right click on it in Library > Export to SWC
put this SWC in your Flash Builder libs folder
There is explanation by Jesse Warden http://jessewarden.com/2011/06/integrating-flash-components-with-flex-revisited.html
Cheers!
I created a new actionscript project using Flex Builder 3 and tried
to run the following file. I get this error :
Definitions: fl.controls:Button could not be found.
All I want to do is, to add a button to the application.
How could I do it?
package {
import PaperBase;
import org.papervision3d.objects.primitives.Cone;
import fl.controls.Button;
import fl.controls.Label;
import fl.events.ComponentEvent;
public class cone1 extends PaperBase {
public var cone:Cone = new Cone();
protected var sceneWidth:Number;
protected var sceneHeight:Number;
public function cone1() {
sceneWidth = stage.stageWidth
sceneHeight = stage.stageHeight;
init(sceneWidth*0.5,sceneHeight*0.5);//position of the cone
}
override protected function init3d():void {
cone.scale = 5;
cone.pitch(-40)
default_scene.addChild(cone);
}
override protected function processFrame():void {
cone.yaw(1);//rotation speed
}
}
}
The fl.* package is part of Flash Professional, not Flex. For Flex you should be using the components that are part of the mx.* package.
Now, that being said, I'm fairly sure it is possible to use Flash components in Flex. I'm just not sure how it's done off the top of my head.
Also, you don't need an actual button component to get a "button like" ui element - any class that extends InteractiveObject will do. This incldes Sprite and MovieClip.
Branden is correct the fl package is a part of the Flash IDE..I am not sure either but you may be able to add the package to your class path if you know where the package resides on your file system..i am guessing somewhere in C:/program files/adobe/flash
if you want to use components in flex builder I think you need make a flex project not an actionscript project
and change your imports to:
import mx.controls.Button;
import mx.controls.Label;
import mx.events.FlexEvent;
Also if you do not need to use components either you can use a Sprite for a button like branden said and you could just use a TextField for a label.
another option if you have the flash IDE is to make a SimpleButton, press F8 select button, click enter. then give it a linkage name by right clickin it in the library panel and selecting linkage name. then export the .swf and put the swf in the src folder for your project and embed it like this:
[Embed(source="flashfile.swf")]
public var myButton:Class;
You may even be able to export the Flash IDE components this way but not sure...actually I am not 100% positive if the [Embed] meta data works in an actionscript project or just flex projects so you will have to check and see.
It depends what version of the IDE you have, for CS4 and Mac the location would be /Applications/Adobe Flash CS4/Common/First Run/Classes
Add that folder or the relevant folder for your installation/OS to your classpath in flashbuilder/eclipse and it will interpret the class calls fine.
It makes sense if you're coding pure actionscript and dont want to use flex components, or employing a mixed coding and designing in IDE approach.
#philip the embed tag cannot be used in pure actionscript
Not sure why you would want to, but if you need to import the flash libs into flex,try dragging what you want to the stage in flash and exporting as a .swc file to import into your flex project.