Results 1 to 4 of 4

Thread: Converting Element to String

  1. #1
    Join Date
    Jul 2009

    Arrow Converting Element to String

    I am using swfobject to embed flash in my sites. My hope is to take the html element being replaced, and feed that into a flashvar as a string. Then I can convert it back to xml inside of flash and parse it to my heart's content.

    Unfortunately, I don't know my way around javascript and tend to get in over my head quickly.

    The following script breaks swfobject. I assume it's an error in javascript but I'm not familiar with debugging javascript.

    var parent1 = document.getElementById('pageTitle');
    var flashvars = {};
    flashvars.parentXML = parent1.toString();
    It's the third line that causes the error. Is it possible to convert an element to a string as such?

    Not really sure if what I'm doing is possible or how I would manage it better.

    Any advice?

  2. #2
    Join Date
    Jul 2009
    I am far from great at Javascript but try using innerHTML and outerHTML to get the tag and then strip out what you don't want. Tizag or w3schools probably explain those two better than I could.

  3. #3
    Join Date
    Jul 2009
    If memory serves me, I believe that outerHTML is IE only, which is a bit of a deal breaker for me.

    I would be happy to work with innerHTML. If I could get that into a string, I can manage the rest on the Flash end. Unfortunately, it's still breaking swfobject.

    Here is my full (revised) script:
    var parent1 = document.getElementById('pageTitle').innerHTML;
    		var flashvars = {};
    			flashvars.parentXML = "Test";
    		var params = {};
    			params.scale = "noscale";
    			params.salign = "tl";
    			params.wmode = "transparent";
    		var attributes = {};
    			swfobject.embedSWF("flash/pageTitle.swf", "pageTitle", "510", "150", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
    In this case, it's the first line that's breaking swfobject. I replaced the variable reference in line 3 with a string literal. It's just the reference to innerHTML that causes swfobject to break (it runs without it...but doesn't pass anything usable via flashvars).

    It seems that the first line is perfectly valid javascript, so I suppose it's something a little more complicated than just a simple javascript error. Something related to swfobject I suppose. It's always more difficult than it seems like it should be.

  4. #4
    Join Date
    May 2007
    does the element with id 'pageTitle' exist before this JavaScript is executed?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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