2

hey guys, is there any parameter where i could apply a classname to a swfobject?

    <script type="text/javascript">
        var params = { allowScriptAccess: "always" };
swfobject.embedSWF("http://www.youtube.com/v/j_aFmziaRdU&amp;enablejsapi=1&amp;playerapiid=ytplayer_13", "ytplayer_13", "425", "365", "8", null, null, params);

    </script>

This gets rendered as <object ... Is there any chance where i could add a classname to this <object when creating it with swfobject? like <object class="classnam" ...

1
  • Made your code visible (use `` s to mask the <> in xml) and added a css tag. Commented Feb 16, 2011 at 10:53

2 Answers 2

3

You use the attributes parameter (there is no direct link to the paragraph, open link and search for "STEP 3: Embed your SWF with JavaScript" headline) to assign an id or a class to the object. You could then use document.getElementById() to get the object, once it has been created. Or use #id or .classname from CSS, just the way you would expect it to work. Caution, though: attributes.class would cause an error (it's a reserved keyword), you have to use attributes.styleclass to set the classname.

Sign up to request clarification or add additional context in comments.

7 Comments

yeah thank you. I'm already adding it with jquery. That works fine. I was just wondering if there is a better way so i don't have to wait for the object to be created.
You don't, if you use css selectors - the browser will handle it for you.
what do you mean by css-selectors? what do you mean with "you don't"? I'm just looking for the best way to add a classname to this <swfobject> now i'm simply using jquery with $('#vidoeID').addClass('classname'); and that works fine. Is there a better and faster (or more reliable) way of doing this or not?
I meant: If you use the argument parameter, you don't have to wait for the object to exist. Use attributes.styleclass="classname" and add the attributes object to your swfobject.embedSWF() call, as described in the documentation I linked to. A CSS selector is the expression used to select the element directly from a stylesheet (.classname, in your case), as opposed to selecting the element via JavaScript.
No, you just have to read that damn documentation! ;) It's really simple: var attributes = {}; attributes.styleclass="classname"; swfobject.embedSWF("http://www.youtube.com/v/ j_aFmziaRdU&amp;enablejsapi=1&amp;playerapiid=ytplayer_13", "ytplayer_13", "425", "365", "8", null, null, params, attributes);
|
-2

You can alter you swfobject.js file, and manually add it there. Or do a manual embed, versus SWFObject. Also, typically SWFObject is inserted into a container div, you should also be able to insert a class there.

Hope this helps. I think that's what you were asking, if not, my bad.

4 Comments

-1 because this is really not a helpful answer at all: It serves only one use-case (what if you had a website with many Flash objects and different style classes - would you create an individual swfobject.js for each one?), and it creates the impression that SWFObject can only be used in a very crude and unpractical way, creating stiff and unflexible HTML, which is exactly the problem it was meant to fix.
Moreover, swfobject replaces the container div with the flash object, so adding a class there does exactly nothing.
-1 for answering his question? Just because you consider it a crude answer, it still serves the purpose. Your answer is the better one, and it was there when I posted mine. I was providing an alternative. Just because you wouldn't use it, doesn't make it wrong.
That's true, but it doesn't make it right, either. I didn't give you -1 because you answered the question. I gave you -1, because it a) the answer isn't correct (the <div>part) and b) it isn't helpful (the rest, see explanation above). And obviously, someone else must have felt the same way about it, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.