Re: How can I change the content of a text layer??

Dmitry Skavish <[email protected]> Thu, 21 Nov 2002 01:32:04 -0500
Newsgroups gmane.comp.java.jgenerator.devel
Message-ID <[email protected]>
Le=F3nidas,

> I like your idea, but can you tell me any place where could I find any =
help
> and/or documentation regarding this way of work? (I would be interested=
 in
> collaborate in the development of this tool, but first at all I would l=
ike
> to understand very well how it works, etc.)

I would recommend you to look at com.iv.flash.Generator class. In short y=
ou need something
like this:

             try {
                 file =3D FlashFile.parse(inFileName, false, encoding);
             } catch( FileNotFoundException e ) {
                 Log.logRB(Resource.FILENOTFOUND, new Object[] {inFileNam=
e}, e);
             }

             if( file !=3D null ) {
                 // load environment
                 Context context =3D new StandardContext();

                 context.setValue("make", "BMW");
                 context.setValue("model", "328i");

                 file.processFile(context);

                 try {
                     file.setCompressed(compressOutput);
                     FlashOutput fob =3D file.generate();
                     BufferedOutputStream bos =3D new BufferedOutputStrea=
m( new FileOutputStream( outFileName ) );
                     bos.write( fob.getBuf(), 0, fob.getSize() );
                     bos.close();
                 } catch( IOException e ) {
                     Log.logRB(Resource.ERRWRITINGFILE, new Object[] {out=
FileName}, e);
                 }

             }

so now if in this file there is a text like: "My car is {make} {model}", =
then
after file.processFile(context) it will be: "My car is BMW 328i"

I hope it helps!

>=20
> Thanks again for your help, time and attention.
>=20
> Att. Le=F3nidas Williams
> ----- Original Message -----
> From: "Dmitry Skavish" <[email protected]>
> To: "Le=F3nidas Williams Ga=EDnza" <[email protected]>
> Cc: <[email protected]>
> Sent: Tuesday, November 19, 2002 6:06 AM
> Subject: Re: [Jgen-devel] How can I change the content of a text layer?=
?
>=20
>=20
>=20
>>Le=F3nidas,
>>
>>first of all try to put some debug code to see whether you in fact chan=
ge
>>the text or not. If you do then it should work.
>>
>>second why don't you try pure jgenerator approach, i.e. put some variab=
les
>=20
> into
>=20
>>the text like {var1}, then create StandardContext, put variables in it =
and
>>process flash file with this context.
>>
>>
>>>I need your help. I am trying to
>>>
>>>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 t=
he
>>>text shown.
>>>3) obtain a new swf file.
>>>
>>>I am trying it using the code that I enclose in this message, but it i=
s
>>>not working. Could you help me please? Where am I doing wrong the step=
s?
>>>
>>>Thanks in advance for your help:
>>>
>>>    public static void main(String[] args) {
>>>        try{
>>>            FlashFile ff =3D FlashFile.parse("source.swt");
>>>
>>>            String flash_path =3D "Text1";
>>>
>>>             Script scr =3D (Script)ff.getDefFromLibrary(flash_path);
>>>             Frame frm =3D scr.getFrameAt(0);
>>>             for(Enumeration enum =3D
>>
> frm.elements();enum.hasMoreElements();){
>=20
>>>                Text txt =3D (Text)((Instance)enum.nextElement()).def;
>>>                IVVector iv =3D
>>>(IVVector)txt.getTextItems();
>>>                    for(Enumeration enum2 =3D
>>>iv.elements();enum2.hasMoreElements();){
>>>                        TextItem txtItem =3D
>>
> (TextItem)enum2.nextElement();
>=20
>>>                        txtItem.text =3D "Hello World.
>>>Modified!!";
>>>                    }
>>>             }
>>>
>>>             ff.addDefToLibrary("Text1",  scr);
>>>             FlashOutput fob =3D ff.generate();
>>>             BufferedOutputStream bos =3D new BufferedOutputStream( ne=
w
>>>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);
>>>        }
>>>    }
>>
>>
>=20
>=20
>=20




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf