View Full Version : Is it possible to extend class w/o access to class code?
PsuFan
February 3rd, 2010, 09:47 AM
Is it possible?
Say you were importing flash.events.KeyboardEvent and you wanted it to extend the MovieClip class, is this possible? Where you dont have access to the class to just type "extends XXX".
(This is just an example, I'm sure this wouldn't work / be useful)
Thanks
justkevin
February 3rd, 2010, 10:07 AM
Yes, you can. I don't think you can create a pure AS3 project without your base class extending Sprite.
wvxvw
February 3rd, 2010, 10:24 AM
Can you think about another example, the one you give is very confusing... If you mean something like:
can you alter inheritance for the class after it's been compiled? - then the answer is no. It was possible in AS2, but not in AS3.
I'm not sure how the question of necessary extending Sprite came in here, but, you can have an SWF with entry point being not a Sprite extending class, it'll throw an error saying that objects not extending Sprite aren't allowed to link to the root, but, through some hacks you can sneak the code that will run after this error happens :) However, I cannot see any practical use to this particular feature.
PsuFan
February 3rd, 2010, 11:50 AM
Thats kind of whats happening. Some morons decided that they didnt want to have their code open source, which I didnt even know was possible till now. So they put the code into the library (which I guess you cant export), and I guess this was done with .swc. The problem is it was made for CS3 - AS3, but the CS3 compiler was less strict, the CS4 compiler gives an error saying the code does not extend the Movieclip class. Since the code is in the library, it has a frames, and a timeline, and must extend the movieclip class.
So the library has Export: comany.whatever.etc
and the actionscript code has import company.whatever.etc
But the error says Location: ErrorResult (Compiled Clip)
So I guess I cant extend them because they are compiled?
justkevin
February 3rd, 2010, 05:07 PM
wvxcw: I was bringing up the sprite example to show that it is not only possible, but an intended part of flash.
PsuFan: Does the error show up if you try to a) import the class, b) create an instance of the class or c) extend the class?
It's possible to create a class as "final" which would mean you can't extend it, but that may not be the problem here.
PsuFan
February 3rd, 2010, 09:31 PM
Import, and get serveral because that imports others.
5000: The class 'r1.deval.D' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
So is it possible?
Bummer, when you right click > properties on the object in the library, the Base class is grayed out, if it would let me type in there, would it work if I added flash.display.MovieClip?
Thanks
Shaedo
February 3rd, 2010, 09:44 PM
have you tried compiling it as a cs3 project ? (I think in the cs4 you just choose save as then select cs3)
PsuFan
February 3rd, 2010, 10:36 PM
When I try and save, it says it is a CS3 project and will save to CS4. Does that mean its already what your trying to do?
I saved as CS3, same error. It still uses the strict CS4 compiler...
I dont really want to have to get CS3 just cause no one can get this working in CS4...
its an eval() function. I posted her before about other solutions that did this and no one replied, so fixing this was the last option I had. I hacked the code but it seemed partially incomplete and couldnt get it to compile.
wvxvw
February 4th, 2010, 10:07 AM
Ah, so we're talking about D.eval here :) well it was never compiled with either version of CS and wasn't really intended for use in that environment :)
It was compiled with Flex 2 COMPC. SWC format had lots of changes since then and most of COMPC versions cannot compile Flash compatible SWCs. Just don't use Flash CS# for this sort of tasks - it's not really made for it.
PsuFan
February 4th, 2010, 10:28 AM
No it was compiled with CS3, there is a flash example included with the download. It just doesnt work in CS4 because Adobe made the compiler more strict (I believe).
It is an AS3 library for Adobe Flex™ 3 and Flash™ programs to execute text strings of dynamic AS3 expressions and programs
wvxvw
February 4th, 2010, 11:47 AM
Trust me, I know what I'm saying :)
Well, you see Flex 2 had a very similar ASC to that of Flash 9 beta those days (It wasn't called CS yet).
The library (that is the SWC in question) was compiled using some very first versions of COMPC, besides, it is possible that the authors made some manipulations on bytecode level after compilation. The compilers those days ware less robust... I used this SWC in Flash CS3 some time ago and it worked because the SWC format that Flash accepted was very similar to that COMPC produces. However, we are 2 major releases after this library was compiled. There ware significant changes in how Flash CS4 handles SWC, I think it would expect anything from Flex 3 and above but not the Flex 2.
Anyways, for somewhat serious coding Flash CS# is just a wrong tool, so, just use something normal instead - problem solved.
PsuFan
February 4th, 2010, 12:53 PM
Well Flash is all I have and its a large project, Im sure it would be hard to convert it.
So I guess all I can do is hope someone builds on for Flash sometime in the future (or maybe built into CS5).
Thanks
wvxvw
February 4th, 2010, 01:14 PM
Well, you can get the SDK and recompile that SWC... it's all free...
PsuFan
February 4th, 2010, 06:34 PM
I can recompile the SWC? How, I dont have the source. What SDK? Flex SDK, dont really know how that works.
wvxvw
February 4th, 2010, 08:33 PM
Well, you download Flex SDK here:
http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK
Get some AS editor, there are lots of topics in this and any other AS forum to convince you to choose one.
To recompile the SWC you can "monkey patch" it, which means something like this:
- you write an AS class with the same name as the one you want to replace in the SWC, make it accessible to compiler (put it on the classpath), write the config file to embed all other classes from the SWC, compile...
However, I think it would be a waste because once you'll get some normal editor and development enviroment you'll hardly want to go back to compiling and coding in Flash... Flash compiler has a good set of transcoders, but it's the worst compiler in terms of development: slow, inflexible, difficult to configure etc.
So, normally the workflow which includes Flash compiler would do the opposite: compile assets in Flash and then use them with another compiler, not other way around.
Apart from SDK compilers there are many other tools that let you manage resources / bytecode, to name a few:
HaXe, SWFMill, SamHaXe, HXswfML, SWFTools...
PsuFan
February 4th, 2010, 11:21 PM
If I replaced a class, wouldn't I need to know the code in the class? Wouldnt I just be rewriting the whole thing?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.