Re: Replace layer?
Dmitry Skavish <[email protected]> Mon, 11 Nov 2002 16:21:37 -0500
| Newsgroups | gmane.comp.java.jgenerator.devel |
|---|---|
| Organization | JZox, Inc. |
| Message-ID | <[email protected]> |
Le=F3nidas,
> My goal is to replace the gif image that is in a layer.
The problem here is that all the images which are used in .swf are
just some special case of shape fill, so they always go with a shape.
So order to replace an image you need to modify the shape also.
In general this is not a trivial task, because it may require to
completely parse a shape with all its information, replace transformation
matrix and so on. I was doing similar gig recently and ran into that prob=
lem
when the client requested that the image to be replaced could be scaled a=
nd
aligned inside the replaced image place. If you just need to replace one =
gif
file with another of the same dimensions then you can use the code below.=
If you
need more flexibility (like scaling and aligning) then I would suggest yo=
u
do it yourself, because unfortunately I cannot publish the code here whic=
h I was paid for.
FlashFile file ...;
String flash_path =3D .....; // name of image in the fi=
le
String image_path =3D .....; // name of new image file
FlashDef def =3D file.getDefFromLibrary(flash_path);
if( !(def instanceof Bitmap) ) {
Log.error("Symbol '"+flash_path+"' is not a bitmap, igno=
red.");
continue;
}
Bitmap old_img =3D (Bitmap) def;
Bitmap new_img =3D Bitmap.newBitmap(image_path);
file.removeDef(old_img);
file.addDefToLibrary(flash_path, new_img);
new_img.setID(old_img.getID());
Hashtable processed =3D new Hashtable();
for( Enumeration e =3D file.definitions(); e.hasMoreElements=
(); ) {
FlashDef def =3D (FlashDef) e.nextElement();
if( def instanceof LazyShape ) {
LazyShape shape =3D (LazyShape) def;
IVVector bitmaps =3D shape.getBitmaps();
if( bitmaps !=3D null ) {
boolean is_replaced =3D false;
for( int h=3D0; h<bitmaps.size(); h++ ) {
LazyShape.BitmapRef bref =3D (LazyShape.Bitm=
apRef) bitmaps.elementAt(h);
if( bref.bitmap =3D=3D old_img ) {
bref.bitmap =3D new_img;
is_replaced =3D true;
}
}
if( is_replaced ) {
Rectangle2D bounds =3D shape.getBounds();
}
}
}
}
--=20
Dmitry Skavish
-----------------------
Boston, MA, USA
tel. +1 781 910-3810
http://www.jzox.com
http://www.flashgap.com
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf