Loading Dynamic Data into Flash - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Loading Dynamic Data into Flash

Description:

B? m n H? th?ng th ng tin Khoa C ng ngh? th ng tin. ?i h?c Khoa h?c ... L?y d? li?u th ng qua Flash Remoting. So s nh v k?t lu?n. T?ng ... li?u th ng qua ... – PowerPoint PPT presentation

Number of Views:347
Avg rating:3.0/5.0
Slides: 32
Provided by: mikech2
Category:
Tags: data | dynamic | flash | loading | thong

less

Transcript and Presenter's Notes

Title: Loading Dynamic Data into Flash


1
Loading Dynamic Data into Flash
  • Nguy?n Vi?t Thành
  • B? môn H? th?ng thông tin Khoa Công ngh? thông
    tin
  • Ð?i h?c Khoa h?c t? nhiên TpHCM
  • 22/03/2005

2
M?c l?c
  • T?ng quan M?c tiêu
  • L?y d? li?u t? file text
  • L?y d? li?u t? XML
  • L?y d? li?u t? CSDL
  • L?y d? li?u thông qua Flash Remoting
  • So sánh và k?t lu?n

3
T?ng quan M?c tiêu
  • Gi?i thi?u các cách ph? bi?n dùng d? l?y d? li?u
    cho Flash
  • Th?o lu?n và so sánh các cách này
  • K?t lu?n v? các tru?ng h?p s? d?ng cho m?i cách

4
Yêu c?u tiên quy?t
  • Ph?n m?m so?n th?o Flash Macromedia Flash MX
    2004
  • Ngôn ng? l?p trình server-side PHP
  • Co s? d? li?u MySQL
  • Component Action Script dành cho Macromedia Flash
    MX
  • B? cài d?t m? r?ng ph?c v? Action Script dùng cho
    PHP AMFPHP

5
D? li?u t? file text
  • Ð?nh d?ng d? li?u
  • keyvalue
  • key1value1key2value2key3value3
  • key1value1key2value2key1value3key2value4
  • VD MSSV9800659TenThanhMSSV9900123TenBinh
  • S? d?ng hàm LoadVars() ho?c LoadVariables() d?
    l?y d? li?u t? file text
  • Ví d? d?c m?t dòng d? li?u và nhi?u dòng d? li?u

6
D? li?u t? file text VD1
7
D? li?u t? file text VD1 (cont)
  • N?i dung d? li?u
  • TitleAnastasioCommentsThis is a nice
    guyImageanastasio.jpg
  • Source code
  • myData new LoadVars()
        myData.load("anastasio.txt")
        myData.onLoad function(success)
            if(success)             Title_txt.htmlT
    ext ""this.Title""             Comment
    s_txt.text this.Comments             holder_mc.
    loadMovie(this.Image)          else
    trace("Error loading data")     

