Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 978
  • Last Modified:

Loading dynamic text/content - Soccer Livescore

Hi there

I am developing a soccer live-score website by using php. The design is such the way when these is scoring, a new small window would be opened with a flash(ver6) curtain open slowly apart and show the score at the back loaded dynamically.

My design and critical problem is;
The flash loaded the dynamic result from a text file updated by my php script. However, the design would not work when there are concurrent users(and it will ofcourse) access my website. It is because the file will be opened and write concurrently, and therefore it corrupted at the end.

I have an idea where an unique text file will be opened to each user accessing to my website, thus to avoid the corruption. But the Flash seems accept one URL(my text file) only according to the MX FLASH, am I right?

In the Actions-Frame
Actions->Browser/Network->loadVariables

URL: text.txt  (this is the problem)
Location: Level
Variables: Send using GET

In the properties
-Dynamic text
-Var:datavalue


In the text.txt;
datavalue=UEFACL 3' MANUTD 1-0 JUVENTUS;    


Question;
How can I solve the problem with this design? I am quite new to MX FLASH, any better solution will be appreciated!

Thanks

Gary
0
garytan
Asked:
garytan
  • 10
  • 6
  • 2
1 Solution
 
rascalpantsCommented:
can you explain this problem further:

"The flash loaded the dynamic result from a text file updated by my php script. However, the design would not work when there are concurrent users(and it will ofcourse) access my website. It is because the file will be opened and write concurrently, and therefore it corrupted at the end."

I don't think there is any problem with multiple users accessing the swf...

you should just have flash connect to the php file and have that file just echo the score in the following format:

team1score=2&tema2score=4&

I am not sure why you are trying to use a php page AND a txt page...  As long as the output is in the above format, Flash can read in the variables...

You can probably just use a looping movieclip that constantly checks the php page with a loadVariables() in one of the frames...


in your code above:

datavalue=UEFACL 3' MANUTD 1-0 JUVENTUS;  


it should look like this:


datavalue=UEFACL 3' MANUTD 1-0 JUVENTUS&


you should probably seperate the variables like this:

league=UEFACL 3&team1=MANUTD&team1score=1&team2=JUVENTUS&team2score=0&


let me know if you have any questions...


rp
0
 
garytanAuthor Commented:
Hi rp,

In the URL, we put:-
livescore.php?scorea=1&scoreb=2&teama=120&teamb=200&language=chinese

In the livescore.php file will read the team name base on the team index (120 and 200) and the language user selected.

At the end of the php file, we did this

echo $team_name_a_chinese;
echo $team_name_b_chinese;
echo $scorea;
echo $scoreb;

We tried this out but doesnot work.

Please comment,
Gary
0
 
henrywwCommented:
hi gary,

i don't quite understand ur original question....
"be opened and write concurrently"
where does the write file come in??
 
but for the second part, like rp said, u should use output the vars like

echo "teamAname=".$team_name_a_chinese."&";
echo "teamBname=".$team_name_b_chinese."&";
echo "scorea=".$scorea."&";
echo "scoreb=".$scoreb;

so the output from the php will look like

teamAname=XYZinCHINESE&teamBname=ABCinCHINESE&scoreA=1&scoreB=2

becareful if u are printing chars in BIG5/GB, & make sure u escape all the chars before sending, the "&" char in the chinese text is what u have to watch out for.

cheers


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
garytanAuthor Commented:
hi henry

you and rp's idea seem to be good. Another problem here is,
the flash didnt display my chinese character, I am not quite sure your suggestion about chinese character here.

The php output below looks ok, but flash output failed.

teamAname=JUVENTUS&teamBname=ÂüÁª(MAN UTDinCHINESE)&scoreA=1&scoreB=2


gary
0
 
garytanAuthor Commented:
Hi henry and rp,

Forgive me for not be able to express my problem in details... let me do it again.

I am developing a flash using Flash MX, named livescore.swf

It will be called by livescore.php. In livescore.php it will read the database to check
if there is any new score since last refresh.

For e.g. today has 3 match

1. ManU vs Liv
2. Chel vs Leeds
3. News vs Ars

If there is a new score (ManU 1-0 Liv), the livescore.php will launch livescore.swf in a new window.

In the livescore.swf, it will display the dynamic text, in this case ManU 1-0 Liv

In livescore.fla, i have created 3 objects:

1. HomeTeam
2. Score
3. AwayTeam

I also set

URL:livescore_data.php?teama=120&teamb=121&score=1-0&lang=english
Location: Level
Variables: Send using GET

In the livescore_data.php

