Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/03/2009, 11:50
Avatar de Lynxcraft
Lynxcraft
 
Fecha de Ingreso: noviembre-2007
Ubicación: yecla murcia
Mensajes: 1.346
Antigüedad: 17 años, 2 meses
Puntos: 51
crear un elemento con funcion return

hola amig@s me vais a tener que disculpar la ignorancia ya que no tengo ni idea si esto se puede hacer ..(el flash me lo permite pero a qui no se XDXD).
bueno tengo este codigo

Código PHP:
<script language="javascript">
function 
CreaObjSwf() { 
      
      var  
ElObjtInEr=document.createAttribute('div');
      
ElObjtInEr.appendChild(document.createTextNode('Texto Que tiene que aparecer en un nuevo Div'));
      return 
ElObjtInEr;
}
function 
reemplazar(textarea){
    var 
nuevoSWF=CreaObjSwf();
    if(
typeof textarea == 'string'textarea document.getElementById(textarea);  //Obtenemos el elemento textarea
    
var divdocument.createElement('div');       //Creamos un div sin nada
    
div.style.width textarea.offsetWidth+'px';       //Ajustamos la anchura
    
div.style.height textarea.offsetHeight+'px';        //Ajustamos la altura 
    
div.style.border '1px solid red';             //Solo para poder verlo..
    
textarea.parentNode.replaceChild(div,textarea); //Reemplazamos el textarea
    
div.appendChild(nuevoSWF)
    
};
</script> 
Bueno, la funcion reemplazar crea un div vació y remplaza un area de texto hasta ahí va todo perfecto pero ahora quiero crear otro div con la función CreaObjSwf dicha función me devuelve el nuevo div que contiene un texto , el caso que no funciona no se si se puede devolver los valores del nuevo elemento a través de return
la cuestión de todo esto es que el código realmente lo tengo asi
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>Editor Cfx</title>

</
head>
<
script language="javascript">
var 
isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true false;
var 
isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true false;
var 
isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true false;
function 
CreaParam(objCont,params){
    for (
i=0;i<params.length;i=i+2){
        var 
newParm=document.createElement('param');
        
newParm.name=params[i];
        
newParm.value=params[i+1];
        
objCont.appendChild(newParm);
    }
}
function 
ValoresExt(srcext)
{
  if (
src.indexOf('?') != -1)
    return 
src.replace(/?/, ext+'?'); 
  else
    return 
src ext;
}
function 
CreaObjSwf(nombre,dirancho alto 

     
dir=ValoresExt(dir'swf');
  
  if (
isIE && isWin && !isOpera)
  {
     var 
ElObjtIn=document.createElement('object'); 
     
ElObjtIn.classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ;
     
ElObjtIn.codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ;
     
ElObjtIn.width=ancho;
     
ElObjtIn.height=alto ;
     
ElObjtIn.id="CfxEditorObj";
     
ElObjtIn.align="middle";
     var 
ElementParam=new Array(
                                
"allowScriptAccess" ,"sameDomain",
                                
"allowFullScreen""false"
                                
"movie"dir,
                                 
"quality","high",
                                
"bgcolor" "#000000"
                                
);
    
CreaParam(ElObjtIn,ElementParam);
    
    var 
str=document.createElement('embed');
    
str.src=dir;
    
str.quality="high";
    
str.bgcolor="#000000" ;
    
str.width=ancho ;
    
str.height=alto ;
    
str.name=nombre ;
    
str.align="middle" ;
    
str.allowScriptAccess="sameDomain";
    
str.allowFullScreen="false" ;
    
str.type="application/x-shockwave-flash";
    
str.pluginspage="http://www.macromedia.com/go/getflashplayer" ;
    return  
ElObjtIn;
  }else{
      
    
ElObjtInEr=document.createAttribute('div');
      
ElObjtInEr.appendChild(document.createTextNode('Navegador no Compatible Con CfxEditor'));
      return 
ElObjtInEr;
 }

}
function 
reemplazar(textarea){
    var 
nuevoSWF=CreaObjSwf('editorCfx','editorCfx',500,600);
    if(
typeof textarea == 'string'textarea document.getElementById(textarea);  //Obtenemos el elemento textarea
    
var divdocument.createElement('div');       //Creamos un div sin nada
    
div.style.width textarea.offsetWidth+'px';       //Ajustamos la anchura
    
div.style.height textarea.offsetHeight+'px';        //Ajustamos la altura 
    
div.style.border '1px solid red';             //Solo para poder verlo..
    
textarea.parentNode.replaceChild(div,textarea); //Reemplazamos el textarea
    
div.appendChild(nuevoSWF)
    
};



</script>
<body>
<p>
  <textarea id="tes" name="texto" cols="50" rows="20"></textarea>
  <input name="Boton" type="button" value="Boton"  onclick="reemplazar('tes');"/>
</body>
</html> 
y como el java tiene lo malo de no decir donde esta exactamente el fallo no tengo ni idea si esta bien programado o no XDXDXDXD
PD:Me pueden recomendar un buen programa de JavaScrit donde tenga un debug del código porque asi estoy dando pasos de ciego XDXD
__________________
Sobran las ideas cuando faltan ganas de trabajar en ellas
Lynxcraft

Última edición por Lynxcraft; 06/03/2009 a las 12:06