A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: XML Quetion, Help Please!

  1. #1
    Junior Member
    Join Date
    Sep 2005
    Posts
    18

    XML Quetion, Help Please!

    XML Question.

    I found a newsBlock component, with the Action scripting provided below.

    Code:
    /* ---------------------------------------------------------------------------------
     (c) 2003 Armen Abrahamyan 
     http://abrahamyan.com 
     armen@abrahamyan.com
     
     Please contact Author for commercial use.
     
     newsBlock component.
     version 1.0
      
     methods :
     
     setSize(w,h) 
     
     how to use :
     
     After installing MXP file just drag newsBlock component from components panel to stage.
     Make sure you put newsblock.xml file in the same directory as your  swf containing the component.
     
     component parameters:
     
     text color:  the color of news text
     link color:  the color of the links in the news
     date color:  the color of the dates in the news
     show full news:  if "true" newsBlock will show full news for each date,else will show only header of news ( will show only number of symbols specifyed in next property) 
     text selectable: "ture" textField will be selectable, otherwise not
     number of symbols: how many symbols to show for each date, if "show full news" property is false 
    
     
     -----------------------------------------------------------------------------------
    */
    #initclip
    function newsBlock() {
    	_global.ref = this;
    	this.init();
    }
    newsBlock.prototype = new MovieClip();
    Object.registerClass("newsBlock",newsBlock);
    // init
    newsBlock.prototype.init = function() {
    	ref._x = Math.round(ref._x);
    	ref._y = Math.round(ref._y);
    	ref.componentWidth = ref._width;
    	ref.componentHeight = ref._height;
    	ref._xscale = ref._yscale=100;
    	ref.boundingBox_mc._visible = false;
    	
    	ref.add_borders();
    	ref.attachMovie("textBlock_mc","textBlock_mc",5)
    	
    	ref.textBlock_mc.news_txt.html=true
    	ref.textBlock_mc.news_txt.selectable=ref.t_select
    	ref.textBlock_mc.news_txt.textColor=this.t_color.toString(16)
    	ref.textBlock_mc.news_txt.text = "loading XML data";
    	
    	ref.setSize(ref.componentWidth, ref.componentHeight);
    	//
    	
    	//----------
    	var newsXML = new XML(this);
    	newsXML.ignoreWhite = true;
    	newsXML.onLoad = function(success) {
    		if (success) {
    			if (this.loaded && this.hasChildNodes) {
    				ref.news_content = new Array();
    				ref.news_date = new Array();
    				if (this.firstChild.nodeName.toLowerCase() == "newsblock") {
    					var nm = this.firstChild.childNodes;
    					for (var i = 0; i<=nm.length; i++) {
    						if (nm[i].nodeName == "news") {
    							ref.news_date.push(nm[i].attributes.date);
    							ref.news_content.push(nm[i].firstChild.nodeValue);
    						}
    					}
    				}
    			}
    			ref.show_news2();
    		}
    	};
    	newsXML.load("newsblock.xml");
    	
    	
    };
    newsBlock.prototype.add_borders = function() {
    	
    	this.attachMovie("border_up", "border_up", 1);
    	this.attachMovie("border_down", "border_down", 2);
    	this.attachMovie("border_left", "border_left", 3);
    	this.attachMovie("border_right", "border_right", 4);
    	
    };
    newsBlock.prototype.show_news = function(n) {
    	ref.textBlock_mc.news_txt.htmlText = "<FONT COLOR='#"+ref.d_color.toString(16)+"'>"+ref.news_date[n]+"</FONT>"+"<br>"+"<FONT COLOR='#"+ref.t_color.toString(16)+"'>"+ref.news_content[n]+"</FONT>" +"<br><A HREF=\"asfunction:ref.show_news2,"+i+"\"><FONT COLOR='#"+ref.l_color.toString(16)+"'><u>Back To Tutorials</u></FONT></A> <br><br>";
    };
    newsBlock.prototype.show_news2 = function() {
    	var cnt = ref.news_content.length;
    	ref.textBlock_mc.news_txt.text = "";
    	if(!ref.sf_news){
    		for (var i = 0; i<cnt; i++) {
    			ref.textBlock_mc.news_txt.htmlText += "<FONT COLOR='#"+ref.d_color.toString(16)+"'>"+ref.news_date[i]+"</FONT>"+"<br>"+"<FONT COLOR='#"+ref.t_color.toString(16)+"'>"+ref.news_content[i].substring(0, ref.n_symbol)+"</FONT>"+"...<br><A HREF=\"asfunction:ref.show_news,"+i+"\"><FONT COLOR='#"+ref.l_color.toString(16)+"'>"+"<u>More Information</u></FONT></A> <br><br>";
    		}
    	}else{
    		for (var i = 0; i<cnt; i++) {
    			ref.textBlock_mc.news_txt.htmlText += "<FONT COLOR='#"+ref.d_color.toString(16)+"'>"+ref.news_date[i]+"</FONT>"+"<br>"+"<FONT COLOR='#"+ref.t_color.toString(16)+"'>"+ref.news_content[i]+"<br><br>";
    		}
    		
    	}
    };
    // setSize
    newsBlock.prototype.setSize = function(w, h) {
    	this.componentWidth = Math.round(w);
    	this.componentHeight = Math.round(h);
    	this.boundingBox_mc._width = Math.round(w);
    	this.boundingBox_mc._height = Math.round(h);
    	var tmp = 4;
    	this.border_up._x = 0;
    	this.border_up._y = 0;
    	this.border_up._width = this.boundingBox_mc._width-tmp-16;
    	this.border_left._x = 0;
    	this.border_left._y = this.border_up._height;
    	this.border_left._height = this.boundingBox_mc._height-this.border_up._height-this.border_down._height;
    	this.border_down._x = 0;
    	this.border_down._y = this.border_up._height+this.border_left._height;
    	this.border_down._width = this.border_up._width;
    	this.border_right._x = this.border_up._width-this.border_right._width;
    	this.border_right._y = this.border_up._height;
    	this.border_right._height = this.border_left._height;
    	this.textBlock_mc.news_txt._x = this.border_left._width;
    	this.textBlock_mc.news_txt._y = this.border_up._height;
    	this.textBlock_mc.news_txt._width = this.border_up._width-this.border_left._width-this.border_right._width
    	this.textBlock_mc.news_txt._height = this.border_left._height-this.border_up._height-this.border_down._height
    	
    };
    #endinitclip
    The XML code that goes with it is
    Code:
     
    <?xml version='1.0'?>
    <newsblock>
    <news date='13 10 03'>Working with Flash documents overview.When you create and save Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 documents within the Flash authoring environment, the documents are in FLA file format. To display a document in Macromedia Flash Player, you must publish or export the document as a SWF file
    </news>
    <news date='04 08 03'>Saving Flash documents.You can save a Flash FLA document using its current name and location, or save the document using a different name or location. You can revert to the last saved version of a document. You can also save Flash MX 2004 content as a Flash MX document.
    </news>
    <news date='27 07 03'>About adding media content.You can add media content to a Flash document in the Flash authoring environment. You can create vector artwork or text directly in Flash; import vector artwork, bitmaps, video, and sound; and create symbols, reusable media content such as buttons.
    </news>
    </newsblock>


    So I want to change the code in flash to make whatever data I put into “<news date='XXXXXXX'>” A link that will open on a new window.

    In the Action scripting I know that "+ref.news_date[i]+" on the 100’th line of code is when the data is pulled and used, I just don’t know how to take that and make it a hyperlink.

    I really hope some one can help, thanks!

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    It looks like the code is filling in a html text box. You will need to write html code that creates a link. < a href="link" target="newWindow"> is what you need wrapped around that code.

    I would suggest that you should post a smaller amount of code if you want your questions answered quickly.

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  3. #3
    Junior Member
    Join Date
    Sep 2005
    Posts
    18
    Quote Originally Posted by tupps
    It looks like the code is filling in a html text box. You will need to write html code that creates a link. < a href="link" target="newWindow"> is what you need wrapped around that code.

    I would suggest that you should post a smaller amount of code if you want your questions answered quickly.

    Thanks

    Luke
    Sorry about the excess code, I just wanted everyone to know what exactly I am working with.

    So what “code” needs the < a href="link" target="newWindow"> wrapped around?

    Thanks!

  4. #4
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Modify any line with ref.news_date[i] for example
    ref.textBlock_mc.news_txt.htmlText += "<FONT COLOR='#"+ref.d_color.toString(16)+"'>"+ref.news_d ate[i]+"</FONT>"+"<br>"+"<FONT COLOR='#"+ref.t_color.toString(16)+"'>"+ref.news_c ontent[i]+"<br><br>";

    As follows: (changes are in bold)
    ref.textBlock_mc.news_txt.htmlText += "<FONT COLOR='#"+ref.d_color.toString(16)+"'><a href = 'http://yourlink.com/page.htm' target = '_blank'>"+ref.news_date[i]+"</a></FONT>"+"<br>"+"<FONT COLOR='#"+ref.t_color.toString(16)+"'>"+ref.news_c ontent[i]+"<br><br>";
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  5. #5
    Junior Member
    Join Date
    Dec 2006
    Posts
    15

    newsblock? images?

    Ho Ho it's christmas.

    I have been toying with the same neat news block tutorial and I'm trying to add images to each post via xml. But I havn't got a clue anymore and I have gone completely code blind. Basically I would like to insert specific images to each dated post, that will scroll with the post on the page. I'll keep hammering away at it. But any advice would we welcome.

    mcgoo

    http://board.flashkit.com/board/newr...e=1&p=3574489#

  6. #6
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    If you wrap whatever section of the XML you want to add valid html formatted image paths to in CDATA tags, depending on the version of Flashplayer your component targets, you should be able to push the text and images to the html textfield with no problem. Flash needs to have a valid html path,width and height sent to it. Problem for me is, this is an old post already addressed before my tenure and some players are still around.

    Tupps hasn't posted here since May this year for instance but Kortex is still around so I'll sit back and see what he can add since he originally seemed to be on your sheet of music and offered solutions.

    At the very least post the entire source code for the original package that was the original basis for this thread discussion to help us all help you. If nothing pans out I'll work on it based on the original.

  7. #7
    Junior Member
    Join Date
    Dec 2006
    Posts
    15

    newsblock? images?

    Hi

    It's the newsblock component that Magic Toe Nailwas working on.

    you can down load it from
    http://abrahamyan.com/exp/28%2010%2003.html

    Here is the xml:
    <?xml version='1.0'?>
    <newsblock>
    <news date='13 10 03'>Working with Flash documents overview.When you create and save Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 documents within the Flash authoring environment, the documents are in FLA file format. To display a document in Macromedia Flash Player, you must publish or export the document as a SWF file.
    </news>
    <news date='10 09 03'>Creating or opening a document and setting properties.You can create a new document or open a previously saved document as you work in Flash. In Windows, you can use the New File button to open a document of the same type as the last document created.
    </news>
    <news date='04 08 03'>Saving Flash documents.You can save a Flash FLA document using its current name and location, or save the document using a different name or location. You can revert to the last saved version of a document. You can also save Flash MX 2004 content as a Flash MX document.
    </news>
    <news date='27 07 03'>About adding media content.You can add media content to a Flash document in the Flash authoring environment. You can create vector artwork or text directly in Flash; import vector artwork, bitmaps, video, and sound; and create symbols, reusable media content such as buttons.
    </news>
    <news date='Ybench' URL="swfs/Ybench" target="_root.box"></news>
    </newsblock>


    Basically I think I need to attach _root.box to every news date item in the fla and then in the xml use something like what in green above. I'm just not sure whereto do that.

    here is the fla code
    /* ---------------------------------------------------------------------------------
    (c) 2003 Armen Abrahamyan
    http://abrahamyan.com
    armen@abrahamyan.com

    Please contact Author for commercial use.

    newsBlock component.
    version 1.0

    methods :

    setSize(w,h)

    how to use :

    After installing MXP file just drag newsBlock component from components panel to stage.
    Make sure you put newsblock.xml file in the same directory as your swf containing the component.

    component parameters:

    text color: the color of news text
    link color: the color of the links in the news
    date color: the color of the dates in the news
    show full news: if "true" newsBlock will show full news for each date,else will show only header of news ( will show only number of symbols specifyed in next property)
    text selectable: "ture" textField will be selectable, otherwise not
    number of symbols: how many symbols to show for each date, if "show full news" property is false


    -----------------------------------------------------------------------------------
    */
    #initclip
    function newsBlock() {
    _global.ref = this;
    this.init();
    }
    newsBlock.prototype = new MovieClip();
    Object.registerClass("newsBlock",newsBlock);
    // init
    newsBlock.prototype.init = function() {
    ref._x = Math.round(ref._x);
    ref._y = Math.round(ref._y);
    ref.componentWidth = ref._width;
    ref.componentHeight = ref._height;
    ref._xscale = ref._yscale=100;
    ref.boundingBox_mc._visible = false;

    ref.add_borders();
    ref.attachMovie("textBlock_mc","textBlock_mc",5)

    ref.textBlock_mc.news_txt.html=true
    ref.textBlock_mc.news_txt.selectable=ref.t_select
    ref.textBlock_mc.news_txt.textColor=this.t_color.t oString(16)
    ref.textBlock_mc.news_txt.text = "loading XML data";

    ref.setSize(ref.componentWidth, ref.componentHeight);
    //

    //----------
    var newsXML = new XML(this);
    newsXML.ignoreWhite = true;
    newsXML.onLoad = function(success) {
    if (success) {
    if (this.loaded && this.hasChildNodes) {
    ref.news_content = new Array();
    ref.news_date = new Array();
    if (this.firstChild.nodeName.toLowerCase() == "newsblock") {
    var nm = this.firstChild.childNodes;
    for (var i = 0; i<=nm.length; i++) {
    if (nm[i].nodeName == "news") {
    ref.news_date.push(nm[i].attributes.date);
    ref.news_content.push(nm[i].firstChild.nodeValue);
    }
    }
    }
    }
    ref.show_news2();
    }
    };
    newsXML.load("xml/newsblock.xml");


    };
    newsBlock.prototype.add_borders = function() {

    this.attachMovie("border_up", "border_up", 1);
    this.attachMovie("border_down", "border_down", 2);
    this.attachMovie("border_left", "border_left", 3);
    this.attachMovie("border_right", "border_right", 4);

    };
    newsBlock.prototype.show_news = function(n) {
    ref.textBlock_mc.news_txt.htmlText = "<FONT COLOR='#"+ref.d_color.toString(16)+"'>"+ref.news_d ate[n]+"</FONT>"+"<br>"+"<FONT COLOR='#"+ref.t_color.toString(16)+"'>"+ref.news_c ontent[n]+"</FONT>" +"<br><A HREF=\"asfunction:ref.show_news2,"+i+"\"><FONT COLOR='#"+ref.l_color.toString(16)+"'><u>Back To Tutorials</u></FONT></A> <br><br>";
    };
    newsBlock.prototype.show_news2 = function() {
    var cnt = ref.news_content.length;
    ref.textBlock_mc.news_txt.text = "";
    if(!ref.sf_news){
    for (var i = 0; i<cnt; i++) {
    ref.textBlock_mc.news_txt.htmlText += "<FONT COLOR='#"+ref.d_color.toString(16)+"'>"+ref.news_d ate[i]+"</FONT>"+"<br>"+"<FONT COLOR='#"+ref.t_color.toString(16)+"'>"+ref.news_c ontent[i].substring(0, ref.n_symbol)+"</FONT>"+"...<br><A HREF=\"asfunction:ref.show_news,"+i+"\"><FONT COLOR='#"+ref.l_color.toString(16)+"'>"+"<u>More Information</u></FONT></A> <br><br>";
    }
    }else{
    for (var i = 0; i<cnt; i++) {
    ref.textBlock_mc.news_txt.htmlText += "<FONT COLOR='#"+ref.d_color.toString(16)+"'>"+ref.news_d ate[i]+"</FONT>"+"<br>"+"<FONT COLOR='#"+ref.t_color.toString(16)+"'>"+ref.news_c ontent[i]+"<br><br>";
    }

    }
    };

    if (items < 1) {
    getURL(url, target);
    _root.box.loadMovie("swfs/"+this.news_txt+".swf");
    }


    // setSize
    newsBlock.prototype.setSize = function(w, h) {
    this.componentWidth = Math.round(w);
    this.componentHeight = Math.round(h);
    this.boundingBox_mc._width = Math.round(w);
    this.boundingBox_mc._height = Math.round(h);
    var tmp = 4;
    this.border_up._x = 0;
    this.border_up._y = 0;
    this.border_up._width = this.boundingBox_mc._width-tmp-16;
    this.border_left._x = 0;
    this.border_left._y = this.border_up._height;
    this.border_left._height = this.boundingBox_mc._height-this.border_up._height-this.border_down._height;
    this.border_down._x = 0;
    this.border_down._y = this.border_up._height+this.border_left._height;
    this.border_down._width = this.border_up._width;
    this.border_right._x = this.border_up._width-this.border_right._width;
    this.border_right._y = this.border_up._height;
    this.border_right._height = this.border_left._height;
    this.textBlock_mc.news_txt._x = this.border_left._width;
    this.textBlock_mc.news_txt._y = this.border_up._height;
    this.textBlock_mc.news_txt._width = this.border_up._width-this.border_left._width-this.border_right._width
    this.textBlock_mc.news_txt._height = this.border_left._height-this.border_up._height-this.border_down._height

    };
    #endinitclip




    many thanks

    mcgoo

  8. #8
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Was there still problem with this one?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  9. #9
    Junior Member
    Join Date
    Dec 2006
    Posts
    15
    Yes Kortex and as you can brobably tell I'm quite green to this, so if I don't get things straight away, I'll just have to keep plugin. So any help is very welcome.

    mcgoo

  10. #10
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    well there is a lot of code there and I have never played with the tutorial in question, but from a quick glance:

    <news date='Ybench' URL="swfs/Ybench" target="_root.box"></news>

    It seems that your intent here is to provide the path to a SWF to be loaded in the URL="swfs/Ybench", which in XML terms is called an attribute (anything inside a tag with the name = someValue format). However, this structure differers from the rest of the nodes that provide date and text data. So the code to handle this would be different and I am not sure how the images fit into the over all scheme of things.

    It does not look like the data structure for this was originally set up to include data for an image. It only has arrays for dates and text, so it could take a bit of customization to get this system to do what you want (but it definitely is not impossible, and again I have only had time to look at this quickly.)

    Let me know if you have any specific questions.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  11. #11
    Junior Member
    Join Date
    Dec 2006
    Posts
    15

    newsblock? image?

    Hi and thanks for replying kortex and Chris_Seahorn

    Basically I just want to add images or swfs to the xml news data and fla. I was intending to take the attributes from the xml file and define them in the fla. But I do not know how or what is the best way to do this.
    Also I was thinking of using thumbnail images in the news data and large images in the main expanded news. Which is probably a little too *****ious for solo me at the moment.
    Here are some images as to what it could look like, if they explain it a bit better than i can.

    [IMG]news01.jpg[/IMG]
    [IMG]news02.jpg[/IMG]

    Your advice or even links to other posts, are very much welcomed.

    thanks

    mcgoo
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center