PDA

View Full Version : Flex Components in AS3 project


firdosh
10-15-2006, 07:47 PM
I am trying to use the Flex components in an AS3 only project using FLex Builder

package {

import mx.core.*;
import mx.events.FlexEvent;
import mx.controls.Button;

public class UsingFlexComponents extends Application
{
public function UsingFlexComponents()
{
super();
this.layout = "vertical";
this.addEventListener(FlexEvent.APPLICATION_COMPLE TE, doInit);
}

private function doInit(e:FlexEvent):void {
var t:Button=new Button();
t.label="wassup";
this.addChild(t);
}
}
}

it compiles and runs fine but I do not see a button. ??

thanks
cheers:)
firdosh

firdosh
10-15-2006, 11:32 PM
i tried extending the Container class but then I get a runtime error

Error: Could not find resource bundle core
at mx.resources::ResourceBundle$/getResourceBundle()[C:\dev\GMC\sdk\frameworks\mx\resources\ResourceBun dle.as:125]
at mx.core::UIComponent$cinit()
at global$init()[C:\dev\GMC\sdk\frameworks\mx\core\UIComponent.as:7 90]
at global$init()[C:\ApplicationsFLEX\UsingFlexComponents\UsingFlexC omponents.as:9]

Tink
10-15-2006, 11:36 PM
I'm not sure what you would achieve by doing this. An AS 3.0 project that included the Flex framework would then be a Flex project wouldn't it? So you might as well just use Flex?

firdosh
10-15-2006, 11:38 PM
Using no mxml ?

Tink
10-16-2006, 12:04 AM
Avoiding MXML is probably not the best thing. MXML makes things quick and easy, so avoiding it initially because its something new to learn is not the best approach. Seriously MXML will speed up your development!!

alternatively you could use the minimum MXML required. Heres 2 approachs's

add a listener to the Application class and once its been fully created you can use solely ActionScript.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" creationComplete="onCreationComplete( event );" >
<mx:Script>

<![CDATA[

import mx.events.FlexEvent;

private function onCreationComplete( event:FlexEvent ):void
{
// ActionScript from here onwards..
}

]]>
</mx:Script>
</mx:Application>

or alternatively you could just write your own class extending Canvas and add that as a Child

Your MXML
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns:myPackage="myPackage.*" >
<myPackage:MyApplication/>
</mx:Application>

Your AS class
package myPackage
{

import mx.containers.Canvas;

public class MyApplication extends Canvas
{

public override function initialize():void
{
super.initialize();
// Start coding AS from here
}

}

}
Seriously though, I'd recommend spending a bit of time with MXML. If your going to use Flex (i.e. the components and architecture), you might as well use it for what its good at, instead of fighting against it.

firdosh
10-16-2006, 02:57 AM
thanks but, I do use mxml and i think its great since it seprates the interface from the code , this is just something I am trying to figure out as to why its not working

cheers :)
firdosh

Tink
10-16-2006, 11:40 AM
ok, but i still don't quite understand why you want to figure this out.

Basically your saying here that you want to use Flex (i.e. the components, these extra classes and the architecture behind them that make Flex), without using Flex.

i.e. you want to use something you don't want to use.

I don't think there is a way of using Flex without using the minimum MXML.

Assertnfailure
10-16-2006, 04:03 PM
If anything, I'd wager to say that the flex container components (at least the ones that would merit being used outside of flex) are a little too heavy to not be used for their intended purpose. There's alot thats running under the hood to achieve simple effects like stretching and centering and aligning content based on the stage and/or other ui components etc.

Tink
10-16-2006, 04:17 PM
Well u use one component that requires the Flex framework and your using Flex.

dr_zeus
10-17-2006, 12:11 AM
Mike Chambers from Adobe has stated the following about Flex components in an Actionscript project:

There is not support for using the Flex Framework in an AS only project. While it is theoretically possible, you would have to manually bootstrap a lot of the application initialization code that Flex handles (something which would be rather complex).

If you want to play with the framework, but don't want to layout your app with mxml, then the easier way is to create a simple mxml file that contains an application tag, and a script tag that then points to your code.

This way, the application tag will take care of all of the initialization, and you can then leverage the framework via ActionScript.

