View Full Version : flex+f9 combo trouble
robster
01-12-2007, 08:56 AM
hello all,just got myself flex recently and now wanted to convert an f8/AS2 project to AS3.
In the AS2 version the setup was like this: swf generated from flash 8 ide and into that compiled classes written in eclipse/fdt.
Now i´ve converted all class files in flex to as3 compliant and the fla/swf generated from flash 9 ide into an f9/as3 suitable one.
Now comes the problem: I don´t know how to compile into an existing swf from flex.
Like for AS2 projects i could say something like this in the mtasc compiler args field:
-swf pathToSwf/swfName.swf -frame 12
so i could specify an input swf and also specify into which target frame classes are exported there.
Are there similar compiler args in flex or some other way to do it?
I looked for several compiler arg listings on the web but couldn´t find something fitting :(
dr_zeus
01-12-2007, 06:38 PM
What you describe is not a supported workflow with Flex. Flex has certain requirements for the base application, and you must compile it cleanly with mxmlc. You cannot inject code into another SWF. If you need graphic assets from Flash Authoring, you should embed them in your Flex project.
robster
01-12-2007, 07:48 PM
What you describe is not a supported workflow with Flex. Flex has certain requirements for the base application, and you must compile it cleanly with mxmlc. You cannot inject code into another SWF. If you need graphic assets from Flash Authoring, you should embed them in your Flex project.
Thanks for your reply,though i don´t get why this shouldn´t be possible really.
I mean shouldn´t an swf with as3 code exported for flash 9 player from flash 9 ide have the same compiled base as an swf generated from flex in an actionscript project?
If so there would be no propper reason why i can´t inject code into the swf generated from flash.
If it was about doing a new project from the ground up,sure,i could just go with the suggested workflow for flex as3 projects but yeah,porting an as2 project that is set up like this,there it would be very helpful if there was just those two compiler arg equivalents in flex.
It feels really weird to me that my free as2 mtasc can do such things the adobe as3 compiler should not be capable of.
dr_zeus
01-12-2007, 08:12 PM
MTASC was designed to inject code because it cannot compile graphic assets into the SWF. Its creator knew that many users would be using a combined Flash Authoring and MTASC workflow. However, with the Flex compiler, the majority of users will simply be using it alone because it can handle embedding assets from graphic files and other SWFs.
It's not necessarily that MTASC has a feature that MXMLC doesn't, it's that MTASC created a feature to work around it's own short-comings.
robster
01-12-2007, 08:17 PM
thanks for the insight,yeah,i get why that feature was added to mtasc,though i still think its a heavy miss from adobe to not add it to the flex compiler (if it really doesn´t exist). I think i´m not the only one who has done projects with as2 like that before and will have to upgrade them to as3 soon.
Anyway,so what´s the suggested workflow for using an swf generated from flash 9 ide (with library items) in a flex as3 project then?
I´d like to be able to instantiate elements from my lib as if those were sitting in the main swf flex generates.
dr_zeus
01-12-2007, 09:29 PM
Here's the page from the LiveDocs describing the Syntax for Embedding assets (http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000970.html).
Though you can embed your assets in any class, I generally recommend making a central location for your embeds if you're used to using the Flash Authoring library. Here's a quick example:
package
{
public class Library
{
[Embed(source="flashassets.swf" symbol="MyAsset")]
public static var MyAsset:Class;
}
}
...
//in another class
var background:Sprite = new Library.MyAsset();
this.addChild(background);
robster
01-14-2007, 08:42 AM
thanks,yes,this sounds like a good way to do it for new projects one does in flex right away. I think it will be handy to really only use flash to create animated mc assets and then embed them as library assets like you described in an as3 project in flex.
However for this project i´m just converting up from as2 the fla is set up totally with the thought to merge the code in and execute it at a certain point (when things like preloader and some anim and view settings stuff is done on the main timeline). Therefore i just instantiate my main class in the fla now in the right frame which works fine then :)
Thanks again for your help though, this will be really useful for my future projects :)
this is just a suggestion, but if you have a Flash AS 2.0 project, wouldn't you be best off converting it to a Flash AS 3.0 project.
If you use Flex are you actually going to be making use of any of the Flex framework?
robster
01-14-2007, 04:01 PM
this is just a suggestion, but if you have a Flash AS 2.0 project, wouldn't you be best off converting it to a Flash AS 3.0 project.
If you use Flex are you actually going to be making use of any of the Flex framework?
i´m not sure i got what you mean exactly. Before it was a project with a fla with view assets and view code and lots of class files i edited in eclipse with fdt. then i compiled the classes into the flash generated swf.
Now i tried to do something similar in AS3: Port my fla to be flash 9 compliant and then recode all classes in Eclipse with flex plugin (by setting up an as3 code project,so yes,i don´t use the flex framework really).
I thought in the next step i could just like in as2 with mtasc, compile my classes into the flash ide made swf but that obviously doesn´t work.
So now i just use Eclipse+flex plugin for class code editing and then instanitate my main class in the fla timeline and do all like that.
Couldn't u make the FLA that contains all the view assets and code the main SWF.
Link it to a document class (created using AS 3.0 project in Flex Builder) which would use you view assets and classes?
This seems a much easier option than embedding everything in AS files.
So now i just use Eclipse+flex plugin for class code editing and then instanitate my main class in the fla timeline and do all like that.This is what I'm suggesting. Theres no need to embed all the assets with metadat in AS files if your using this approach. In fact if your compiling from Flash it won't understand the embed tags, these only work when compiler with the Flex SDK.
robster
01-14-2007, 07:13 PM
yes,i think each way has its pros and cons and i have to try both more but for this project i´m trying something similar like you said now.
I export from flash but on frame 12 of my timeline (don´t ask why on frame 12,its preloader and graphical mumbo jumbo before.. ;) ) i instantiate my main class (and run the app code from there).
(So i don´t have the main class as document class but well,a very similar setup)
Btw while trying to get all that rolling i´ve also checked these slides from you today: http://www.lfpug.com/presentations/2006_07_27_tink/
First of all thanks a lot for your efforts there,it helped me with a few things already,just like several of your blogposts :)
On another note i´m ntot sure if i got it wrong or if there´s a bug in one of those slides´explanation,maybe you want to check that:
In the slide on getDefinitionByName() it says:
var myLibraryAsset:MyClassReference = new MyClassReference();
I tried to do the same with bitmaps from the library and it would always give me an error saying MyClassReference did not exist.
I then checked DocumentClass.as coming with the sample files for the presentation and there it had a similar example with a sound file,the corresponding line was:
var mySound:Sound = new newSound();
so i realized with the :Sound there,in my case i´d have to write :BitmapData
instead of :MyClassReference as type so the full line would look like this:
var myLibraryAsset:BitmapData = new MyClassReference();
and voilà,it worked :)
Just thought maybe you´re into changing that slide if there´s a flaw or yeah,maybe i messed something else up =)
In either case thanks again for your help =)
hey thanks for the kind words :)
I tried to do the same with bitmaps from the library and it would always give me an error saying MyClassReference did not exist.in the example this is defined in the previous line.
This was an explaination for create multiple clips from the library using a String (i.e. clips linked to classes 'Clip0', 'Clip1', 'Clip2' etc.). So to create these dynamically you could use.
import flash.utils.getDefinitionByName();
for( var i:int; i < 3; i++ )
{
var MyClipClass:Class = getDefinitionByName( "Clip" + i ) as Class;
var myClipInstance:MyClipClass = new MyClipClass();
}hope that makes sense. I was really just trying to show how to do the equivilant in AS 3.0 of whats on the previous slide in AS 2.0.
robster
01-15-2007, 03:22 AM
hey thanks for the kind words :)
you´re welcome, you´ve really helped me a great deal so far with your blog and things like those slides,more than you know :)
in the example this is defined in the previous line.
This was an explaination for create multiple clips from the library using a String (i.e. clips linked to classes 'Clip0', 'Clip1', 'Clip2' etc.). So to create these dynamically you could use.
import flash.utils.getDefinitionByName();
for( var i:int; i < 3; i++ )
{
var MyClipClass:Class = getDefinitionByName( "Clip" + i ) as Class;
var myClipInstance:MyClipClass = new MyClipClass();
}hope that makes sense. I was really just trying to show how to do the equivilant in AS 3.0 of whats on the previous slide in AS 2.0.
i got what the example is for and i need to do something similar now (i call a function,pass names to it and then it should instantiate that lib items), what i meant was the exmple didn´t work for me in the way it was written.
So this is how it looked there:
import flash.utils.getDefinitionByName;
var myLibraryAssets:Array = new Array();
for(var i:int =0; i<4;i++)
{
//Create a reference to the class linked to the library item as a Class object.
var MyClassReference:Class = getDefinitionByName("MyLibraryAsset" + i ) as Class;
// Create am instance of the library asset using the Class object created.
var myLibraryAsset:MyClassReference = new MyClassReference();
myLibraryAssets.push(myLibraryAsset);
}
When i have library assets called MyLibraryAsset0,MyLibraryAsset1,MyLibraryAsset2,My LibraryAsset3 (also hving set that as their class setting and they are exported in first frame) and run that code i get an error:
"Type was not found or was not a compile-time constant: MyClassReference."
when i change the type to BitmapData it works,like this:
import flash.utils.getDefinitionByName;
var myLibraryAssets:Array = new Array();
for(var i:int =0; i<4;i++)
{
//Create a reference to the class linked to the library item as a Class object.
var MyClassReference:Class = getDefinitionByName("MyLibraryAsset" + i ) as Class;
// Create am instance of the library asset using the Class object created.
var myLibraryAsset:BitmapData = new MyClassReference();
myLibraryAssets.push(myLibraryAsset);
}
I am not really happy with that though as i´m essentially casting the library assets to BitmapData,i mean what if i really had a custom class going there and it would just cast it to BitmapData and i loose all the functionality of my custom class. Please let me know if i got that wrong somehow,just getting into f9 i´m easily confused by such things :confused:
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.