We help IT Professionals succeed at work.

How can I dynamically change FlashVars item "streamName" at runtime using ASP.NET?

2,778 Views
Last Modified: 2008-07-22
Trying to figure out how to reference the 2 streamName name/value pairs in the <object> and <embed tags> of a flash control on an .aspx page. I am trying to use asp.net to get the data from a table (no problem there) and put it in the value part of streamName FlashVar.

I can't seem to reference these tags, or insert script brackets inside of the <object> or <embed> tags.
I've tried <%# strstreamNameVariable %>. I could do it if I could get javascript to see these tags and their parameters.

Here is the flash control that works static ok on my webpage(the streamName is the onlything I need to change):

  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="400" height="300" id="FLVPlayer">
    <param name="movie" value="FLVPlayer_Progressive.swf" />
    <param name="salign" value="lt" />
    <param name="quality" value="high" />
    <param name="scale" value="noscale" />
    <param name="FlashVars" value="&MM_ComponentVersion=1&skinName=Clear_Skin_3&streamName=zydeco-example&autoPlay=false&autoRewind=true" />
    <embed src="FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName=Clear_Skin_3&streamName=zydeco-example&autoPlay=false&autoRewind=true" quality="high" scale="noscale" width="400" height="300" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />  
</object>
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
The embedded tags don't work no matter how I do it. I did end up with what you suggest (pretty much exactly like you say). I will award you the points, only fair. However, if I might squeeze a little more out of you:  I would like to serverside write these tags to javascript that then does a document.write or a document.getElementById("someSpanID").innerHTML= javscriptVariable. Can't seem to figure that one out. (body onload fill the span or something like that). Reason being is that I'm trying to avoid that annoying "click here to activate control" which happens unless you write the flash tags using javascript.

Here is my working code that models your soluton, thank you very much!
            Dim sbFlashPlayer As New StringBuilder

            'FOR IE BROWSERS
            sbFlashPlayer.Append("")
            sbFlashPlayer.Append(Environment.NewLine)
            sbFlashPlayer.Append("")
            sbFlashPlayer.Append(Environment.NewLine)
            sbFlashPlayer.Append("")
            sbFlashPlayer.Append(Environment.NewLine)
            sbFlashPlayer.Append("")
            sbFlashPlayer.Append(Environment.NewLine)
            sbFlashPlayer.Append("")
            sbFlashPlayer.Append(Environment.NewLine)
            sbFlashPlayer.Append("")
            sbFlashPlayer.Append(Environment.NewLine)
            'FOR ALL OTHER BROWSERS
            sbFlashPlayer.Append("")
            sbFlashPlayer.Append(Environment.NewLine)
            sbFlashPlayer.Append("")
            sbFlashPlayer.Append(Environment.NewLine)

            objFlash.Text = sbFlashPlayer.ToString

Commented:
You can have the literal contain a <script> tag with a single function which does a document.write() of each line in the code you posted.

An alternative method that I've found is to have a bit of script near the bottom of your page (say after the closing body tag and before the closing html tag) which does something like this:

var els = document.getElementsByTag('object')

for(i = 0; i < els.length; i++)
{
   els.outerHTML = els.outerHTML;
}

I've no idea why it works, but for some reason it does (I used it in a project a few months back).  You may have to do the same for the embeds.

Author

Commented:
"I've no idea why it works"

Works for what? Getting rid of the "Click here to activate control".
Hope that is what you mean.
You have good ideas.

Commented:
Sorry, yeah it gets rid of the click here to activate.

Author

Commented:
Yeah, this didn't work. Still have to click twice to start the flash:

  <script type="text/javascript">

    var els = document.getElementsByTag('object');

    for(i = 0; i < els.length; i++)
    {
       els.outerHTML = els.outerHTML;
    }
</script>  

Commented:
See the script below.

It does pretty much the same thing that your script does, however I have it in an external .js file which I reference on each page that needs it.  I believe at one point I tried putting it directly on the page and it wouldn't work for some reason, so try the script below in an external .js file.
if (navigator.appName == "Microsoft Internet Explorer") (function() {
        var onload = window.onload || function(){};
        if (document.body != null) 
        {
			document.body.setAttribute('onload', null);
        }
        window.onload = function() {
                onload.apply(this, arguments);
                var tags = ['object', 'embed', 'applet'];
                for( i=0; i<tags.length; i++ ) {
                        var elements = document.getElementsByTagName(tags[i]);
                        for(j=0; j<elements.length; j++)
                                elements[j].outerHTML = elements[j].outerHTML
                }
        }
})();

Open in new window

Author

Commented:
Well, I think I should make this another question and award points if it is solved. The code below of yours that I used in a javascript file that is referenced at the bottom of my .aspx page returns the first 3 "hey" alerts. But does not return the last one alert("hey 4") and only a blank screen is displayed with or without the alerts.


alert("hey");
           if (navigator.appName == "Microsoft Internet Explorer") (function() {
                    var onload = window.onload || function(){};
                    if (document.body != null)
                    {
                   
                              document.body.setAttribute('onload', null);
                    }
                    window.onload = function() {
                            onload.apply(this, arguments);
                             alert("hey 2");
                            var tags = ['object', 'embed', 'applet'];
                            for( i=0; i

Commented:
Hmm, if nothing is showing up on the page, then it wouldn't get into the last "hey" since the source would appear to be empty.  Perhaps there's a malformed tag on the page which is causing it not to render anything?

Author

Commented:
Well, I take out the script reference and then the page loads.
There is a macromedia flash version detector in the body onload already.

Commented:
That could be effecting it some how, I'm not sure.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.