I'm try to create a flash widget. I would like the widget will be valid
in Internet Explorer and FireFox. Too I would like don't have to
activate the control in Internet Explorer.
At the end of the message I attach the code I am use.
Can somebody tell me if this is the best option to do that?, I think
that I would have to extend the DOM and DOMImpl object but I don' t
know very well.
I don't not why but when I try to add the embed element in the object
element the next exception is thrown.
[WARN] Exception thrown into JavaScript
java.lang.RuntimeException: JavaScript method
'@com.google.gwt.user.client.impl.DOMImpl::appendChild(Lcom/google/gwt/user/client/Element;Lcom/google/gwt/user/client/Element;)'
threw an exception
at
com.google.gwt.dev.shell.ie.ModuleSpaceIE6.invokeNative(ModuleSpaceIE6.java:394)
at
com.google.gwt.dev.shell.ie.ModuleSpaceIE6.invokeNativeVoid(ModuleSpaceIE6.java:283)
at
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:127)
at
com.google.gwt.user.client.impl.DOMImpl.appendChild(DOMImpl.java:27)
at com.google.gwt.user.client.DOM.appendChild(DOM.java:64)
Caused by: com.google.gwt.core.client.JavaScriptException: JavaScript
Error exception: Invalid argument.
public class Flash extends Widget
{
private Element object;
private Element embed;
public Flash() {
object = DOM.createElement("object");
DOM.setAttribute(object, "classid", "...");
DOM.setAttribute(object, "codebase", "...");
embed = DOM.createElement("embed");
DOM.setAttribute(embed, "type", "...");
DOM.setAttribute(embed, "pluginspace", "..." );
---> DOM.appendChild(object,embed);
setElement(object);
}
public void setMovie(String movie) {
setParameter("movie", movie);
DOM.setAttribute(embed, "src", movie);
}
public String getMovie() {
return DOM.getAttribute(embed, "src");
}
public void setFlashVars(String flashVars) {
setParameter("FlashVars", flashVars);
DOM.setAttribute(embed, "FlashVars", flashVars);
}
public String getFlashVars() {
return getParameter("FlashVars");
}
private void setParameter(String name,String value) {
Element param = findParam(name);
if (param!=null) {
DOM.setAttribute(param,"value",value);
}
else
{
param = DOM.createElement("param");
DOM.setAttribute(param,"name",name);
DOM.setAttribute(param,"value",value);
DOM.appendChild(object, param);
}
}
private String getParameter(String name) {
Element param = findParam(name);
return (param!=null) ? DOM.getAttribute(param,"value") : null;
}
private Element findParam(String name) {
Element element = object;
Element child;
for(int i=0; i < DOM.getChildCount(element); i++)
{
child = DOM.getChild(element,i);
if(DOM.getAttribute(child,"name").equals(name))
{
return child;
}
}
return null;
}
}
Since IE uses <object> and FF uses <embed> thats inside the <object> to
target the flash, I give unique IDs to both <object> and <embed> and
then use try{}catch(){} to get the flash itself.
Take a look at the DOM implementation in the gwt-user jar, or check out
my implementation of PNGImage in the distribution at the URL below.
http://gwtwidgets.blogspot.com/2006/05/announce-gwt-widget-library-002.html
For PNGImage in IE I create a <span>, in all other browser it is an
<img>.
Rob
I think that you do not have to do that because then you are creating
widgets coupled to the browser
I think that you do not have to do that because then you are creating
widgets coupled to the browser