A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Read Text length in ChildNode for autoScroll

  1. #1
    Twansparant Twandeman's Avatar
    Join Date
    May 2004
    Location
    Amsterdam
    Posts
    197

    Read Text length in ChildNode for autoScroll

    Hi everyone,
    I'm nearly finished making a website with all of it's content in one xml file.
    I have a textbox which reads its content from the xml file with. I'm using a scrollcomponent on the textbox. Now I want to autohide the scrollcomponent if the number of characters is below some number.

    How can I read-in the number of text characters in the ChildNode?

    PHP Code:
    var Desc project.childNodes[3].firstChild;
    detail_mc.description.xmltext.text Desc;
    //Auto Scroll description
    if (project.childNodes[3].firstChild.nodeValue >= 10) {
        
    detail_mc.scrolldesc._visible true;
        } else {
        
    detail_mc.scrolldesc._visible false;

    If I try this line:
    var Desc = project.childNodes[3].firstChild.nodeValue;
    The textbox stays empty, so that doesn't work somehow.

    Can anyone give me a hand?
    Thanks!
    Toine Kamps | Design & Coding
    toinekamps.com

  2. #2
    Member
    Join Date
    May 2003
    Location
    Florida
    Posts
    90
    try

    var Desc = String(project.childNodes[3].firstChild.firstChild);
    visit my portfolio and sign my guestbook!!

  3. #3
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Hi,

    I think the string .length property is what you need..

    AS:
    PHP Code:
    // if "project.childNodes[3].firstChild" is  a text node then use
    // (for text nodes, the "nodeValue" is a string)
    var Desc project.childNodes[3].firstChild.nodeValue

    // if "project.childNodes[3].firstChild" is NOT a text node then use 
    // var Desc = project.childNodes[3].firstChild.toString()

    detail_mc.description.xmltext.text Desc

    //Auto Scroll description 
    if (Desc.length >= 10) { 
        
    detail_mc.scrolldesc._visible true
    } else { 
        
    detail_mc.scrolldesc._visible false
    }

    // Equivalent to the previous "if" condition is this:
    // detail_mc.scrolldesc._visible=(Desc.length >= 10)?true:false 
    As i wrote in the last line of the previous code, Equivalent to your "if" condition, is this (one) line (use the ternary ? -conditional operator) :
    Code:
    detail_mc.scrolldesc._visible=(Desc.length >= 10)?true:false
    (is not something important, just if want a bit shorter code)


    Kostas
    Last edited by Kostas Zotos; 06-09-2008 at 01:45 PM.
    K. Zotos online portfolio: http://www.in3d.eu

  4. #4
    Twansparant Twandeman's Avatar
    Join Date
    May 2004
    Location
    Amsterdam
    Posts
    197
    Thanks guys! You were both right!
    First I had to make it a string like Cesspenar suggested, and then I could use the Desc.length property like Kostas Zotos suggested.
    Thanks a lot!
    Toine Kamps | Design & Coding
    toinekamps.com

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