<?php
     
     /* Set index */
     $teama_id  = trim($_GET['a']);
     $teamb_id  = trim($_GET['b']);
     $score = trim($_GET['s']);
     $override_session_curr_language = $_GET['lang'];
     
     /* this will retrieve the team name (english or chinese) */
     include('../lib/get-team-caption-cacher.php');
     
     echo "field1=".$cached_teama_name."&";
     echo "filed2=".$score."&";
     echo "field3=".$cached_teamb_name."&";
?>

My questions:
1. How can the livescore.php pass the 3 dynamic values (TeamA_Index, to livescore.swf? Currently for my
testing, i hardcoded the 3 values in the URL in livescore.fla.

2. when the user language = chinese, i want the livescoredata.php to generate the field1, field3 (team names) in chinese, does my code ok?
I understand that chinese character is double bytes, and the text generated by php will be single byte plain text....

Many thanks,
Gary
0
 
garytanAuthor Commented:
Hi all,

Can anyone please help? This problem cost my project delayed....

SOS....

Gary
0
 
garytanAuthor Commented:
Hi all,

Can anyone please help? This problem cost my project delayed....

SOS....

Gary
0
 
henrywwCommented:
sorry gary,

i can give u a hand later tonight, but i am going out now and...

where are u? which time zone are u in ...
i am in HK - GMT +8

i should be back at 11pm ...

send me the files - PHP & FLA

and i will see what i can do for u ..
cheers

my email -
henryww@yahoo.com

cheers
0
 
henrywwCommented:
Hi Gary,

1. How can the livescore.php pass the 3 dynamic values (TeamA_Index, to livescore.swf? Currently for my
testing, i hardcoded the 3 values in the URL in livescore.fla.

"the livescore.php will launch livescore.swf in a new window."

if i understand u correctly, u have a main page call livescore.php and checks for new scores, and the livescore.fla(swf) is a movie in the popup window to show new score

so when u popup the window, u have something like
URL:livescore_data.php?teama=120&teamb=121&score=1-0&lang=english for the url ... then u want to pass the values to the swf. correct?


BUT THEN ...
Where is 'a', 'b' & 's' come from?

<?php
    /* Set index */
    $teama_id  = trim($_GET['a']);
    $teamb_id  = trim($_GET['b']);
    $score = trim($_GET['s']);
    $override_session_curr_language = $_GET['lang'];
   
    /* this will retrieve the team name (english or chinese) */
    include('../lib/get-team-caption-cacher.php');
   
    echo "field1=".$cached_teama_name."&";
    echo "filed2=".$score."&";
    echo "field3=".$cached_teamb_name."&";
?>

i still don't quite understand the complete logic, anywaay , where is the swf exactly?  



************
CASE 1 - Assume u have a popWindow call myFlash.php
and when livescore.php detects a new score, it open myFlash.php.

now u have a livescore_data.php which will print the result as in field1=NAME_A&field2=1-1&field3=NAME_B

in ur livescore.swf
//frame 1
loadVariables("livescore_data.php");

//frame 2
//then u can make reference to the variables

// example
MyTeamA= field1;
MyTeamB =field3;
theScore = field2;
// ... etc

but u have to make sure the values are loaded before doing anything with them. if u are simply making ur TEXTBOX variable to refer to field1, field2, field3 then that's fine

case 2
if u want to pass values the flash using html, add the following line to the flash object (html)

<OBJECT classid= .. .... ... ..
<param name="FlashVars" value="field1=123&field2=234&field3=abc">
<EMBED .. .. .. .. FlashVars="field1=123&field2=234&field3=abc"></EMBED>
</OBJECT>

using php <? echo ?> to paste the values for u.

*************


2. when the user language = chinese, i want the livescoredata.php to generate the field1, field3 (team names) in chinese, does my code ok?
I understand that chinese character is double bytes, and the text generated by php will be single byte plain text....


now this is a tricky one, it depends on the source, where do u get ur TEXT (chinese) from? and are they unicode or big5/GB encoded? do u know?

if the text is unicode and from database (or a text file) then u will have to have MX to be able to show them correctly. otherwise, if they are big5 or GB encoded, that's fine, make sure u escape the names in chinese before passing it to the URL string. and unescape in flash to display it. however, not all chinese char can be displayed properly.

my suggestions will be, if u are not dealing with many different names, then make the individual names of teams as movieclips and show them using the index value. this is the ONLY way for now u can guarantee all chinese chars are displayed properly.

cheers
0
 
henrywwCommented:
oh sorry ... one more thing, if the selected language=chinese,

make sure u change the popup window/html char encoding

<META http-equiv="Content-Type" content="text/html; charset=big5">

using standard fonts for the textbox, don't embed any fonts will work fine for big5/gb encoding

cheers
0
 
garytanAuthor Commented:
hi, henry

really appreciate of your reply, just to clarify with you, the ‘a’, ‘b’, ‘s’ is simply my typo, a means teama, b means teamb and s means score in my statement.

I attached my logic explaination and files for your reference(in your yahoo email)

hope to hear from your soon. appreciate that!


gary
0
 
garytanAuthor Commented:
hi, henry

really appreciate of your reply, just to clarify with you, the 'a', 'b', 's' is simply my typo, a means teama, b means teamb and s means score in my statement.

I attached my logic explaination and files for your reference(in your yahoo email)

hope to hear from your soon. appreciate that!


gary
0
 
garytanAuthor Commented:
Henry

Great! your suggestion seems to be work on my problem, I pass the variables via the flash object and it able to display the result in english, as well as in chinese character too!

now it is time for touch-up, I would like to control, say when there is score for TeamA, an animation(a spinning boal image) will be attached next to the team name, how can i pass the image to the flash? or can I control it in flash itself?


you deserve all the credit points!!

cheer

gary
0
 
henrywwCommented:
OH COOL ...

glad that u got it done finally :)

well, as simple as creating a symbol and check which team has the score (or the winner) and attach the movieclip next to the name or something ...

it is not so hard ... :)

