Foros del Web » Creando para Internet » Flash y Actionscript »

pasar variable externa a Flash

Estas en el tema de pasar variable externa a Flash en el foro de Flash y Actionscript en Foros del Web. Hola que tal... tengo un problema... yo tengo una animación flash en la cual necesito mostrar un texto animado, pero el valor del texto cambia ...
  #1 (permalink)  
Antiguo 06/01/2006, 20:45
 
Fecha de Ingreso: febrero-2005
Mensajes: 98
Antigüedad: 19 años, 2 meses
Puntos: 0
pasar variable externa a Flash

Hola que tal... tengo un problema... yo tengo una animación flash en la cual necesito mostrar un texto animado, pero el valor del texto cambia de acuerdo a la página a la que entro. Lo que hice fue llamar al SWF de la siguiente manera:

<param name="movie" value="animacion.swf?mostrar=textoquequieromostrar " />

Entonces genero un texto dinámico en el Flash y en variable le pongo el valor "mostrar"... todo me funciona bien... me muestra el texto, pero el gran problema es que por ese cambio de valor en la variable "mostrar" me carga nuevamente el flash... eso quiere decir que por cada sección que entre en la página me va a cargar el flash (y es el mismo) y eso genera lentitud... hay una manera de hacer lo q quiero pero evitando esta carga tantas veces?

Gracias
  #2 (permalink)  
Antiguo 07/01/2006, 01:48
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Otra manera de hacerlo seria no variar la carga del .swf, es decir, no enviar como parametro el texto, sino que internatmente, dentro del .FLA con objetos loadvars cargues desde un .ASP o .JSP o .PHP el texto para que se despliegue, o bien, accesando desde el .FLAH a la variable cargada en la page con un JAVASCRIPT.
  #3 (permalink)  
Antiguo 07/01/2006, 06:37
 
Fecha de Ingreso: febrero-2005
Mensajes: 98
Antigüedad: 19 años, 2 meses
Puntos: 0
Pero como cargaría del .FLA la variable del archivo .php, porque el valor del texto se genera de acuerdo al valor enviado por .GET al archivo .php... es decir que cuando estoy ejecutando el archivo .php recién ahí cargo el valor del texto que quiero mostrar en el SWF.
  #4 (permalink)  
Antiguo 07/01/2006, 09:02
Avatar de Mauri1  
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago de Chile
Mensajes: 558
Antigüedad: 21 años, 5 meses
Puntos: 0
Luego de las etiquetas <?php ?> coloca una variable &mensaje = <?php echo $el_mensaje; ?>

Luego en el flash carga la variable del php con loadVars()

Código:
cargar=new loadVars()
cargar.load("archivo.php")
cargar.onLoad=function(succes){
 if(succes){
  mensaje_txt.text=this.mensaje
 }else{
  mensaje_txt.text="Error"
 }
}
Con eso debería funcionarte.

  #5 (permalink)  
Antiguo 07/01/2006, 16:51
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
La idea mas o menos seria esta:

a) El php recibe el valor del campo

b) El php despliega el html incluyendo las tags para el flash como normalmente se hace

c) el php TAMBIEN inicializa un valor con JAVASCRIPT dentro del codigo HTML
(algo como:)
<script>
variable = <?valor dinamico?>
</script>


d) El Flash, recupera mediante comunicaccion con JAVASCRIPT la data del campo "variable", de esta manera estaras evitando la recarga del .swf con
<"archivo.swf?variable=xxxx>

A ver si esto te acomoda.
  #6 (permalink)  
Antiguo 07/01/2006, 17:42
 
Fecha de Ingreso: febrero-2005
Mensajes: 98
Antigüedad: 19 años, 2 meses
Puntos: 0
Entiendo lo que me quieres decir wwwmaster, entendiste la idea y sí, exactamente eso es lo que necesito... pero no soy muy bueno en actionscript, como podría llamar ese valor que está en javascript desde el SWF. Gracias
  #7 (permalink)  
Antiguo 09/01/2006, 11:32
 
Fecha de Ingreso: febrero-2005
Mensajes: 98
Antigüedad: 19 años, 2 meses
Puntos: 0
Alguna idea please?... cómo capturo ese valor del javascript desde el swf?
Gracias
  #8 (permalink)  
Antiguo 09/01/2006, 21:37
 
