PDA

View Full Version : Linkage Library MC containing objects & Flex Builder compiler


panel
04-23-2007, 01:19 PM
Hi

My way to work with Flash and AS is to create graphics in Flash and linkage them to classes (this way I can easlny separate code from design). I am creating classes in Flex Builder becouse work goes faster with autocompletion system.

Few things changed between Flash CS3 vs Flash 9 Aplha. One of them is that when you linkage library symbol and create class with the same name you don't have to define all objects (MC's, Buttons and other objects that were created in Flash in this linkaged MC) as public class variables (In flash 9 alpha you have to define all of them as public or make class dynamic).
At firtst I liked this new 'feature' but after working a while working with it I see some disadvantages.

Flex builder dosen't even know that those variables exist, and show reference errors like this: (becouse part of class is in Flash and part is in code). (So when I makre real error may not see it instantly)
1119: Access of possibly undefined property playPause_mc through a reference with static type ControlerDecorator.


When I try to define those variables in class errors in Flex Builder dissapear but Flash Throws compilation Error
1151: A conflict exists with definition playPause_mc in namespace internal.
...becouse at this point Flash knows that this variable is defined...

Is there any way to show flex builder compiler that those variables really exist without define them? or have you got any other ideas? Mabye you have betther ways to join graphics and Code?

Tink
04-23-2007, 02:26 PM
Hey panel

I'm out at FiTC at the moment but i have a JSFL command and window SWF where you can specify the directory, it will then run through your library an create stub classes for anything that is auto-generated.

I'll make sure i tidy it up and blog it etc on Fri when i et back.

panel
04-23-2007, 02:54 PM
Thanks Tink I hope it will help me.
I will be waiting to hear from you.

robbob22
05-01-2007, 09:40 PM
Hey Panel,

I code in the same manner with AS2 and Flash 8 (but use a different code editor). Have you found any workarounds yet? I sure like my code-hinting to coincide with what I have on the stage....

Thanks
Robert

SmackMe
05-02-2007, 01:34 PM
Try making your class (classes) dynamic.

robbob22
05-02-2007, 02:23 PM
Smackme,

I'm failing to understand how making classes dynamic will solve the problem at hand. Can you elaborate?

Thanks
Robert

SmackMe
05-02-2007, 03:07 PM
Smackme,

I'm failing to understand how making classes dynamic will solve the problem at hand. Can you elaborate?

Thanks
Robert

I assume that you are using the embed metadata tag to bring flash content into flex. Here is a piece of code on which I will comment:


package
{
import flash.display.Sprite;
import flash.display.Shape;

[Embed(source="library.swf", symbol="Rect")]

dynamic public class Rect extends Sprite {

public var _mata:Circle;

public function Rect() {

var shape:Shape = getChildAt(0) as Shape;
_mata = getChildByName("mata") as Circle;

for(var i:int; i<numChildren; i++) {
trace(i + " : " + getChildAt(i).name + getChildAt(i));
}
// traces
//0 : instance2[object Shape]
//1 : mata[object Circle]

}



}
}


Rect and Circle are actual symbols in library.swf exported in 1st frame;
Rect symbol contains a shape and an instance of Circle (extends Sprite) which I gave an instance name of "mata" in the property inspector. If I try to declare it right after _mata like so:

public var _mata:Circle;
public var mata:Circle;

... and recompile library.swf it will give 1151 error.
Also if I remove dynamic keyword it gives Error #1056: Cannot create property mata on Rect
So, the way I see it, a way to access objects from your library symbols is by means of getChildByName("a_name_here"), storing it into a local variable and eventualy casting to a certain type.

If anything else pops, I'll add further comments.

Regards