11 Replies Latest reply on May 22, 2006 9:01 AM by 2m

    How do I create a title, that behaves like a button?

    rohai Level 1
      Hi,

      I'm using XML to load data from asp to flash. Here's the XML example:

      1. <?xml version="1.0" encoding="iso-8859-1"?>
      2. <news>
      3. <item>
      4. <headline>Flash XML Based News reader out today!</headline>
      5. <date>05/09/1986</date>
      6. <message>Today my new xml based flash news reader came out, I am so excited!</message>
      7. </item>
      8. <item>
      9. <headline>One day until the Flash XML Based News reader is out!</headline>
      10. <date>05/08/1986</date>
      11. <message>Tomorrow my new xml based flash news reader comes out, I am so excited!</message>
      12. </item>
      13. <item>
      14. <headline>Two days until the Flash XML Based News reader is out!</headline>
      15. <date>05/07/1986</date>
      16. <message>The day after tomorrow my new xml based flash news reader comes out, I am so excited!</message>
      17. </item>
      18. </news>


      And here's the ActionScript part:

      1. // Initialize the xml object that our news will be loaded into
      2. var news_xml : XML = new XML();
      3. // ignore all whitespaces inside of our xml file
      4. news_xml.ignoreWhite = true;
      5. // when the xml recieves a return from the load() function call, execute this function
      6. news_xml.onLoad = function( success : Boolean ) {
      7. // if the xml file was successfully loaded
      8. if ( success ) {
      9. parseNews(this);
      10. }
      11. }
      12. // call the load function on the xml object, passing in the url of your xml file
      13. news_xml.load("xmlTutorial.xml");
      14. // this function will take our news xml object and parse it
      15. function parseNews( _xml : XML ) : Void {
      16. // first we create an array that holds all the values of the item nodes
      17. var items : Array = _xml.firstChild.childNodes;
      18. // now we want to iterate over every item in the items array
      19. // and parse the nodes as we see fit
      20. for ( var i : Number = 0 ; i < items.length ; i ++ ) {
      21. // here we set the text of the text field ( news_txt )
      22. // the first thing we add to the textfield is the headline then a line break
      23. news_txt.htmlText += "<b>" + items .childNodes[0].firstChild +"</b><br>";
      24. // next we add the string date followed by the date value in the xml file
      25. news_txt.htmlText += "Date: " + items
      .childNodes[1].firstChild + "<br>";
      26. // now we add the message, then two line breaks, only for formatting
      27. news_txt.htmlText += " " + items .childNodes[2].firstChild + "<br><br>";
      28. }
      29. }

      So far is everything clear to me. But what I want to do now is that after a user clicks on title, next happens:
      the current swf unloads
      the flash sends data to asp (ID of an article and ID of an author, which movie to load next).

      How do create a title/button?I know how to make a title to behave like a link (just add the http://... in the headline tag in XML document. But this,..... I just don't know how to do that.

      THX for any help
        • 2. Re: How do I create a title, that behaves like a button?
          rohai Level 1
          2m, thx for your reply. This part as I said know. What I don't know is how to make that after the user clicks on a title, the flash sends var to asp and unloads the movie. Then from asp flash get the var with content and var with movieID so the right swy can be loaded.
          • 3. Re: How do I create a title, that behaves like a button?
            2m Level 2
            Sorry for misunderstanding you.

            In that case I wouldn't unload the movie, but sendAndLoad Vars or XML to asp, and then reinitialize the movie with the new data, if its contetn is datadriven (vars or xml) or determin the swf to load, and load it onto level 1.

            Seems to be the easier and more userfriendly solution, as you dont have to reload the whole page.
            • 4. Re: How do I create a title, that behaves like a button?
              rohai Level 1
              2m, thx again for your patience. Kglad already told me to use Load class. I have to unload a swf because the whole article is in another swy file .

              What I don't know how to do is:

              If I'd likew the tilte to be a link, then I would do this:

              1. <?xml version="1.0" encoding="iso-8859-1"?>
              2. <news>
              3. <item>
              4. <headline><a href ...>Flash XML Based News reader out today!</a></headline>
              5. <date>05/09/1986</date>
              6. <message>Today my new xml based flash news reader came out, I am so excited!</message>
              7. </item>
              ...

              In this case when the user clicks on the title, the new page will load. I don't want that. I want to create that after the click flash starts to communicate with asp, which then creates or alters the XML for flash and sends the info which movie must be loaded.

              Do I do this already in XML or in AS? I assume it has to be done something like OnRelease send var to asp. Or is that way the wrong one.

              I studied one case, but it was for the List component. The author there did this:

              in XML he wrote attributes and the he added them as an item AddItem and the title worked as URL link. But I don't want to use List component and I was thinking there must be the same solution for me.
              • 5. Re: How do I create a title, that behaves like a button?
                2m Level 2
                Hello rohai,

                it is always hard to give good advise to someone one doesn't know, especially who's level of experience and background one can only guess.

                There are always a lot of working solutions, and often those demanding more know-how are better in terms of reusability and so on, but what I like to find is a solution that you understand and can handle and learn from.

                So forgive me if i ask the question about the unloading-part again.

                Why do you want to unlaod your original swf, why not just hide its content and display the swf you want to load "within" that movie. You can than unload that movie and re-display your table of contents once again without reloading it from an external source.

                I would like to understand your concept to best help you.

                (If you already have a [partly] working example it might also help)
                • 6. Re: How do I create a title, that behaves like a button?
                  rohai Level 1
                  2m, you are right. I should tell you about my concept. It's all on the paper yet, because this is how I work - first I write down everything on paper, study it and the next step in trying to make it work on computer.

                  I have a main swf, I call it system.swf. System.swf receives the info about the swfs, it must be loaded from html tag <object><param>. The ID of the movies is send from flash to asp and then via <object>back to flash. Does that make sense? Is there a better way for that?

                  So, the system.swf is loaded for the whole time - let's say it on level1. On level 2 are then loaded other swfs.It depends which content the user wants to see.

                  About the article part:
                  first the user sees the list of last articles (title, date and short description). When he/she clicks on the title, all the action happens:
                  flash sends the data which article the user wants to read to asp, asp searches in data base for the requested article and creates xml, where are title, date and the whole content of the article.
                  At the same time asp also sends via <object>tag in html the id of the swf that must be loaded and the id of the author of the article, so the swf, where the pictures of the all authors are, will know what picute must load (this is the second swf that is loaded on the article part - it's created like a gallery; the author of the active article is bigger and if the user wants to read the last article of other author, he/she just closes the picture and then the images are moving in a slider way and when he/she clicks on an image, it get larger and the last artcle of this author is loaded).

                  And I wonder how can I make this all to happen: when the user clicks on a title, all the var action happens?

                  If you have better idea how to create this, please, advice.
                  THX for the help so far
                  • 7. Re: How do I create a title, that behaves like a button?
                    2m Level 2
                    I think i do understand what you want, but your approach seems overly complicated to me.
                    Maybe that is due to the fact that I'm missing something crucial, so I try to sum up what I understood, and how I would do it.

                    You have one xml which contains the list (doesn't matter if it is a static file or if it is generated dynamicly).

                    Each item of your list has title, date, and shortdescription. (An unique id typically whould help.)

                    You would load that xml into your swf (the path to that xml can well be defined inside flashvars param if needs be) parse it, and generate a movieclip for each item.
                    That clip contains 3 textfields (this is one way to do it, depends a bit on the design you want to have).

                    The textfield with the title would have a link to a function (lets call it getAtricle(id)).

                    This function could send the id (or date and title if the id thing cannot be done) to the server, that responds wit a new xml, that is of the article format.

                    When that data has arrived (onLoad) a function "showArticle()" would hide the list clips, and build the article texts, and start loading the author image, acording to the path given in the xml data.

                    All this can be done without loading external swfs and without sending things via the <object> tag, which is a concept I doubt exsists, at least I nerver heard or read of.

                    You would just use sendAndLoadXML methods or SendAndLoadVars.

                    • 8. Re: How do I create a title, that behaves like a button?
                      rohai Level 1
                      THX for your help. I will look into it. And yes, it does sound a little complicated ;-).Can I ask you more if I'll need more help?

                      Cheers
                      • 9. Re: How do I create a title, that behaves like a button?
                        2m Level 2
                        Sure, you can always ask, I won't make promises, but I'm willing to help if I can spare the time then.
                        • 10. Re: How do I create a title, that behaves like a button?
                          rohai Level 1
                          How do I link textfield with function?
                          • 11. Re: How do I create a title, that behaves like a button?
                            2m Level 2
                            Hi

                            try this:
                            ____________
                            function testFunction (message_str){
                            trace(message_str);
                            }

                            this.createTextField("test_txt", this.getNextHighestDepth(), 10, 10, 200, 20);
                            this.test_txt.html = true;
                            this.test_txt.htmlText = "<a href=\"asfunction:testFunction, hello world\">My link</a>";
                            ________________

                            cu soon!