Fecha de Ingreso: febrero-2005
Mensajes: 98
Antigüedad: 19 años, 2 meses
Puntos: 0
Por favor, es urgente... cómo puedo capturar el valor del javascript desde el SWF?... creo que sólo eso es lo que me falta.

Saludos. Gracias
  #9 (permalink)  
Antiguo 09/01/2006, 22:08
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Con FLash 8:

Example
The following example calls the JavaScript function sayHello() in the HTML page that contains the SWF. The call is made by using the ExternalInterface.call() method.

import flash.external.*;

var greeting:String;
var btn:MovieClip = createButton(100, 30, 0xCCCCCC);
btn.onPress = function() {
greeting = String(ExternalInterface.call("sayHello", "browser"));
this.mcTxt.text = greeting; // >> Hi Flash.
}

function createButton(width:Number, height:Number, color:Number):MovieClip {
var depth:Number = this.getNextHighestDepth();
var mc:MovieClip = this.createEmptyMovieClip("mc_" + depth, depth);
var mcFmt:TextFormat;

mc.beginFill(color);
mc.lineTo(0, height);
mc.lineTo(width, height);
mc.lineTo(width, 0);
mc.lineTo(0, 0);

mcFmt = new TextFormat();
mcFmt.align = "center";
mcFmt.bold = true;

mc.createTextField("mcTxt", depth, 0, 0, width, height);
mc.mcTxt.text = "Call JS Function";
mc.mcTxt.setTextFormat(mcFmt);

return mc;
}


For the previous example to work properly, you should be copy and paste the following code into the containing HTML page. Unless the HTML page is hosted on a server, your browser may alert you with a security warning.

<script>
function sayHello(name) {
alert(">> Hello " + name + ".");
return ">> Hi Flash.";
}
</script>
  #10 (permalink)  
Antiguo 09/01/2006, 22:09
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
(fue tomado de la ayuda de Flash 8), si le das a la ayuda en tu version de Flash y buscas por el texto "javascript" o palabras similares, debiera mostrarte codigo como ese
  #11 (permalink)  
Antiguo 09/01/2006, 22:13
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Tambien con el FSCOMMAND:

Tal como lo parece decir el manual de la ayuda:
Usage 2: To use fscommand() to send a message to a scripting language such as JavaScript in a web browser, you can pass any two parameters in the command and parameters parameters. These parameters can be strings or expressions, and they are used in a JavaScript function that handles, or catches, the fscommand() function.

In a web browser, fscommand() calls the JavaScript function moviename_DoFScommand, which resides in the webpage that contains the SWF file. For moviename, supply the name of the Flash object that you used for the NAMEattribute of the EMBED tag or the ID property of the OBJECT tag. If you assign the SWF file the name myMovie, the JavaScript function myMovie_DoFScommand is called.

In the web page that contains the SWF file, set the allowScriptAccess attribute to allow or deny the SWF file's ability to access the web page. (You set this attribute in the HTML code that embeds the SWF file--for example, in the PARAM tag for Internet Explorer or the EMBED tag for Netscape.) When allowScriptAccess is set to "never", outbound scripting always fails. When allowScriptAccess is set to "always", outbound scripting always succeeds. When it is set to "sameDomain", scripting is allowed only from SWF files that are in the same domain as the web page. If allowScriptAccess is not specified in a web page, it defaults to "sameDomain" for Flash Player 8, and to "always" for previous versions of Flash Player.

When using this function, consider the Flash Player security model. For Flash Player 8, the fscommand() function is not allowed if the calling SWF file is in the local-with-file-system or local-with-network sandbox and the containing HTML page is in an untrusted sandbox. For more information, see the following:
  #12 (permalink)  
Antiguo 10/01/2006, 00:09
 
Fecha de Ingreso: febrero-2005
Mensajes: 98
Antigüedad: 19 años, 2 meses
Puntos: 0
Gracias a todos.

Usé el primer ejemplo que aparecen en esta dirección:

http://www.macromedia.com/es/support...cript_comm.htm

y funcionó lo que quería... pero ahora me surgió un problema quizás para mí algo menor... en el navegador Firefox no funciona.

Alguien tiene alguna idea? Gracias
  #13 (permalink)  
Antiguo 10/01/2006, 22:09
 
Fecha de Ingreso: febrero-2005
Mensajes: 98
Antigüedad: 19 años, 2 meses
Puntos: 0
Alguien sabe sobre este problema de incompatibilidad?
Gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:38.