8
D? li?u t? file text VD1 (cont)
9
D? li?u t? file text VD2
10
D? li?u t? file text VD2 (cont)
  • N?i dung d? li?u
  • Title0AnastasioComments0This is a nice
    guyImage0an1.jpgTitle1Anastasio on
    carComments1Here's Anastasio's
    carImage1an2.jpgcant2
  • Source code
  • myData new LoadVars()
  •  myData.load("anastasio2.txt")
  •  myData.ref this
  • myData.onLoad function(succes) if(succes)
        for(var i0 i
           this.ref"Title_txt"i.htmlText""thi
    s"Title"i"
    "        this.ref"Comments_txt
    "i.text this"Comments"i        this.ref"h
    older_mc"i.loadMovie(this"Image"i)     
    else trace("Error loading data")

11
D? li?u t? file text VD2 (cont)
12
D? li?u t? file XML
  • Ð?nh d?ng d? li?u tuân theo chu?n c?a file XML
  • Có DTD ho?c schema d? mô t? c?u trúc và ki?u d?
    li?u ch?a bên du?i
  • M?i tag m? s? có m?t tag tuong ?ng d? dóng
  • Các tag l?ng bên trong ph?i du?c dóng tru?c các
    tag bao bên ngoài
  • Duy?t tài li?u XML (phân c?p) d? l?y d? li?u c?n
    hi?n th?
  • Ví d?

13
D? li?u t? file XML VD
14
D? li?u t? file XML VD (cont)
  • N?i dung d? li?u
  • datatitle name CDATA REQUIRED(PCDATA)itle name"Anastasio"This is a nice
    guyan2.jpgtle name"Anastasio's car"Anastasio
    loves his caran1.jpgtitle

15
D? li?u t? file XML VD (cont)
  • Source code
  • myXML new XML() myXML.ignoreWhite true
    myXML.load("anastasio.xml") myXML.ref this
  •  myXML.onLoad function(succes)
            if(succes)             var root
    this.firstChild             nodes
    root.childNodes             for(var i0
    iis.ref"Title_txt"i.text nodesi.attributes.n
    ame                 subnodes
    nodesi.childNodes                 this.ref"Com
    ments_txt"i.text subnodes0.firstChild.toStri
    ng()                 this.ref"holder_mc"i.load
    Movie(subnodes1.firstChild.toString())
                          else trace("Error
    loading XML document")     

16
D? li?u t? file XML VD (cont)
17
D? li?u t? CSDL
  • Ð?nh d?ng d? li?u d? li?u du?c luu tr? trong các
    b?ng c?a m?t CSDL quan h?
  • S? d?ng m?t ngôn ng? server-side (ASP.NET, JSP,
    PHP) d? l?y d? li?u t? CSDL và tr? ra text d?nh
    d?ng (gi?ng tru?ng h?p l?y d? li?u t? file text)
  • Ví d? minh h?a dùng PHP và MySQL

18
D? li?u t? CSDL VD
19
D? li?u t? CSDL VD (cont)
  • N?i dung d? li?u
  • CREATE TABLE titles (ID int(11) NOT NULL
    auto_increment,Title varchar(255) NOT
    NULL,Comments mediumtext NOT NULL,Image
    varchar(255) NOT NULL,PRIMARY KEY (ID))
  • INSERT INTO titles VALUES ( '1', 'Anastasio',
    'This is a nice guy', 'an1.jpg')
  • INSERT INTO titles VALUES ( '2', 'In the car',
    'Here's Anastasio's car', 'an2.jpg')

20
D? li?u t? CSDL VD (cont)
  • Source code server-side
  • connect mysql_connect("localhost", "root",
    "root")         mysql_select_db("anastasio",
    connect)
  • result mysql_query("SELECT Title, Comments,
    Image FROM titles")
  • cant 0
  • while(rowmysql_fetch_array(result))
  •   echo "TitlecantrowTitleCommentscantr
    owCommentsImagecantrowImage"   
  • cant         
  •  echo "cantcant"

21
D? li?u t? CSDL VD (cont)
  • Source code Flash
  •   myData new LoadVars()         myData.ref
    this         myData.load("anastasio.php")
            myData.onLoad function()
                if(succes)                 for(var
    i0 iref"Title_txt"i.text this"Title_txt"i
                        this.ref"Coments_txt"i.tex
    t this"Coments_txt"i                     thi
    s.ref"holder_mc"i.loadMovie(this"Image"i)
                                  else
    trace("Error loading data")         

22
D? li?u t? file XML VD (cont)
23
D? li?u thông qua Flash Remoting
  • Là co ch? c?a Macromedia giúp Flash có th? truy
    c?p, th?c hi?n tr?c ti?p các ch?c nang thu?c phía
    server.
  • Không s? d?ng co ch? keyvalue, Flash s? d?ng AMF
    (ActionScript Message Format) d? trao d?i d?
    li?u.
  • C?n các b? h? tr? dành riêng cho ASP.NET, Java,
    PHP
  • Ví d? minh h?a dùng AMFPHP

24
D? li?u thông qua Flash Remoting VD
25
D? li?u t? CSDL VD (cont)
  • N?i dung d? li?u
  • CREATE TABLE titles (ID int(11) NOT NULL
    auto_increment,Title varchar(255) NOT
    NULL,Comments mediumtext NOT NULL,Image
    varchar(255) NOT NULL,PRIMARY KEY (ID))
  • INSERT INTO titles VALUES ( '1', 'Anastasio',
    'This is a nice guy', 'an1.jpg')
  • INSERT INTO titles VALUES ( '2', 'In the car',
    'Here's Anastasio's car', 'an2.jpg')

26
D? li?u t? CSDL VD (cont)
  • Source code server-side
  • class News              var dbhost
    "localhost"         var dbname "anastasio"
            var dbuser "root"         var
    dbpass ""                  function News()
                                 this-methodTable
    array(                 "getTitles" array(
    //selects all available Titles                 "d
    escription" "Returns avaible Category of
    books",                     "access"
    "remote", // available values are private,
    public, remote                 "returntype"
    "recordSet"                 )             )
            // Initialize db connection
            this-conn mysql_pconnect(this-dbhos
    t, this-dbuser, this-dbpass)
            mysql_select_db (this-dbname)
                     function getTitles()
                         return mysql_query("SELECT
    Title, Comments FROM titles")              

27
D? li?u t? CSDL VD (cont)
  • Source code Flash
  •  include "NetServices.as
  • include "NetDebug.as"
  •  NetServices.setDefaultGatewayUrl("http//localhos
    t/myFolder/gateway.php")
  •   var gatewayConnection
    NetServices.createGatewayConnection()
  • service gatewayConnection.getService("News",
    this)
  • getTitles_Result function(rs)   cant
    rs.getLength() //how many rows are in our
    recordset?   for(var i0 i   //Dinamyc put base on stage and fetch data to
    it        attachMovie("base", "base"i, i,
    _x200, _y(40i)40)        this"base"i.Tit
    le_txt.htmlText ""rs.getItemAt(i).
    Title"
    "        this"base"i.Comments_txt.
    text rs.getItemAt(i).Comments
                                 
     service.getTitles()

28
D? li?u t? file XML VD (cont)
29
So sánh và k?t lu?n
  • Ch?n cách luu tr? và l?y d? li?u nào cho phù h?p?
  • Tùy thu?c vào d? ph?c t?p và nhu c?u c?a ?ng d?ng
  • S? lu?ng nhi?u hay ít
  • C?u trúc don gi?n hay ph?c t?p
  • Tính thay d?i c?p nh?t thu?ng xuyên hay không
  • Yêu c?u v? t?c d? c?n truy xu?t nhanh hay ch?m
  • Tùy thu?c vào môi tru?ng tri?n khai ?ng d?ng

30
Tham kh?o
  • Tutorial, Loading data into Flash,
    www.flash-db.com, Jorge Solis, 2005
  • Tutorial, A Introduction to Flash Remoting,
    www.flash-db.com, Jorge Solis, 2005

31
Th?o lu?n
  • Q A
Write a Comment
User Comments (0)
About PowerShow.com