How can I modify a text element

Leónidas Williams Gaínza <[email protected]> Sun, 17 Nov 2002 09:39:06 +0100
Newsgroups gmane.comp.java.jgenerator.devel
Message-ID <002d01c28e14$caaeab10$a1ea2550@lwilliams>
This is a multi-part message in MIME format.

------=_NextPart_000_002A_01C28E1D.2C114400
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Hi to everybody:

I need your help. I am trying to=20

1) read a swt file that has a layer containing a Library Item kind of =
movie clip that is a text.
2) open this file and change the content of this text item, changing the =
text shown.
3) obtain a new swf file.

I am trying it using the code that I enclose in this message, but it is =
not working. Could you help me please? Where am I doing wrong the steps?

Thanks in advance for your help:

    public static void main(String[] args) {
        try{
            FlashFile ff =3D FlashFile.parse("source.swt");
           =20
            String flash_path =3D "Text1";
            =20
             Script scr =3D (Script)ff.getDefFromLibrary(flash_path);
             Frame frm =3D scr.getFrameAt(0);
             for(Enumeration enum =3D =
frm.elements();enum.hasMoreElements();){
                Text txt =3D (Text)((Instance)enum.nextElement()).def;
                IVVector iv =3D (IVVector)txt.getTextItems();            =
       =20
                    for(Enumeration enum2 =3D =
iv.elements();enum2.hasMoreElements();){
                        TextItem txtItem =3D =
(TextItem)enum2.nextElement();
                        txtItem.text =3D "Hello World. Modified!!";      =
                 =20
                    }
             }
               =20
             ff.addDefToLibrary("Text1",  scr);   =20
             FlashOutput fob =3D ff.generate();
             BufferedOutputStream bos =3D new BufferedOutputStream( new =
FileOutputStream( "target.swf" ) );
             bos.write( fob.getBuf(), 0, fob.getSize() );
             bos.close();

             System.out.println("Done!");
        }catch(Exception e){
            System.out.println("Excepci=F3n: " + e);
        }
    }

------=_NextPart_000_002A_01C28E1D.2C114400
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2719.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>Hi to everybody:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I need your help. I am trying to =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>1) read a swt file that has a layer =
containing a=20
Library Item kind of movie clip that is a text.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>2) open this file and change the =
content of this=20
text item, changing the text shown.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>3) obtain a new swf file.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am trying&nbsp;it using the code that =
I enclose=20
in this message, but it is not working. Could you help me please? Where =
am I=20
doing wrong the steps?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks in advance for your =
help:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; public static void =
main(String[]=20
args) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
try{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
FlashFile ff =3D=20
FlashFile.parse("source.swt");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
String=20
flash_path =3D=20
"Text1";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
Script scr =3D=20
(Script)ff.getDefFromLibrary(flash_path);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
Frame frm =3D=20
scr.getFrameAt(0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
for(Enumeration enum =3D=20
frm.elements();enum.hasMoreElements();){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
Text txt =3D=20
(Text)((Instance)enum.nextElement()).def;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
IVVector iv =3D=20
(IVVector)txt.getTextItems();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
for(Enumeration enum2 =3D=20
iv.elements();enum2.hasMoreElements();){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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nbsp;=20
BufferedOutputStream bos =3D new BufferedOutputStream( new =
FileOutputStream(=20
"target.swf" )=20
);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;=20
bos.write( fob.getBuf(), 0, fob.getSize()=20
);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;=20
bos.close();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
System.out.println("Done!");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
}catch(Exception=20
e){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
System.out.println("Excepci=F3n: " +=20
e);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
}<BR>&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_002A_01C28E1D.2C114400--




-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing 
your web site with SSL, click here to get a FREE TRIAL of a Thawte 
Server Certificate: http://www.gothawte.com/rd524.html