Jump to content
(Open Beta) HyperSpin 2 is now available for everyone ×

(TUT) .SWF reading its own name and playing a video with the same name (portable path)


dark13

Recommended Posts

Posted

Longest title ever I guess...

 

I'm still exploring flash and I come up with a fun idea. What if a .swf could read its name and play a video (.flv or .mp4) with the same name in a given path?

 

It might seems a stupid idea BUT if you want an .swf to play an .mp4 without embedding it (paths will not be portable) OR embedd a .flv into it you must use flash every single time and create the related .swf. So, a 300 games systems means creating 300 .swf in flash. What if you could create a single .swf and simply changing its name to play a specific video?

 

Here's the idea: we have an .xml used as configuring files path, it must reside in an hardcoded path. For now we'll be using

 

C:\HyperSpin\dark13\position.xml

 

You can't change this path. If you don't have installed HS in C:/ like me just create those folders, you don't need a full install in C:

 

This xml is really easy

<xml>

 <position>C:/Hyperspin test/Media/Sega Genesis/Video/</position>

 </xml>\

You only need to change C:/Hyperspin test/Media/Sega Genesis/Video/ to the path where you are storing videos you want the .swf to play.

 

Now simply use 3 Ninjas Kick Back (USA).swf , it will read 3 Ninjas Kick Back (USA).mp4 in C:\HyperSpin\Media\Sega Genesis\Video\  . Change the name of this .swf to the one of any video you have in this folder and it will play that video.

 

Still have to double check code and ask some infos to JJB about his code but you can test it, please test it  :)

 

Honestly I don't know if I'll ever use this "trick" but I guess it may comes in handy :P

 


-----------------------

 

Instruction for the attached files:

 

1- Drop position.xml in C:\HyperSpin\dark13\position.xml and configure path if needed. While changing path in the .xml copy/pasting from an hd location remember to change \ to /, so:

 

C:\Hyperspin test\Media\Sega Genesis\Video\

 

Becomes

 

C:/Hyperspin test/Media/Sega Genesis/Video/

 

 

2- use the .swf. It will play 3 Ninjas Kick Back (USA).mp4. Change its name to match the name of another video and it will play that video.

 

3- .fla file is a source file. It is supposed to be used in flash to check code and change stuff/create another .swf.

Read .swf own name and play .mp4 video.zip

Posted

Yeah, that would be possible but there are some problems.

 

1- Flash pro don't like HUGE layers. I wanted to use text, not .pngs, in scrolling text but I had some problems with it. Moreover text is more cpu-intensive than a .png

 

2- How do you manage cue point for loop? It depends from the "size" of the text layer. Maybe it is possible to animate by code and use variables taken from the .xml but configuring would be a nightmare as you have no visual feedback for what you are configuring.

  • 3 months later...
Posted

Longest title ever I guess...

 

I'm still exploring flash and I come up with a fun idea. What if a .swf could read its name and play a video (.flv or .mp4) with the same name in a given path?

 

It might seems a stupid idea BUT if you want an .swf to play an .mp4 without embedding it (paths will not be portable) OR embedd a .flv into it you must use flash every single time and create the related .swf. So, a 300 games systems means creating 300 .swf in flash. What if you could create a single .swf and simply changing its name to play a specific video?

 

Here's the idea: we have an .xml used as configuring files path, it must reside in an hardcoded path. For now we'll be using

 

C:\HyperSpin\dark13\position.xml

 

You can't change this path. If you don't have installed HS in C:/ like me just create those folders, you don't need a full install in C:

 

This xml is really easy

<xml>

 <position>C:/Hyperspin test/Media/Sega Genesis/Video/</position>

 </xml>\

You only need to change C:/Hyperspin test/Media/Sega Genesis/Video/ to the path where you are storing videos you want the .swf to play.

 

Now simply use 3 Ninjas Kick Back (USA).swf , it will read 3 Ninjas Kick Back (USA).mp4 in C:\HyperSpin\Media\Sega Genesis\Video\  . Change the name of this .swf to the one of any video you have in this folder and it will play that video.

 

Still have to double check code and ask some infos to JJB about his code but you can test it, please test it  :)

 

Honestly I don't know if I'll ever use this "trick" but I guess it may comes in handy :P

 

-----------------------

 

Instruction for the attached files:

 

1- Drop position.xml in C:\HyperSpin\dark13\position.xml and configure path if needed. While changing path in the .xml copy/pasting from an hd location remember to change \ to /, so:

 

C:\Hyperspin test\Media\Sega Genesis\Video\

 

Becomes

 

