Este tuto vai envolver Flash, ASP e Access, portanto é indispensável que saiba pelo menos o básico destes programas e linguagens. Chega de papo e vamos ao assunto:
1º Passo: Vamos criar o arquivo do Banco de Dados. Abra o Access e crie uma novo arquivo com o nome de data.mdb e uma tabela no modo design. Acrescente 4 itens, id com tipo de data Auto-numeração, nome com tipo de data Texto, data com tipo de data Texto e Texto com tipo de data Texto.
Dê o nome de notícias a esta tabela. Feche o Access.
2º Passo: Vamos criar o arquivo de conexão com o banco de dados. Abra o seu editor de ASP (pode ser o bloco de notas viu?) e digite os seguintes códigos:
<% Dim conexao set conexao = Server.CreateObject("ADODB.Connection") conexao.Open "provider=microsoft.jet.oledb.4.0;data source=" & server.MapPath("data.mdb") & "" %>
Salve o arquivo como conexao.asp
3º - Passo: Vamos criar o arquivo de administração, crie um novo arquivo no seu editor e acrescente as seguintes linhas:
<!--#include file="conexao.asp"--> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="top"> <table width="100%" border="0" bordercolor="#FF0000" bgcolor="#FF9999"> <tr> <td width="17%"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Data da notícia</strong></font></td> <td width="83%"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Notícia apresentada até o momento</strong></font></td> </tr> </table> <div align="left"></div> <table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF0000"> <% DSNtemp = conexao sqlstmt = "SELECT * FROM noticias ORDER BY id DESC" Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sqlstmt, DSNtemp, 3, 3 TotalRecs = rs.recordcount x = 0 For x = 1 to 9999 If rs.eof then Exit For Else data = rs("data") id = rs("ID") nome = rs("nome") link = "<a href='ver.asp?id=" & id & "'>" & data & "</a>" description = nome %> <tr> <td width="17%"><font face="Arial, Helvetica, sans-serif" size="2"> <% =link%> </font></td> <td width="83%"><font face="Arial, Helvetica, sans-serif" size="2"> <% =description%> </font></td> </tr> <% rs.MoveNext End If Next%> </table> <table> <tr> <td height="26" colspan=2 align=right><div align="left"><font size="2" face="Arial, Helvetica, sans-serif"><a href="apagar.asp">Apagar Notícia</a> | <a href="enviar.asp">Adicionar Notícia</a> </font></div></td> </tr> </table> </td> </tr> </table> <p> </p> </body> </html>
Salve este arquivo como admin.asp
4º Passo: Vamos criar o arquivo que visualiza as notícias (lembre que isto tudo faz parte do setor administrativo). Crie um novo arquivo no seu editor e acrescente as seguintes linhas:
<!--#include file="conexao.asp"--> <% dim privacy_section dim features dim f_name do_search = request("do_search") id = request.querystring("id") DSNtemp = conexao noticias = "SELECT * FROM noticias where id =" & id & " ORDER BY id DESC" Set rs = Server.CreateObject("ADODB.Recordset") rs.Open noticias, DSNtemp, 3, 3 TotalRecs = rs.recordcount data = rs("data") id = rs("id") nome = rs("nome") p1= rs("texto") description = p1 %> <TR> <TD style="{padding:6px;}"> <table width="100%" > <tr> <td width="17%" bgcolor="ff9999"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Exibindo <% =nome %> publicada em <% =data %> </strong></font></td> </tr> <input type=hidden name="StateID3" value="<% =StateID %>"> </table> <table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#FF0000" > <tr> <td width="17%"><font face="Verdana" size="2"> <% =description%> </font> </td> </tr> </table> <table > <tr> <td height="26" colspan=2 align=right><div align="left"><font size="2" face="Arial, Helvetica, sans-serif"><a href="apagar.asp">Apagar Notícia</a> | <a href="enviar.asp">Adicionar Notícia</a> </font></div></td> </tr> </table> <p> <div align="center"> <center> </center> </div> <p>
Salve o arquivo como ver.asp
5º Passo: Vamos criar o arquivo que faz a noticia e a envia para o Banco de Dados, crie um novo arquivo no seu editor e acrescente as seguintes linhas:
<!--#include file="conexao.asp"--> <% dim privacy_section dim features dim f_name do_search = request("do_search") %> <% 'Declaração de variáveis Dim texto Dim data Dim nome inputnum = request.querystring("inputnum") if IsEmpty(inputnum) or inputnum = "" then %> <script language=JavaScript> function preview1(){ if (form.nome.value == ""){ div1.innerHTML = "<p align=center><br><br><br><br>Um título para sua notícia é recomendado.<br><br>Coloque um título para sua notícia e pré-visualize novamente.</p>"} else{ div1.innerHTML = "<B>"+ form.nome.value + " - " + form.data.value + "</b><br><br>" + form.texto.value} } function nomechange(){ form.nome.value = form.nome2.value } </script> <TR> <TD style="{padding:6px;}"> <table width="100%" cellpadding="0" cellspacing="0" bgcolor="ff9999"> <tr> <td width="17%"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Adicionar notícia</strong></font></td> </tr> </table> <form id=form method="POST" action="enviar.asp?inputnum=1"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="188" align="left" valign="top"> <table width="550" height="168" border="1" cellpadding="5" cellspacing="0" bordercolor="#FF0000"> <tr> <td width="9%" height="119"> <p><font color="#FF9999" face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="2">Texto:</font></strong></font></p></td> <td width="91%" align="left"><font size="2" face="Arial"><font size="2" face="Arial"> <textarea name="texto" cols="47" rows="8" class="caixa_texto" style="border-style: solid; border-width: 2"></textarea> </font></font></td> </tr> <tr> <td height="23"><strong><font color="#FF9999" size="2" face="Verdana, Arial, Helvetica, sans-serif"> Título:</font></strong></td> <td align="left"> <input name="nome" type="text" class="caixa_texto" size="38" maxlength="255"> </td> </tr> <tr> <td height="24"><strong><font color="#FF9999" size="2" face="Verdana, Arial, Helvetica, sans-serif">Data:</font></strong></td> <td align="left"><font face="Arial" size="2"> <input name="data" type="text" value="<% =Date %>" size="13"> </font></td> </tr> </table> </td> </tr> </table> <div align="left"><br> <font face="Arial" size="2"><a onclick="preview1()" name="prev" href="#prev"><font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Pré-visualizar</font></a><br> <br> </font> </div> <div align="center"> <center> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td><table width="500" border="1" cellpadding="3" cellspacing="0"> <tr> <td width="100%" align="left"><div id="div1" style="width: 715; height: 221"> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font></div></td> </tr> </table></td> </tr> </table> <p> <div align="left"><br> <font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Clique em 'Enviar' para colocar esta notícia no ar. <br> Caso você queira alterá-la, <a href="#top">clique aqui. </a> </font><br> <br> <input name="B1" type="submit" value="Enviar"> </div> </center> </div> </form> <table> <tr> <td height="26" colspan=2 align=right><div align="left"><font size="2" face="Arial, Helvetica, sans-serif"><a href="apagar.asp">Apagar Notícia</a> | <a href="enviar.asp">Adicionar Notícia</a> </font></div></td> </tr> </table> <% else data1 = Now() nome = request.form("nome") data = request.form("data") texto = request.form("texto") nome = Replace(request.form("nome"), "'", "''") data = request.form("data") texto = Replace(Request.Form("texto"), "'", "''") 'Conexão com o banco de dados set con = Server.CreateObject("ADODB.Connection") DSNtemp = conexao con.Open DSNtemp noticia = "INSERT INTO noticias (nome,data,texto)" noticia = noticia & " VALUES (" noticia = noticia & "'" & nome & "'," noticia = noticia & "'" & data & "'," noticia = noticia & "'" & texto & "'" noticia = noticia & ")" Set rs = con.execute(noticia) %> <table> <tr> <td> </td> </tr> </table> <br> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr bgcolor="#999999"> <td height="1" bgcolor="#999999"></td> </tr> <tr> <td height="60" align="center" valign="top"> <p align="center"> </p> <p align="center"><font color="#FF9999" size="4" face="Verdana">Sua notícia foi adicionada com sucesso!</font><font face="Verdana" size="4"><br> </font><font face="Verdana" size="2"><br> </font></p> </td> </tr> </table> <br> <table> <tr> <td height="26" colspan=2 align=right><div align="left"><font size="2" face="Arial, Helvetica, sans-serif"><a href="admin.asp">Página Inicial</a> | <a href="enviar.asp">Adicionar Notícia</a> </font></div></td> </tr> </table> <br> <div align="left"> <%end if%> </div> <p> <div align="center"> <center> </center> </div> <p>
Salve o arquivo como enviar.asp
6º Passo: Agora criaremos o arquivo que apaga as mensagens que não são mais desejadas.
<!--#include file="conexao.asp"--> <% dim features dim f_name dim data dim link dim id dim nome do_search = request("do_search") %> <% flag = request.querystring("flag") if flag = 1 then If IsEmpty(request.form("id")) then response.write "<br><br><br><br><br><br><p align=center>" response.write "<table border=1 cellpadding=3 cellspacing=0 width=423 bordercolor=#006699><tr><td width=415 bgcolor=#00ccff> <p align=center><font face=Verdana size=2 color=#003399>Erro</font></p></td></tr>" response.write "<tr><td width=415 bgcolor=#FFFFFF><p align=center><font face=Verdana size=2 color=#000000>Se você quer deletar alguma notícia" response.write " selecione uma caixa de seleção, em seguida clique em apagar.</font></p></td></tr></table>" response.end End If set rs = nothing id = request.form("id") set con = server.createobject("ADODB.Connection") DSNtemp = conexao con.Open DSNtemp For each record in request("id") apagar = "DELETE * from noticias WHERE ID=" & record Set RS = con.execute(apagar) Next response.Redirect("apagar.asp") end if %> <TR> <TD style="{padding:6px;}"> <form method="POST" action="apagar.asp?flag=1"> <div align="left"><br> <table width="100%"> <tr bgcolor="ff9999"> <td width="7%" height="19" align="center"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong> Apagar</strong></font></td> <td width="14%"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Data da notícia</strong></font></td> <td width="79%"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Notícia apresentada até o momento</strong></font></td> </tr> </table> <% set rs = nothing DSNtemp=conexao sqlstmt = "SELECT * FROM noticias ORDER BY id DESC" Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sqlstmt, DSNtemp, 3, 3 TotalRecs = rs.recordcount x = 0 For x = 1 to 9999 If rs.eof then Exit For Else data = rs("data") id = rs("ID") nome = rs("nome") link = "<a href='ver.asp?id=" & id & "'>" & data & "</a>" description = nome %> <table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#FF0000" > <tr> <td width="7%" align="center"> <font size="2" face="Arial, Helvetica, sans-serif"> <input name="ID" type="checkbox" value="<% =id %>"> </font></td> <td width="14%"><font face="Arial, Helvetica, sans-serif" size="2"> <% =link%> </font> </td> <td width="79%"><font face="Arial, Helvetica, sans-serif" size="2"> <% =description%> </font></td> </tr> </table> <% rs.MoveNext End If Next%> <table width="199" > <tr> <td width="100%" height="26" align=right> <div align="left"> <input name="submit" type="submit" id="submit" value="Apagar"> </div></td> </tr> <tr align="left" valign="baseline"> <td height="20"><font size="2" face="Arial, Helvetica, sans-serif"><a href="admin.asp">Página Inicial </a> | <a href="enviar.asp">Adicionar Notícia</a> </font></td> </tr> </table> </div> </form> <div align="center"> <center> </center> </div>
Salve este arquivo como apagar.asp
7º Passo: Após criados os arquivos administrativos, vamos criar o arquivo que manda os dados para o Flash.
<%@Language="VBScript"%> <% Option Explicit Dim oRS, oConn, strSQL Dim noticia Set oConn = Server.CreateObject("ADODB.Connection") Set oRS = Server.CreateObject("ADODB.Recordset") oConn.Open "provider=microsoft.jet.oledb.4.0;data source=" & server.MapPath("data.mdb") & "" strSQL = "SELECT * FROM noticias ORDER BY data DESC " oRS.Open strSQL, oConn, 2, 3 ' Se não for encontrado nenhuma notícia, ele retorna um valor falso para o Flash If oRS.EOF Then Response.Write "sucesso=False" ' Caso o contrário, ele retorna um valor True juntamente com os dados das notícias Else Response.Write "sucesso=True¬icia=" Do While Not oRS.EOF noticia = noticia & oRS ("nome") & vbCr noticia = noticia & oRS ("data") & vbCr noticia = noticia & oRS ("texto") & vbCr oRS.MoveNext Loop End If oRS.Close Set oRS = Nothing oConn.Close Set oConn = Nothing Response.Write Server.URLEncode(noticia) %>
Salve este arquivo como flash.asp
8º Passo: Agora vamos criar o arquivo Fla, Abra o flash e crie um novo documento.
- Crie duas Camadas (Ações e Layout). Na 1ª Frame da camada ações declare as seguinte variáveis:
system.useCodepage = true; noticia = ""; sucesso = "";
-Agora adicione na camada layout um pequeno texto (ex. Carregando noticias). Adicione frames até a 5ª frame.
- Na 2ª Frame da camada ações, adicione a seguinte linha:
loadVariablesNum("flash.asp", 0, "POST");
É ela quem vai carregar as variáveis enviadas pelo arquivo flash.asp.
- Na 3ª Frame da camada ações adicione:
if(sucesso ne ""){ if(sucesso eq "False"){ gotoAndPlay(5); }else{ gotoAndStop(6); } }
Enquanto o arquivo flash.asp não retornar um valor True para o flash, ele vai ficar "carregando notícias".
-Na 5ª Frame adicione um gotoAndPlay(3);
-Na 6ª Frame um stop();
-E por fim na 6ª Frame da camada layout, crie um campo de texto dinâmico com uma variável noticia. Adicione uma barra de rolagem e pronto! Basta publicar o seu filme flash num servidor com suporte a asp e vc tem o seu sistema de notícias.
Espero que este tuto seja útil para o desenvolvimento da galera.
At's