9 Replies Latest reply on Aug 8, 2011 1:59 AM by Pierre-RAFFA

    Store datas in document

    Pierre-RAFFA

      Hi,

      I know it's possible to store datas like String to the document or pageItem ..

      But is it possible to store complex datas like HostObject in document ?

      Thanks.

        • 1. Re: Store datas in document
          Harbs. Level 6

          Document.insertLabel()

           

          Harbs

          • 2. Re: Store datas in document
            Pierre-RAFFA Level 1

            Document.insertLabel can only store string data ..The second parameter must be a string and i would like to store a HostObject per exemple ..

            Any idea ?

            • 3. Re: Store datas in document
              RayCong

              using SDK,or  Dynamicly create HostObject from string.

              • 4. Re: Store datas in document
                Harbs. Level 6

                You just need to serialize the data first, and unserialize it when you read it out...

                • 5. Re: Store datas in document
                  Pierre-RAFFA Level 1

                  Ok, so i'm creating a HostObject.

                   

                  var vHostObject:HostObject = new HostObject ();

                   

                  and now, how to give it the string data stored in Document.extractLabel to get a valid HostObject ??

                  (just for information, the string data represents PageItem.properties.toSource() )

                   

                  Thanks Harbs.

                  • 6. Re: Store datas in document
                    Harbs. Level 6

                    Hold on.

                     

                    You are using the CS SDK and writing in Actionscript?

                     

                    What exactly are you using HostObject for?

                     

                    It always helps to give full info when you ask questions. I missed the reference to HostObject...

                     

                    Harbs

                    • 7. Re: Store datas in document
                      Pierre-RAFFA Level 1

                      Yes, i'm using CS SDK in Flex.

                       

                      I have to get several states ( geometry, rotation, strokeColor .... )  of a PageItem in Page.

                      To do that, i get that state by using PageItem.properties which is HostObject according to Flex debugger and I store the PageItem.properties.toSource() by using  PageItem.insertLabel(key , value:String)

                      And in my palette,  when user want to change state of PageItem, I would like to switch state by using PageItem.properties = PageItem.extractLabel("state2").

                      But PageItem.properties waits a HostObject and i have a string, so how to convert this string to be setted to PageItem.properties. ??

                       

                      I could store PageItem.properties(HostObject)  into a Dictionnary and switch states simply ... This works .. but i want to store all states in Document because afer a reopen, i would find them again ...

                       

                      I hope my english is ok...

                      Thanks Harbs.

                      • 8. Re: Store datas in document
                        Harbs. Level 6

                        I don't think you need HostObject for that. I think a simple Object will work.

                         

                        Do a Google search for serializing Objects in Actionscript, and you'll find many approaches. There are ByteArray methods you can use if you want to go that way. You can even use an Extndscript call with eval() to do it in standard Javascript.

                         

                        No matter what method you use to serialize and unserialize the data, you'll write the serialized string to a label and read it out afterwards.

                         

                        Harbs

                        • 9. Re: Store datas in document
                          Pierre-RAFFA Level 1

                          I finally used a jsx call to execute an eval which returns this famous HostObject.

                          I set the PageItem.properties with that, and ......................that works !!!

                           

                          Thanks Harbs for your help.

                           

                          Pierre RAFFA

                          Aquafadas.