0

Ultilizando PHP e MYSQL no FLASH

criado por Renato Julios em 14/10/2005 7:19pm
Sempre tive receio de usar o flash em plicaçoes em que o cliente queria sites dinamicos, até que um dia não tive escapatoria e tive que aprender a fazer o flash exibir os dados do mysql.
Vendo a dificulde de se fazer este tipo de coisa resolvi montar este artigo que esplicara como você deve poder criar uma tabela no mysql e exibir seus resultados em um filme em flash.
Vamos la então.

1º. Abra o flash e crie um campo de texto dinamico e instacie-o de texto_html.
2º. Adicione um UIscrollBar e coloque na sua Target instance name a instancia texto_html.
3º. Adicione mais um quadro chave e digite o seguinte codigo AC.

CODE AC:
//----------------------------------------------------
stop();
// Diz ao flash para reconhecer acentos Gráficos
System.useCodepage = true;
// Função para Carregar o PHP dentro do flash
function carregar(){
// Objeto XML para buscar os dados no arquivo PHP
var texto = new XML();
texto.onData = function(html_no_flash){
texto_html.html = true;
texto_html.htmlText = html_no_flash;
}
//Entre as aspas duplas vc coloca a pagina em PHP
texto.load("dados.php");
}
carregar();
//-----------------------------------------------------

4º. Salve o aquivo e exporte como swf.

Agora vamos criar o codigo em PHP que vai se chamar dados.php

dados.php:
<?php
// Conecta ao banco de dados
$connect = mysql_connect("localhost","usuario","senha");
// Seleciona o banco de dados
$select = mysql_select_db("banco");
//comando SQL
$sql = "select texto from flash";
//Realiza o query
$query = mysql_query($sql);
// Salva o resultado em Arrays
$mais = mysql_fetch_array($query);
$roa = $mais[texto];
//Imprime o texto
echo $roa;
?>

5º. O proximo passo agora e criar a tabela onde colocaremos os dados a serem exibidos no filme em flash.

dados.sql
-- Estrutura da tabela `flash`
-- 

CREATE TABLE `flash` (
  `id` int(11) NOT NULL auto_increment,
  `texto` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

-- 
-- Extraindo dados da tabela `flash`
-- 

INSERT INTO `flash` VALUES (1, 'Supported HTML tags\r\nThis section lists the built-in HTML tags supported by Flash Player. You can also create new styles and tags using Cascading Style Sheets;\r\n\r\nAnchor tag (<a>)\r\nThe <a> tag creates a hyperlink and supports the following attributes:\r\n\r\nhref Specifies the URL of the page to load in the browser. The URL can absolute or relative to the location of the SWF file that is loading the page.\r\ntarget Specifies the name of the target window to load the page into.\r\nFor example, the following HTML snippet creates the link "Go home," which opens www.macromedia.com in a new browser window.\r\n\r\n<a href="../home.htm" target="_blank">Go home</a>\r\n\r\nYou can also define a:link, a:hover, and a:active styles for anchor tags by using style sheets.\r\n\r\nBold tag ()\r\nThe  tag renders text as bold. A bold typeface must be available for the font used to display the text.\r\n\r\nThis is bold text.\r\n\r\n--> exemple\r\n\r\nBreak tag (<br>)\r\nThe <br> tag creates a line break in the text field, as shown in this example:\r\n\r\nOne line of text<br>\r\nAnother line of text<br>\r\n\r\nFont tag (<font>)\r\nThe <font> tag specifies a font or list of fonts to display the text.\r\n\r\nThe font tag supports the following attributes:\r\n\r\ncolor Only hexadecimal color (#FFFFFF) values are supported. For example, the following HTML code creates red text.\r\n<font color="#FF0000">This is red text</font>\r\n\r\nface Specifies the name of the font to use. You can also specify a list of comma-separated font names, in which case Flash Player chooses the first available font. If the specified font is not installed on the playback system, or isn''t embedded in the SWF file, then Flash Player chooses a substitute font.\r\nExample:\r\n\r\n<font face="Times, Times New Roman">This is either Times or Times New Roman..</font>\r\n\r\nsize Specifies the size of the font, in pixels. You can also use relative point sizes (+2 or -4).\r\n<font size="24" color="#0000FF">This is green, 24-point text</font>\r\n\r\nImage tag (<img>)\r\nThe <img> tag lets you embed external JPEG files, SWF files, and movie clips inside text fields. Text automatically flows around images you embed in text fields. This tag is supported only in dynamic and input text fields that are multiline and wrap their text.\r\n\r\nList item tag (
  • )\r\nThe
  • tag places a bullet in front of the text that it encloses.\r\n\r\nGrocery list:\r\n
  • Apples
  • \r\n
  • Oranges
  • \r\n
  • Lemons
  • \r\n\r\nThe above code would render as follows:\r\n\r\nGrocery list:\r\n\r\n\r\n\r\n * Apples\r\n\r\n * Oranges\r\n\r\n * Lemons\r\n\r\n\r\n\r\nParagraph tag (<p>)\r\nThe <p> tag creates a new paragraph. It supports the following attributes:\r\n\r\nalign Specifies alignment of text within the paragraph; valid values are left, right, and center.\r\nclass Specifies a CSS style class defined by an TextField.StyleSheet object. (For more information, see Using style classes.)\r\nThe following example uses the align attribute to align text on the right side of a text field.\r\n\r\ntextField.htmlText = "<p align=''right''>This text is aligned on the right side of the text field</p>";\r\n\r\nThe following example uses the class attribute to assign a text style class to a <p> tag.\r\n\r\nvar myStyleSheet = new TextField.StyleSheet();\r\nmyStyleSheet.secreateTextField("test", 10, 0,0, 300,100);\r\ncreateTextField("test", 10, 0,0, 300,100);\r\ntest.styleSheet = myStyleSheet;\r\ntest.htmlText = "<p class=''body''>This is some body-styled text.</p>.";\r\n\r\nSpan tag (<span>)\r\nThe <span> tag is available only for use with CSS text styles. (For more information, see Formatting text with Cascading Style Sheets.) It supports the following attribute:\r\n\r\nclass Specifies a CSS style class defined by an TextField.StyleSheet object. For more information on creating text style classes, see Using style classes.\r\nText format tag (<textformat>)\r\nThe <textformat> tag lets you use a subset of paragraph formatting properties of the TextFormat class within HTML text fields, including line leading, indentation, margins, and tab stops. You can combine <textformat> tags with the built-in HTML tags.\r\n\r\nUnderline tag (<u>)\r\nThe <u> tag underlines the tagged text.\r\n\r\nThis text is <u>underlined</u>.\r\nThe above code would render as follows:\r\n\r\nThis text is underlined.\r\n\r\n');

    é isso ai espero que ajude alguem, é um artigo simples mas muito util.

    Por: Renato Campoy
    E-mail: renatocampoy@yahoo.com.br

    Comentários:

    Mostrando 1 - 1 de 1 comentários
    mto bom... finalmente um script que funciona de uma forma rápida e prática...parabéns...

    abraços
    22/02/2010 12:55pm (~14 anos atrás)

    Novo Comentário:

    (Você pode usar tags como <b>, <i> ou <code>. URLs serão convertidas para links automaticamente.)