1) create a symbol with the (a spinning boal image)

2) export the symbol (linkage) and name it "goal" or something

2) since u have pass the team names & scores in, so u should be able to determine who wins right?

4)
// attach the movie  - i only make up the figures
_root.attachMovie("goal","goal",100)
 
if (winner == 1) {
_root.goal._x = 5;
_root.goal._y = 100;
} else if (winner ==2) {
_root.goal._x = 100;
_root.goal._y = 100;
}

i am not sure if that exactly what u mean, but if u are having trouble to determine who wins ...

say - the score u have is "6-3","0-2" .. etc
eg.

score = "6-3";
var tmpString = score.split("-");
// this will give u an array
scoreA = parseInt(tmpString[0]);
scoreB = parseInt(tmpString[2]);

if (scoreA > scoreB) {
//winner is A

} else if (scoreA < scoreB) {

// winner is B

} else {

// draw game
}

then u can set the animation position and appropiate action from the above information.

cheers
0
 
garytanAuthor Commented:
actually, when a team scored, the new window will pop-up, with the flash. At the same time, I would like to attach the image to the team (say attach next to the teamname) who have make the score during the moment. The winning team at full-time is not really a concern here.

in this case, your suggestion above cant determine which team score at the time, (like at 10rd minute, MU score 1 goal, and Juventus is 1 already, so i will pass;

<object..>
<param name="FlashVars" value="datavalue4=10'&datavalue=EPL&datavalue1=MU&datavalue2=1-1&datavalue3=Juventus">

datavalue4 is my minute field in flash
datavalue is my leaguename field in flash
datavalue1 is my hometeam field in flash
datavalue2 is my scores field in flash
datavalue3 is my awayteam field in flash

I have an idea here, like when a team score, in this case MU, I will pass an indicator variable to <param ..>. At flash, I extract and find out which team is scoring, thus start to load the image. do it work?

If it do work, may I know how to pass the indicator variable from my php? and at flash site, how can I identify it, like writing the activescript, if then else statement?

I am quite new to flash, will appreciate more instruction.


awaiting your reply, thank you!

gary
0
 
henrywwCommented:
ok ok ... now i under a bit ...
so this is kind of like a real-time scoring board.

like if a user comes on the site when it is,.. say ... 30Min in the game and the score at that moment is 2-1 and the team who had just scored is MU, so u want to indicate MU is team who had just score. correct?

well .. it all depends on the DB structure and ur PHP, whenever a score is updated, if u have the TIME stamp for it as well, then u can compare the value and see who scored last.

otherwise if u have data as in MU vs Juventus and the score is stored in the sequence "1-0", "1-1", "2-1" ... etc
untill end game "2-3" etc ..

i really have to know what data is available.

also, do u only want to indicate who scored the last goal or every goals scored, that's is quite different and quite difficult for to do a score board ...

i understand sometimes the scoring is order is also important, i kind of know what sort of site u are doing... but i do need more information.

cheers
0
 
rascalpantsCommented:
sorry for not replying garytan... have been unavailable lately...


I did not read through all of the posts above, but let me know if you need help with your original question...  I believe your problem has/had to do with the way your PHP code is displaying your variables...


they need to be in the following format:

<?php

echo "teamAname=$team_name_a_chinese&teamBname=$team_name_b_chinese&teamAscore=$scorea&teamBscore=$scoreb";

?>

Also your character problem can be solved by making sure that your dynamic text boxes that display the teams and scores are using Embedded fonts.  This way the swf uses the dynamic text and displays the characters as graphics and not text...  this should help...


Again, sorry if this is redundant... And let me know if you have any questions


rp
0
 
garytanAuthor Commented:
patient and valuable comment! Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 10
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now