Subj : void Viewport2D::testMe() To : netscape.public.mozilla.jseng From : =?ISO-8859-1?Q?R=E9my_Deslignes?= Date : Thu Jul 08 2004 06:37 pm Hi, I am currently having troubles while accessing to an HTMLEmbed element (a flash player in fact) within a loaded page : I can get the DOM object, *probably* can create the related JSObject, but I cannot get the SetVariable property ( which I can see with the DOM Inspector ) , neither call this function... I am probably doing somethin wrong while creating my JsContext... But I dont't know what !! If someone, on earth or below, can help me , I can assume that he / she would graduate a higher karma for this life and maybe for the next ones... Regards, nsresult rv; // gets the XPConnect component nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); // gets the document nsCOMPtr doc; webNav->GetDocument(getter_AddRefs(doc)) ; // gets the JSContext JSContext* cx; nsCOMPtr idoc = do_QueryInterface(doc); nsCOMPtr global; idoc->GetScriptGlobalObject(getter_AddRefs(global)); nsCOMPtr context; global->GetContext(getter_AddRefs(context)); cx = NS_REINTERPRET_CAST(JSContext*, context->GetNativeContext()); //GetContextFromDocument(idoc,&cx); nsCOMPtr element; doc->GetElementById(NS_LITERAL_STRING("myFlash"), getter_AddRefs(element)); nsCOMPtr childNodes; element->GetChildNodes(getter_AddRefs(childNodes)); PRUint32 length; childNodes->GetLength(&length); for (unsigned int i=0; i subNode; childNodes->Item(i,getter_AddRefs(subNode)); nsCOMPtr test; subNode->QueryInterface(NS_GET_IID(nsIClassInfo), getter_AddRefs(test)); nsCOMPtr HTMLEmbedElement = do_QueryInterface(subNode); if (HTMLEmbedElement) { nsCOMPtr s; test->GetHelperForLanguage(nsIProgrammingLanguage::JAVASCRIPT,getter_AddRefs(s)); nsCOMPtr helper(do_QueryInterface(s)); nsCOMPtr wrapper; rv = xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), subNode, NS_GET_IID(nsIDOMHTMLEmbedElement), getter_AddRefs(wrapper)); NS_ASSERTION(rv, ""); nsCOMPtr native_wrapper; rv = xpc->GetWrappedNativeOfNativeObject(cx, ::JS_GetGlobalObject(cx), subNode, NS_GET_IID(nsIDOMHTMLEmbedElement),getter_AddRefs(native_wrapper)); NS_ASSERTION(rv, ""); // nsCOMPtr wrapper; // xpc->GetWrappedNativeOfNativeObject(cx, ::JS_GetGlobalObject(cx), subNode, NS_GET_IID(nsIDOMNode),getter_AddRefs(wrapper)); if (wrapper) { JSObject *jsobj; if(NS_SUCCEEDED(wrapper->GetJSObject(&jsobj))) { helper->PostCreate(native_wrapper, cx, jsobj); jsval fval = OBJECT_TO_JSVAL(jsobj); jsval argv[3], retval; argv[0] = OBJECT_TO_JSVAL(jsobj); argv[1] = STRING_TO_JSVAL("myVar"); argv[2] = STRING_TO_JSVAL("test"); ------> /* ----ALWAYS GET JSVAL_VOID */ JS_GetProperty(cx,::JS_GetGlobalObject(cx) ,"SetVariable", &fval); if (fval!=JSVAL_VOID) { } ------> /* ----RETURN BUT DOES ANYTHING */ if (JS_CallFunctionName(cx, ::JS_GetGlobalObject(cx), "SetVariable", 3, argv, &retval)) { } } } } } .