C:/Hyperspin test/Media/Sega Genesis/Video/

 

 

2- use the .swf. It will play 3 Ninjas Kick Back (USA).mp4. Change its name to match the name of another video and it will play that video.

 

3- .fla file is a source file. It is supposed to be used in flash to check code and change stuff/create another .swf.

I feel like I've followed everything correctly, but it doesn't play...

 

Here's screenshots:

 

4FYXzxE.png

 

vQA8To4.png

Show your support for the Most Badass Project of them all!

Subscribe to me on YouTube and Facebook!

  • 2 weeks later...
Posted

Right now I'm using a different code, still have to polish it and probably I should use index instead of split as bugs may occur with some system names but here's the thing

BKmyFileName = this.loaderInfo.url;
BKmyFileNameArray = BKmyFileName.split(String.fromCharCode(92));
BKnum = BKmyFileNameArray.length;

BKthisSWF = BKmyFileNameArray[BKnum-1] ;

BKmyFileNameArray2 = BKthisSWF.split(".swf");;

BKthatSWF = BKmyFileNameArray2[0] ;

BKmypath = BKmyFileName.split(String.fromCharCode(92)).join("/");
BKmyFileNameArray3 = BKmypath.split("Media");

BKmypath2 = BKmyFileNameArray3[0] ;

BKmypath3 = BKmyFileNameArray3[1]
BKmyFileNameArray4 = BKmypath3.split("Images");

BKmypath4 = BKmyFileNameArray4[0]

SysBkLoader.load(new URLRequest(BKmypath2 + "dark13/Aeon Nox/Backgrounds/" + BKmypath4 + BKthatSWF + ".png"));

This code is not using a configurable .xml to get the path of the folder

 

BKmypath2 = HS folder

BKmypath4 = System name (MySystem/)
BKthatSWF = the name of the swf itself and of the png it will load (obviously you are going to load .mp4)

 

(String.fromCharCode(92)) is simply \ char

 

ALWAYS use / instead of \ while coding paths in flash. Consider that the files will work ONLY inside HS Media/MySystem/Images folder as "Images" and "Media" folders' names are used to get the name of the system itself (Media and Images folders MUST not be in the HS path, a path like c:\stuff\Media\HyperSpin will NOT work).

 

To debug the file in flash just use hardcoded path, and comment the part of code that find the system's name, flash will debug the file from windows temp folder and will give a random name to the file so it's impossible to debug the real code the file will be using :P

As usual you can consider the code under CC attribution non-commercial :)

Posted

Right now I'm using a different code, still have to polish it and probably I should use index instead of split as bugs may occur with some system names but here's the thing

BKmyFileName = this.loaderInfo.url;
BKmyFileNameArray = BKmyFileName.split(String.fromCharCode(92));
BKnum = BKmyFileNameArray.length;

BKthisSWF = BKmyFileNameArray[BKnum-1] ;

BKmyFileNameArray2 = BKthisSWF.split(".swf");;

BKthatSWF = BKmyFileNameArray2[0] ;

BKmypath = BKmyFileName.split(String.fromCharCode(92)).join("/");
BKmyFileNameArray3 = BKmypath.split("Media");

BKmypath2 = BKmyFileNameArray3[0] ;

BKmypath3 = BKmyFileNameArray3[1]
BKmyFileNameArray4 = BKmypath3.split("Images");

BKmypath4 = BKmyFileNameArray4[0]

SysBkLoader.load(new URLRequest(BKmypath2 + "dark13/Aeon Nox/Backgrounds/" + BKmypath4 + BKthatSWF + ".png"));

This code is not using a configurable .xml to get the path of the folder

 

BKmypath2 = HS folder

BKmypath4 = System name (MySystem/)

BKthatSWF = the name of the swf itself and of the png it will load (obviously you are going to load .mp4)

 

(String.fromCharCode(92)) is simply \ char

 

ALWAYS use / instead of \ while coding paths in flash. Consider that the files will work ONLY inside HS Media/MySystem/Images folder as "Images" and "Media" folders' names are used to get the name of the system itself (Media and Images folders MUST not be in the HS path, a path like c:\stuff\Media\HyperSpin will NOT work).

 

To debug the file in flash just use hardcoded path, and comment the part of code that find the system's name, flash will debug the file from windows temp folder and will give a random name to the file so it's impossible to debug the real code the file will be using :P

As usual you can consider the code under CC attribution non-commercial :)

Thanks, I will try this out and let you know how it goes.

Show your support for the Most Badass Project of them all!

Subscribe to me on YouTube and Facebook!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...