Include( SWF ) files...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok, not sure what actionscrpit.org has that I need, but does anyone know simple flash or of a LOADER written in flash. A pre loader would work, anything along that nature I could edit to make it work.

How about the idea that I wanted to stick with .htaccess and php, is any of those things I mentioned possible or how can I do this in php instead of swf.
Jerryscript1
Forum Newbie
Posts: 10
Joined: Thu Jan 27, 2005 4:22 am
Location: Las Vegas

Post by Jerryscript1 »

You can create a holder SWF movie that only loads the movie from the other server. This puts all the work on the browser, no bandwidth used from your server. The holder SWF movie will be less than 1k.

Using flash:
1-create a movie the same size as the movie you want to load from the other server
2-add the following actionscript to the main timeline:

Code: Select all

loadMovie("URL_OF_THE_SWF_FILE_TO_LOAD_HERE","_level0");
3-place this movie in your webpage

Using PHP's Ming module:

Code: Select all

<html><body><center>
<?
ming_useswfversion(6);
$movie = new SWFMovie();
$movie->setDimension(900,500);
$movie->setBackground(255,255,255);
$movie->setRate(60);
$revitalizer=rand();

$actions="loadMovie('URL_OF_THE_SWF_FILE_TO_LOAD_HERE,'_level0');";
$movie->add(new SWFAction($actions));

$movie->save("Blank.swf");
$revitalizer=rand();
print "<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=6,0,0,0" ID=objects WIDTH="900" HEIGHT="500">
<PARAM NAME=movie VALUE="Blank.swf?$revitalizer">
<EMBED src="Blank.swf?$revitalizer" WIDTH="900" HEIGHT="500" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</OBJECT>
";
?>
</center></body></html>
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok, thanks.

One small problem, what about the SIZE you said, it has to match the size of the movie I want to load on one of the other servers.

Did you mean WIDTH and HEIGHT or did you mean SIZE of file. I am going to need to load several HUNDRED different movie swf files, all different size of file and size in width and height. Is there a way I can make a ONE FIT ALL of say 600x500 and if the movie is bigger or smaller, it adjusts?

Thanks.

Is this ALL that I need to have in the brand new file I create?

loadMovie("URL_OF_THE_SWF_FILE_TO_LOAD_HERE","_level0");

AND how do I make it so $revitalizer or a differently named variable automatically inputs in place of URL_OF_THE_SWF_FILE_TO_LOAD_HERE. I want to be able to make ONE loader that can load ALL hundreds of movies just by changing a php variable .

Thanks.

I'm a TOTAL n00b at flash right now, your instructions were VERY clear but I really need to learn this stuff better but no time. I'm going to have to learn how to make a small preloader in fact as well, I want to insert my site's logo (which I haven't created yet, lol) before the game loads, and If I could have a percentage shown, that would be awesome. I saw this one preloader on MANY MANY MANY games, it's white back ground, blue laying down cylinder that fills from left to right and on the right of it it shows percentage loaded, and it fades out when done and loads the movie/game.

Do you know what preloader I am talking about and what's it called, I believe it's open source and that's why it's on so many movies.
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok, now that I'm slowly getting the ball rolling, a focus on the IMPORTANT issue of variable passing.

I believe like I said earlier, imagine bomberman.php has variables like

<?php

$url="http://www.placewherehosted.com/movies/ ... n_game.swf"

?>

and then the html output of my website and THIS page has the <embed> for the new loader WE created (with lots and lots of your help).

How can I get the loader.swf file to GET that $url variable, like how do I PASS $URL down from php INSIDE the same page to the swf.

I do NOT want to have loader.swf?url=http://www.placewherehosted.com/movies/ ... n_game.swf , this COMPLETELY ruins the idea of leech protection, I want it to be a totally SCRAMBLED variable or preferabbly not have ?url at all.

If I could have loader.swf LOAD whatever movie in in the $URL php variable of the page loader.swf is loaded, that would be PERFECT.

If I HAVE to use cookies or sessions, I will understand, I REALLY prefer not to have to use cookies or sessions really, that will mess up alot of coding, etc.

Can I make $URL, global in php so it's passed down to loader.swf or how do I make loader.swf REALIZE there is a variable named $url set in php and have it embed it.

Thanks in advance again~!
Jerryscript1
Forum Newbie
Posts: 10
Joined: Thu Jan 27, 2005 4:22 am
Location: Las Vegas