Source (http://chattyfig.figleaf.com/pipermail/flashcoders/2006-July/169075.html)

To summarize, you need to make a Flex project to use Flex components.

firdosh
10-17-2006, 01:18 AM
there was an example on jam jar which shows how to use only as3 project and use flex components.

paulreitz
03-01-2007, 07:12 PM
ok, but i still don't quite understand why you want to figure this out.

Basically your saying here that you want to use Flex (i.e. the components, these extra classes and the architecture behind them that make Flex), without using Flex.

i.e. you want to use something you don't want to use.

I don't think there is a way of using Flex without using the minimum MXML.

This is the very reason I've come to this forum in the first place. I've been asked at work to find a way to use flex to build a menu interface system for an already existing ( and very large) set of flash applications that have been built w/ Flash 9 & AS3. This project is spread across a couple hundred .as files, and half a dozen or so .fla files. It simply wouldn't be feasible to rebuild the entire project with Flex just to accommodate one small part of the project.

So, anyway...I managed to build an interface in Flex and import it into a test app with a Loader class and get the two .swf files to talk to each other. But when I built a more complex menu system I get the following error;

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.managers::LayoutManager/set usePhasedInstantiation()
at mx.core::Application$iinit()
at XXXXXXXXXX$iinit()
at _XXXXXXXXXX_mx_managers_SystemManager/create()
at mx.managers::SystemManager/::initializeTopLevelWindow()
at mx.managers::SystemManager/::docFrameHandler()

(Sorry I had to 'X' out one of the class names, due to a NDA)
The .swf file that is referencing this object has already been compiled using flexbuilder, and runs just fine by itself.

Any help would be appreciated...thnx

Tink
03-01-2007, 08:02 PM
looks like you are trying to access the property of an object, when the object is null.

without actually see what you are doing though its impossible to pinpoint it. Kinda like me showing you my car and saying it don't work but not letting you get near it to find out why.

paulreitz
03-01-2007, 08:27 PM
OK...here's the code that works;


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="550" height="400" backgroundAlpha="0">
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
import xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;



private function onClickHandler(e:MouseEvent):void
{
//doing stuff
}
]]>
</mx:Script>
<mx:Panel x="10" y="10" width="530" height="380" layout="absolute" title="Test Panel">
<mx:Button x="353" y="236" label="Clicky" click="onClickHandler(event)"/>
</mx:Panel>

</mx:Application>


and this is the code that doesn't work;

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="800" height="600">

<mx:Image x="0" y="0" source="resources/images/xxxxxxxxxxxxx.png"/>
<mx:Label text="xxxxxxxxxxxxx" color="#ffffff" fontWeight="bold" fontFamily="Georgia" fontSize="36" y="24" x="291.5" selectable="false" fontAntiAliasType="advanced"/>
<mx:Button x="10" y="241" label="xxxxxxxxxxxxxxxxxxxx" height="83" width="139"/>
<mx:Button x="170.5" y="241" label="xxxxxxxxxxxxx" width="139" height="83"/>
<mx:Button x="330.5" y="241" label="xxxxxxxxxxxxxx" width="139" height="83"/>
<mx:Button x="491.5" y="241" label="xxxxxxxxxxx" width="139" height="83"/>
<mx:Button x="651" y="241" label="xxxxxxx" width="139" height="83"/>
<mx:Button x="10" y="533" label="xxxxxx" enabled="false" width="99" height="34"/>
<mx:Button x="691" y="533" label="xxxxxxxxxx" height="34" width="99"/>

</mx:Application>


Keep in mind I'm a complete noob to Flex, I've been working exclusively in AS3 up to this point. Also, I've tried putting the above components inside a panel, that also didn't work.

paulreitz
03-01-2007, 09:04 PM
Update....

There is nothing wrong with either block of code above. They both load in every test app I use. The problem is somewhere in the AS3 code of the existing app I'm trying to plug them into. I'll have to keep working at it.

Tink
03-01-2007, 09:53 PM
I was gonna say the code you have posted above does nothing but layout some components and load a PNG.

paulreitz
03-02-2007, 02:34 AM
I'm still not sure what went wrong. I copied and pasted the code from my test app over the code in the app I was working on and it worked, so I must have had something out of place.

sakri
06-29-2007, 11:49 AM
sorry to revive an old thread...

I'm using the flex3 beta, and would like to use some common components in a simple as3 project. I don't need the flex framework, I just want to have use the ComboBox and Button... can this be done?

Thanks!

Sakri

dr_zeus
06-29-2007, 05:32 PM
sorry to revive an old thread...

I'm using the flex3 beta, and would like to use some common components in a simple as3 project. I don't need the flex framework, I just want to have use the ComboBox and Button... can this be done?

Thanks!

Sakri

The Flex framework is designed to be used as a whole. If you want a simpler project that only requires a few components, then I recommend using the new components included with Flash CS3. They're very well designed, and you'll have a much smaller SWF file in the end.

SnakeMedia
08-11-2008, 11:45 AM
Hello I am newbie for actionscript.org. Thanks for happy saying Welcome on our forum! :-)


package myPackage
{

import mx.containers.Canvas;

public class MyApplication extends Canvas
{

public override function initialize():void
{
super.initialize();
// Start coding AS from here
}

}

}


I think that is currect like some AS3-Project. Did you know like Flash-Develop 3 or Spec-Actionscript. i like this. But I need Actionscript Edition for Ubuntu / OpenSuse Linux. I have found mtasc for Linux from mtasc homepage. or better compiler from Flex-Builder 3.x

Thanks, Have Fun, SnakeMedia

Ruben
11-04-2008, 06:54 PM
Update....

There is nothing wrong with either block of code above. They both load in every test app I use. The problem is somewhere in the AS3 code of the existing app I'm trying to plug them into. I'll have to keep working at it.

Hey Paul, I'm having the same kind of issue: the client wanted me to provide him with an swf compiled in flex, which he is using in his flash project. On its own the swf works fine, but apparently there's this error that looks almost exactly like the one you posted (except for the last line):

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.managers::LayoutManager/set usePhasedInstantiation()
at mx.core::Application$iinit()
at XXXXXXXXXX$iinit()
at _XXXXXXXXXX_mx_managers_SystemManager/create()
at mx.managers::SystemManager/::initializeTopLevelWindow()
at mx.managers::SystemManager/::docFrameHandler()

..the question here being; are you sure the problem you were having was caused by the flash/actionscript part of the project and had nothing to do with the flex-swf?

thanks - Ruben