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...


OR

Is there another way to call methods exported by an embed object without having to 
compile a .idl file ( which I d'on't actually have for Macromedia Flash ) ?


Regards,

        nsresult rv;
        // gets the XPConnect component
    nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
    // gets the document
    nsCOMPtr<nsIDOMDocument> doc;
    webNav->GetDocument(getter_AddRefs(doc)) ;
    // gets the JSContext
    JSContext* cx;
    nsCOMPtr<nsIDocument> idoc = do_QueryInterface(doc);
    nsCOMPtr<nsIScriptGlobalObject> global;
    idoc->GetScriptGlobalObject(getter_AddRefs(global));
        nsCOMPtr<nsIScriptContext> context;
        global->GetContext(getter_AddRefs(context));
        cx = NS_REINTERPRET_CAST(JSContext*, context->GetNativeContext());

    //GetContextFromDocument(idoc,&cx);

    nsCOMPtr<nsIDOMElement> element;
    doc->GetElementById(NS_LITERAL_STRING("myFlash"), getter_AddRefs(element));
    nsCOMPtr<nsIDOMNodeList> childNodes;
    element->GetChildNodes(getter_AddRefs(childNodes));
    PRUint32 length;
    childNodes->GetLength(&length);
    for (unsigned int i=0; i<length;i++)
    {
        nsCOMPtr<nsIDOMNode> subNode;
        childNodes->Item(i,getter_AddRefs(subNode));
        nsCOMPtr<nsIClassInfo> test;
        subNode->QueryInterface(NS_GET_IID(nsIClassInfo), getter_AddRefs(test));

        nsCOMPtr<nsIDOMHTMLEmbedElement> HTMLEmbedElement = do_QueryInterface(subNode);
        if (HTMLEmbedElement)
        {

            nsCOMPtr<nsISupports> s;
            
test->GetHelperForLanguage(nsIProgrammingLanguage::JAVASCRIPT,getter_AddRefs(s));
            nsCOMPtr<nsIXPCScriptable> helper(do_QueryInterface(s));

            nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
            rv = xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), subNode,
                                    NS_GET_IID(nsIDOMHTMLEmbedElement), 
getter_AddRefs(wrapper));
            NS_ASSERTION(rv, "");

            nsCOMPtr<nsIXPConnectWrappedNative> native_wrapper;
            rv = xpc->GetWrappedNativeOfNativeObject(cx, ::JS_GetGlobalObject(cx), 
subNode,
                                    
NS_GET_IID(nsIDOMHTMLEmbedElement),getter_AddRefs(native_wrapper));
            NS_ASSERTION(rv, "");

            // nsCOMPtr<nsIXPConnectWrappedNative> 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))
                    {
                    }
                }
            }
        }
    }

_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to