Hi, guy
I've created an animation (swf file) using AS3 and FlashDevelop.
I'm able to compile and play it in FlashDevelop but when I open it in any browser (IE, Firefox, Chrome) I just see the background color and that's it. (I've flash player plugin installed on browsers).

What my animation is doing:
It's reading two matrices from a file and animates arrows according to the information in the file.


I suspect this problem to be because I'm reading data from a file.
When I play same animation, but "hard coding" the data (not reading from a file) everything is ok (play in browser).

What's the problem? How can I solve it? Is it something that's possible to configure from FlashDevelop or/and Compiler????

Thanks in advance.

Did you uploaded your animation on the server or you just trying to run it locally?
In case of server, did you upload animation depended files with relative folder structure (in case files are in sub folders of animation)?

Did you uploaded your animation on the server or you just trying to run it locally?
In case of server, did you upload animation depended files with relative folder structure (in case files are in sub folders of animation)?

I'm playing it locally, and the file containing data is located in the same directory as flash animation. And I'm loading file just by name "data.txt", so file should be in the same folder as flash animation.

Hmm, that is strange. Would you mind to upload your Flash work project file *.fla and the data file?

PS: To add attachment you need to be in advanced editing option (press Go Advanced, if you did not already do so) and bellow post area you will find Manage Attachments option that will allow you to upload

commented: Thanks for trying to help +1

To better diagnose the problem it would be worth trying to run the .swf directly from the desktop in a standalone version of flash player, instead of via a browser plugin.
To do this, navigate to your .swfs directory on the hard drive and double click on it and the standalone player should load and run the file!

If it doesn't work properly in the standalone player, then it is most likely that your actionscript for loading the text file is incorrect.
In which case, it would be an idea to upload some code so we can see what's going on.

However, if it works properly in the standalone player, then it could be a problem with your publish settings...Unfortunately I'm on my wifes laptop at the moment, so I don't have Flashdevelop handy and can't give any suggestions on what to try.

For now, try running your swf in a standalone instance of flashplayer and let us know how you get on!

All the best.
J.

I forgot to tell you guys that I've tried it in a standalone player (Media Player Classic - with flash player on it), and it's working great on standalone player.

I'm attaching my files, but I suspect this problem to be related to compilation or publishing as you guys said.
I'm just pressing CTRL+F8 to compile:

Flex compiler process starting: java -classpath "E:\Program Files\flex_sdk_3.3.0.4852\lib\mxmlc.jar;C:\Users\AKZHOL\AppData\Local\FlashDevelop\Data\AS3Context\FlexShells.jar" -Duser.language=en MxmlcShell
MxmlcShell command: -o;E:\project\ide\Main.swf;-sp+=E:\project\ide;--;E:\project\ide\Main.as
Loading configuration file E:\Program Files\flex_sdk_3.3.0.4852\frameworks\flex-config.xml
E:\project\ide\Main.swf (2170 bytes)
Done(0)
[Capturing traces with FDB]

Any ideas?


BTW, I googled but couldn't find any useful information.

Ok, I think I see the problem. It's not related to publish settings or erroneous code, its a security issue...

I downloaded your code to my desktop and unzipped it to a directory called ide. I then loaded Main.as into FlashDevelop and pressed Ctrl-F8 to build the .swf.
The swf built successfully and ran ok in a standalone player in the FlashDevelop IDE...Lots of squares with different sized arrows pointing in different directions and moving around..OK good so far.

I knocked up a quick and dirty HTML page to embed the swf and opened the page with Firefox and I got a blank blue .swf...Not so good!

I then opened up the directory containing the swf on my desktop and tried to run the swf in a standalone instance of Flash player (flash player 10) and got the following error message:

SecurityError: Error #2148: SWF file file:///C|/Documents%20and%20Settings/Jason/Desktop/ide/Main.swf cannot access local resource file:///C|/Documents%20and%20Settings/Jason/Desktop/ide/data.txt. Only local-with-filesystem and trusted local SWF files may access local resources.
at flash.net::URLStream/load()
at flash.net::URLLoader/load()
at Main/::readMatrix()
at Main$iinit()

This is a pretty straightforward thing to get around, what you need to do is inform flashplayer that your .swf is a trusted file and that you give explicit permission for it to access the local file-system.
"How do I do that??" I hear you cry "Do I need to sign a permission slip for its teacher?"

Well, to do this the following simple steps are necessary:

1. Open up a text editor and enter the path to your .swf
In my case I'd use:

C:\Documents and Settings\Jason\Desktop\ide\Main.swf

2. Save the text file (filename doesn't matter as long as it ends with .txt) to the following path:

C:\WINDOWS\system32\Macromed\Flash\FlashPlayerTrust\yourtextfile.txt

Mine was called "New Text Document.txt" heh heh! :D

Once these steps are done, open up your .swf in explorer and it should work flawlessly. Likewise opening up the HTML file you'll see that the .swf works there too..

Notes on the FlashPlayerTrust directory path:
1. If any of the folders specified in the path above do not exist, then you'll have to add them manually and name them appropriately to match the path specifed above.

2. This path only applies to Windows XP and earlier. If you're on Windows Vista, Mac or Linux, I'm not sure where the FlashPlayerTrust directory goes (it might be the same for Vista, but I'm not sure!)..So you'll have to google it and use that path instead!


Further Notes:
Flash player trusts any .swf's which are in the paths specifed in the text files in the FlashPlayerTrust directory.
Entering a path that ends in a filename into a text file in the FlashPlayerTrust directory:
e.g.

C:\Documents and Settings\Jason\Desktop\ide\Main.swf

will result in that single file (Main.swf) being trusted.

However entering a path that ends with a directory:
e.g.

C:\Documents and Settings\Jason\Desktop\ide

will cause all .swf's in that directory and any .swfs in all of its subdirectories to be trusted.
This can be useful if you are testing several files which require local file access.

Entering the following path:

C:\

would cause all .swf's on C:\ to be trusted (including all subdirectories)...Not recommended, for obvious reasons! ;)

Your text file can have more than one path listed in it, you don't have to create a text file for each individual path you want to add.
You can specify all of your trusted files/paths in one text file.

I generally add text files to FlashPlayerTrust on a per-project basis, that way if i decide to delete one of my projects I can just delete its associated text file in FlashPlayerTrust. That way I don't end up having to go through a global list of paths and delete only the paths relevant to that project!

So that's how you flag swf's as trusted to allow them access to the local file-system...That should solve any issues you have while testing your .swf locally.

If you have any further problems when you upload your .swf to a web-server, you may end up having to alter your loading code to use the full http:// URL of the text file instead of using a relative path...But you might not, so cross that bridge when/if you come to it!

As ever, let me know how you get on!
Cheers for now,
Jas.

commented: As always best and correct answer. Thanks again. +1

JasonHippy
Thanks. As always your answer is correct and in place.
I don't know how can I thank you, if you were in Canada, definitely I would have to buy you a coffee :)..
Thanks again.

BTW, I'm using Vista and path is same.

Hi, guys
I've a little problem, again. Before closing the thread I just wanted to ask. As you might have seen from the code, I'm reading array from the file. I want my flash to be resized depending on the array size read from a file.

I don't know whether I'm using correct word to explain what I want.
I want every square to be 100x100 always, and depending on the array size I want my flash size to resized. For instance if array is 5x5, then I want flash animation to be 500x500, if array size is 100x100, my flash will be 10000x10000. It's ok if there will be scrollbars. Is there a way to achieve this?
Thanks again.

Hi, guys
I've a little problem, again. Before closing the thread I just wanted to ask. As you might have seen from the code, I'm reading array from the file. I want my flash to be resized depending on the array size read from a file.

I don't know whether I'm using correct word to explain what I want.
I want every square to be 100x100 always, and depending on the array size I want my flash size to resized. For instance if array is 5x5, then I want flash animation to be 500x500, if array size is 100x100, my flash will be 10000x10000. It's ok if there will be scrollbars. Is there a way to achieve this?
Thanks again.

Sorry dude, I haven't had a chance to puzzle over this properly yet!

My initial thoughts are that you'll probably have to restructure your code a little. All of the code for loading your text file and drawing and animating your arrows should probaly be moved out of Main and into a class of it's own (ArrowAnimation.as??).

Then you can set the size of the Main.swf [500X500] and add an instance of your animation to the stage inside Main.
This way your arrow animation should appear at full-size. But as you've already mentioned, it may not fit inside the visible area of the main frame (depending on the amount of data in the data file).

Bearing this in mind:
After creating an instance of your animation inside Main, you'd just need to perform a check (in main) to see if the size of the animation is larger than the stage. If it is larger, you could add an ENTER_FRAME event handler to main and use code in the bound function to track the mouse position.
Based on the mouse cursors distance from the centre of the stage (in the x and y axes), you could alter your animations x,y position (essentially scrolling it). The further you move from the centre in any direction, the faster the animation will scroll...If you get my meaning?

You'd also have to set constraints on how far the animation will scroll based on the animations size, to stop your animation from scrolling completely off the visible area!

Probably sounds more complicated than it is, but it would certainly be simpler than attempting to use scroll-bars as you'd have to create a custom control with some kind of panel which used scrollbars. You'd then have to create an instance of your animation class inside the custom panel....Probably wouldn't be a pleasant task!

So a bit of code refactoring and then scrolling based on mouse position would be the best bet IMHO.

Also, I'm not sure if using 100pxX100px cells would be a good idea, especially if your animation has 100X100 cells....Animating a 10000pxX10000px animation will be pretty processor intensive and will probably make your animation run like a pig, scrolling would probably make it even slower again!

When you refactor your animation into it's own class, you could try putting parameters into its constructor which would allow you to be able to alter the size of the cells...That way you can play about with the cell size (maybe also try loading some different sized datasets) and see what the largest cell-size is before the animation slows and the performance starts to decrease. Thus, you can determine the optimum size for the cells based on the size of the dataset!

If I get a chance later, I'll have a go at posting some pseudo code.
Otherwise I might use your previous code and have a go myself!

Cheers for now,
Jas.

Hi, Jason
Thanks again.
Since deadline is almost reached, I've decided to apply a "rude" solution to this problem.
I've decreased cell size to 30x30. And since max array size 140, I've made my animation to be 4200x4200 (30x140=4200). So for arrays of smaller size arrows will be just on the corner, that's ok, since deadline is reaching. But we can still duscuss and find some solution if it'll be helpful for other users later.

Thanks for all your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.