Post by Jerryscript1 »

OK, lots of questions, and they are a bit confusing taken all together, so let's see if we can cut to the gist of it.

You basically want to hide the URL to the SWF game.

In that case, your best bet is to use the second set of code (the Ming code). This will generate a SWF file with the appropriate URL in the loadMovie() function. Of course, this requires you to have Ming on your server (very easy to build and install).

All you would have to do to hide the URL is place the $URL in the spot where the url is required in the Ming code. If each SWF is a different size (height/width, file size doesn't matter), then you could either pass the appropriate sizes as PHP variables, ie $width and $height, or use getImageSize() to retrieve the sizes on-the-fly. Example:

Code: Select all

<html><body><center> 
<? 
ming_useswfversion(6); 
$movie = new SWFMovie(); 
$movie->setDimension($width,$height); 
$movie->setBackground(255,255,255); 
$movie->setRate(60); 
$revitalizer=rand(); 

$actions="loadMovie('$URL','_level0');"; 
$movie->add(new SWFAction($actions)); 

$movie->save("Blank.swf"); 
$revitalizer=rand(); 
print "<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=6,0,0,0" ID=objects WIDTH="$width" HEIGHT="$height"> 
<PARAM NAME=movie VALUE="Blank.swf?$revitalizer"> 
<EMBED src="Blank.swf?$revitalizer" WIDTH="$width" HEIGHT="$height" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> 
</OBJECT> 
"; 
?>
</center></body></html>
The only way to leach the URLs using this method is to download each newly generated SWF file and decompile it. Still can be stolen by those who have the knowledge, but much harder for the average thief!

If you cannot install Ming on your server, then you can pass the URLs via Javascript to the SWF file for loading, but you would have to develop a different method to deal with the size issue. Something like creating a SWF file with the largest necessary dimensions, and a background color that matches the webpage. This way, the smaller files will not be warped.
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

alright, thanks very much. I understand that code 100% completely now and that WILL work beatifully.

I will install ming today I believe and give it a shot, that looks perfect. There's no way someone is going to decompile 4000+ files trying to leech, and if they did, It would take them like months and I think I'm going to repath the folders every month anyways, just for the heck of it~!

Just for my learning purposes anyways, IS there anyway to pass $url from the php into the .swf WITHOUT having embed src="BLANK.swf?url=<? echo $url; ?>"></embed>. I'm sure there is a way to do this where I make the $url variable Global for PHP AND for flash or something, or do this via sessions? $_POST["url"] ? cookies? hidden form fields or something? Or would the only way like what I am describing to be something like sendAndLoad() from bomberman.php, would the flash file be able to load that bomberman.php SOURCE code or would it already parse?

Or how about this. Write another php script called, return.php , and it will have something like fread(bomberman.php) and then I would traverse the individual LINES of bomberman.php (BECAUSE bomberman.php starts out with the php info including that url and description, etc... and then after the php it outputs the html which I DON"T need in flash, it would just slow everything down) so could I like read bomberman.php into return.php and traverse the first say 10 lines, and return.php would return that (which are the variables I need) into the swf loader?

I am definately going to try and most likely use your method of MING, that will be excellent, just wanting to clear up things in my head about flash and php, how to send variables past the beginner stage, (I am semi advanced with php, I can write the alogorithm easily but have to know if it's going to work and then look up the functions on php.net).

Thanks for your help~!!!
Jerryscript1
Forum Newbie
Posts: 10
Joined: Thu Jan 27, 2005 4:22 am
Location: Las Vegas

Post by Jerryscript1 »

So many ideas running through your mind, kinda like a kid with a hundred bucks in a penny candy store! :)

Rather than saving the generated SWF file and outputting it in an HTML page, you can use the loadMovie statement and Ming's output() function. You need to pass headers for swf at the top of your PHP script, something like this:

Code: Select all

<?
header('Content-type: application/x-shockwave-flash'); 
ming_useswfversion(6); 
$movie = new SWFMovie(); 
$movie->setDimension($width,$height); 
$movie->setBackground(255,255,255); 
$movie->setRate(60); 

$actions="loadMovie('$URL','_level0');"; 
$movie->add(new SWFAction($actions)); 

$movie->output(9); // 9 gives maximum file size compression
?>
This method allows use of sessions or any other type of variable passing PHP can handle, and uses no embeding in the browser itself. This script can then be called from the holder flash movie in a loadMovie() statement.
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

hey again, just got around to finding time in the middle of the night to try and install ming, and I am following the directions at:

http://us4.php.net/manual/en/ref.ming.php

AND

http://www.opaque.net/wiki/index.php?MingInstall



So far, I have done this:

Code: Select all

mkdir /root/new/
cd /root/new/
wget http://mesh.dl.sourceforge.net/sourceforge/ming/ming-0.3beta1.tar.gz
gunzip ming-0.3beta1.tar.gz
tar -xvf ming-0.3beta1.tar
cd ming-0.3beta1
make
make install
HERE I GET ERRORS:

Code: Select all

make&#1111;1]: Leaving directory `/root/new/ming-0.3beta1/src'
install -m 0644 libming.so.0.3beta1 /usr/local/lib/
install: cannot stat `libming.so.0.3beta1': No such file or directory
make: *** &#1111;install-dynamic] Error 1

Any clue what this means and how I fix it?


These are the instrcutions from PHP.net

To use Ming with PHP, you first need to build and install the Ming library. Source code and installation instructions are available at the Ming home page: http://ming.sourceforge.net/ along with examples, a small tutorial, and the latest news.

Download the ming archive. Unpack the archive. Go in the Ming directory. make. make install.

This will build libming.so and install it into /usr/lib/, and copy ming.h into /usr/include/. Edit the PREFIX= line in the Makefile to change the installation directory.

Installation
Example 1. built into PHP (Unix)

Code: Select all

mkdir <phpdir>/ext/ming
    cp php_ext/* <phpdir>/ext/ming
    cd <phpdir>
    ./buildconf 
    ./configure --with-ming <other config options


Build and install PHP as usual, restart web server if necessary.

Now either just add extension=php_ming.so to your php.ini file, or put dl('php_ming.so'); at the head of all of your Ming scripts.



On the actual ming tutorial,

2004-11-5:complie PHP with ming support in Fedora Core2

httpd-2.0.52.tar.gz
PHP-4.3.9.tar.gz
Ming function does not work with PHP-5.0.2
Ming CVS
1 install httpd as normal

tar zvxf httpd-2.0.52.tar.gz
cd httpd-2.0.52
./configure --prefix=/usr/local/httpd
make
make install
2. tar zvxf PHP-4.3.9.tar.gz

3. install ming lib

checkout ming from cvs.sourceforge.net
cd ming
modify Makefile, change 'PREFIX = $(DESTDIR)/usr' so 'PREFIX = $(DESTDIR)/usr/local'
so libming and include files will be installed to default path.

make
make install
cd php_ext
cp * ../../php-4.3.9/ext/ming -rf
4. install php

./configure --with-apxs2=/usr/local/httpd/bin/apxs --enable-track-vars=yes--with-ming <other opions> --enable-debug --enable-sigchild
make
make install
5. modify httpd.conf

AddType? application/x-httpd-php .php
AddType? application/x-httpd-php-source .phps


I am on part 3 right after the "make install " line, I am afraid to continue and copy and recompile php, I really don't want to f' things up if you know what I mean, I like to prepare before doing something stupid like a regular n00b.

Yea know, look BEFORE you jump, not close your eyes and jump.

The second to last script you pasted, this one:

Code: Select all

<html><body><center> 
<? 
ming_useswfversion(6); 
$movie = new SWFMovie(); 
$movie->setDimension($width,$height); 
$movie->setBackground(255,255,255); 
$movie->setRate(60); 
$revitalizer=rand(); 

$actions="loadMovie('$URL','_level0');"; 
$movie->add(new SWFAction($actions)); 

$movie->save("Blank.swf"); 
$revitalizer=rand(); 
print "<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=6,0,0,0" ID=objects WIDTH="$width" HEIGHT="$height"> 
<PARAM NAME=movie VALUE="Blank.swf?$revitalizer"> 
<EMBED src="Blank.swf?$revitalizer" WIDTH="$width" HEIGHT="$height" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> 
</OBJECT> 
"; 
?> 
</center></body></html>

Where exactly does this SAVE the file to? The file is named Blank.swf I presume, and I'm wondering where the file is saved to. Is it going to need me to simply chmod the directory to 777 and it writes it out EVERY time, or something like that? OR does it save the file to Blank.swf in the VISITORS internet explorer cache, and doesn't actually physically create the file, just "virtually" creates the file, Does this strain the server load/resources?

Thanks many times over, I am learning flash slowly but surely, and I'm going to write a preloader with my logo's and this anti leech thing very soon (was hoping to install ming tonight and test it out tommorow), hopefully it will be off the bomb.


feyd | :roll:
Jerryscript1
Forum Newbie
Posts: 10
Joined: Thu Jan 27, 2005 4:22 am
Location: Las Vegas

Post by Jerryscript1 »

For building/make/install issues, I highly recomend you use the Ming-Fun mailing list, that way someone using the same OS can answer your questions. (find the mailing list at the ming page on sourceforge). The latest version of Ming (CVS) has extra install issues regarding compiling with various libraries such as libjpeg, libpng, and libgif(libungif?). I use a precompiled version on Windows, with the binaries provided by http://www.kromann.info. I personally have not built Ming on Linux since version 0.2a, so I can't really help you there.

The code you mentioned will save the Blank.swf file to the directory the script is called from (so it does need read/write permission, though not 777 which can be dangerous). The last set of code I posted would output the file to the browser without saving to the server's filesystem, and therefor would be reliant upon the user's cache settings (much safer).

Looking forward to seeing you on the Ming-Fun mailing list.
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

Hey thanks,
I went to the sourceforge, but I can't join that group without paying 40 bucks a year for membership (which I really see as unnecessary).

I follwed the EXACT instructions to COMPILE PHP AS A MODULE, here are my steps.

These are the exact words:

Installing Ming

Last updated 2nd February 2004.

Unfortunately we haven't made Ming use autoconf yet. If you'd like
to help with this, please let us know!

Unpack the Ming source tarball and go into the uncompressed
directory.

$ gunzip ming-0.3beta1.tar.gz
$ tar xfp ming-0.3beta1.tar
$ cd ming


PHP
***

(should work with PHP-4.0.2 and higher)

The preferred method is to build Ming as a PHP module (.so file):

1. Compile the main Ming library

$ make
$ make static

2. Compile the PHP module

$ cd php_ext
$ make

3. Install the PHP module

$ make install

4. Configure PHP to load Ming. You need to adjust your
php.ini file, normally by adding:

extension=php_ming.so

to the extension section, and also making sure the
"extension_dir" parameter in the php.ini file is pointing
to the correct directory. A common default of the php.ini
file is to be pointing to "./", which may need adjusting.


The alternative way is to build Ming into the PHP source:

$ mkdir <phpdir>/ext/ming
$ cp php_ext/* <phpdir>/ext/ming
$ cd <phpdir>
$ ./buildconf
$ ./configure --with-ming=<mingdir> <other config options>

Then build and install php as usual, then restart your web server.





AND HERE IS WHAT I DID.




mkdir /root/new/
cd /root/new/
wget http://mesh.dl.sourceforge.net/sourcefo ... ta1.tar.gz
gunzip ming-0.3beta1.tar.gz
tar -xvf ming-0.3beta1.tar
cd ming-0.3beta1


EDIT Makefile first line
FROM " PREFIX = $(DESTDIR)/usr" TO " PREFIX = $(DESTDIR)/usr/local"

The following lines REMAIN default as
"LIBDIR = $(PREFIX)/lib
INCLUDEDIR = $(PREFIX)/include"


make
make static
cd php_ext
make
make install

ADD "extension=php_ming.so" under the rest of the extensions, WITHOUT ";" since all the others are commented out.

/etc/rc.d/init.d/httpd restart



After doing all of that three times, I still get "Fatal error: Call to undefined function: ming_useswfversion() in /home/user001/public_html/test/ming.php on line 3" when running this in php "<? ming_useswfversion(6); ?> " which is correct syntax. I leave this to lead me to believe that ming is NOT installed and running, so how in the world do I install ming on my (redhat 9, I believe) server?

Now what? lol.....
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok hang on, let me do some more testing.

I TESTED by changing extension_dir = ./ TO extension_dir = /usr/local/lib/php/extensions/ and the error disappeared, which I take it's working now.

I thought ./ would have been recursive :( , guess not but I think it's working now.
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

oh yeck yea, that work absolutely beatifully. The second to last one which creates the Blank.swf is very nice.

So you said 777 is dangerous? What settingsshould I try? Should I Just create a file Blank.swf and chmod that file alone to 777 or how else can i do it? Does this method take alot of server resources do you know or how fast is it? Like say I have 1000 people online simultaneously and they all click on a different file at the same time (with human error and internet lag of course), those thousand queries to create a file Blank.swf with a different url, is that going to be a problem or should I name it based on the FILE name instead of blank.swf I put <? echo "$filename.swf"; ?>, so it just recreates the same file every time each game/movie is loaded.

I may use the last script but I'm testing this one right now until I get my preloader made.

Thanks for ALL your help, really neat stuff with php and ming, didn't think you could do this so easily.
Jerryscript1
Forum Newbie
Posts: 10
Joined: Thu Jan 27, 2005 4:22 am
Location: Las Vegas

Post by Jerryscript1 »

Never heard of a need to pay to join the ming-users (sorry, I previously posted ming-fun) mailing list, here is the URL to sign up http://lists.sourceforge.net/lists/listinfo/ming-users

For chmod settings, I would experiment with the lowest levels first, then work my way up till you find what works, the lower the safer.

Creating the blank swf file with a single line of AS shouldn't be too much of a strain on your server, but testing is the only way to be certain. I've never worked with such high loads, so I can't say for certain. I would recommend trying a session variable created file name, that way each user will access an independent file. You may need to use flock to prevent simultaneous file access with such high loads.

Good luck, and I hope to see you on the Ming mailing list!
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok, great. I believe i'm going to use the last one, the one that returns the url variable into the swf loader, tested both and got both working perfectly.

I'm learning flash bit by bit, in my spare time I'm reading a flash how to book, like for dummies ;), but I have a few small questions.

I built a flash pre loader, that displays the percentage loaded and then shows the file/movie/game.

It loads unbelievably fast, and I think something is wrong with it. It flashes through the loading screen adn then goes to the game screen which says it's loading (some games have a loading percentage game already).

do you think this could be if I placed the loadMovie() on the wrong keyframe, the preloader doesn't really work?

Ok, now for more pressing matters, after that, I'd like to delay the preloader 5 seconds before switching to playing the game, is there a delay(5000) command or something that would work?

Also,
I am getting into more advanced ideas, I'd like to also allow users to DOWNLOAD the game from the preloader screen, like put a button to download the game, and then another button so they can click and start playing online. Thing is, if they download, I want them to download the game in EXE format, ALL games are currently swf format.

Is there a php ming way to create a exe out of swf files? I don't want to have to compile several thousand .exe files out of my current swf files, that would take forever, but if I can do this with php/ming, it would be hella easier.

Also, lol, god I have so many ideas and i'm seriously using all of these, I am wondering how I can INSERT my logo screen BEFORE all of the swf flash files, without opening all thousands of them , that would take years. Is there a way I can create another flash swf file on prompt, like the second to last code you gave me, which has my loader, and then something like loadMovie BUT doesn't CALL a external file, it more like IMPORTS it INTO the new swf file after my logo screen, so it would show my logo screen and then loadMovie which is should be internally embeded in that file.

LoadMovie(http://www.mydomain.com/games/bomberman.swf) loads an external swf movie after my logo, but it calls it ALWAYS, I want something that will generate a new swf file, with my logo in front, and then the game, and this file would be slightly bigger than each of the game files before putting in the logo, since the logo will increase the file size a bit.

(This is something requested by a few of my users, they want to download movies and games from me and I want to give it to them but without having to manually insert my logo into EVERY single file, and then recompile into swf AND exe so they can play online AND offline, with my concerns today going towards the offline exe files now, I can't make a exe which LoadMovie(http://www.mydomain.com/games/bomberman.swf), because that would mean the person would still have to be connected to the internet.

Thanks for all your help, wouldn't have got anywhere without your all of your help and replies about ming (works perfect now).

Cheers,
JC

EDIT: OK one more thing please, also now the SIZE (height and width) of the games/movies is differing big time, some games are like 500x500 and others are like 300x750, quite a diffence and distortion. Is there a way that php/ming can SENSE the size of the movie? how would I do this? did you mention something about javascript, I prefer not to use javascript if at all possible, and I don't have the width and height to pass on from anywhere.)

Thansk~
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

does anyone know how I can IMPORT a movie into a new file which I would create this new file that has a nice flash intro and then plays the movie it imported (not including externally, actually PUSHING the flash game/movie into the new file).

Anyone know how I can do this or if there is a program that does this on a mass scale? And then changing .swf into .exe format on a mass scale?

I'd appreciate any help you guys can give.
Post Reply