Flash Widget

5 views
Skip to first unread message

agujaydedal

unread,
Jun 3, 2006, 5:39:00 PM6/3/06
to Google Web Toolkit
Hello,

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;
}
}

Mr. Monster

unread,
Jun 3, 2006, 6:15:43 PM6/3/06
to Google Web Toolkit
What I do to add flash is simply use HTML() object with the
<object></object> code added to it.

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.

IamRobe...@gmail.com

unread,
Jun 4, 2006, 12:01:38 AM6/4/06
to Google Web Toolkit
What you could do is create browser specific implementations. So
<object> is only used in IE, and <embed> in Firefox.

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

agujaydedal

unread,
Jun 4, 2006, 4:01:48 AM6/4/06
to Google Web Toolkit
I think that you do not have to do that because then you are creating
widgets coupled to the browser

Miroslav Pokorny

unread,
Jun 4, 2006, 5:54:13 AM6/4/06
to Google-We...@googlegroups.com
Perhaps you should add object to the dom and then append embed to object instead of attempting to add embed to object and then adding object to the dom.


On 6/4/06, agujaydedal <aguja...@gmail.com> wrote:

I think that you do not have to do that because then you are creating
widgets coupled to the browser







--
mP

Miroslav Pokorny

unread,
Jun 4, 2006, 5:54:28 AM6/4/06
to Google-We...@googlegroups.com
Perhaps you should add object to the dom and then append embed to object instead of attempting to add embed to object and then adding object to the dom.

On 6/4/06, agujaydedal <aguja...@gmail.com> wrote:

I think that you do not have to do that because then you are creating
widgets coupled to the browser







--
mP
Reply all
Reply to author
Forward
0 new messages