Partial updates to an SWF - actionscript-3

WHat is the standard method for say a server to update an already loaded SWF on the client browser, i.e. something analogous to how an html page is partially updated via ajax (though I don't know a lot about ajax yet either.) Would the mechanism be the same if user-initiated.
I assume the .SWF should have public functions that can be invoked, then you'll use javascript to access the swf from the html page its in, then invoke a public function of that swf.
Just the specific terms or functions I need to search for to get a primer on this would be great.
ALso, How would one go about testing the public functions of an swf that is already loaded in a browser (wihtout having a full Adobe devleopment suite for example).

This is quite a vast subject actually. This is the whole RIA concept. Flash can look after itself in terms of communicating with a server , you don't necessarily need Javascript. You only need a server side language to communicate with.
Since it all can happen within the swf , public functions don't really come into it. A User initiates an action in the movie that triggers a call to a remoting service which in turn sends a response which consequently updates the movie.
A few areas you can look into, in no particular order:
Flash PHP communication
Zend Amf Server ( Zend Framework )
http://framework.zend.com/
For testing purposes , try MonsterDebugger
http://gotoandlearn.com/play.php?id=109
Edit:
Flash can use PHP to retrieve a XML , then parse the XML & change the data inside the SWF according to the data retrieved in the XML
http://gotoandlearn.com/play.php?id=90
In case of a link, the concept is a bit different, because depending on the type of link this may cause a page refresh. The approach in the above tutorial could be user initiated by clicking on a swf element, entering text in a text input box etc... this is what I meant by the RIA concept. It's quite standard now in Flash that user interaction will introduce changes in your SWF by making calls to the server.

Related

Can a scorm lesson (made Captivate HTML5) be played in a browser page?

When I click on the index file of a SCORM package I receive a "Unable to acquire LMS,API content may not playback properly and results may not be recorded" within the browser page. However once past the error message the file plays back perfectly stopping where required, as well as totaling the Q & A session. No matter what browser I open this in I receive the same message. I have JavaScript installed. I edited the index file to read <0 from <9 as suggested on one site.
if(document.documentMode < 0)
{
document.body.innerHTML = "";
Am I attempting the impossible? Does the package need to be hosted within a LMS such as moodle? My purpose is simply a standalone lesson without the additional information supplied by an LMS.
Effectively, yes. A SCO in a SCORM package will attempt to initialize itself via a call to the LMS' API letting it know that it has initialized. To do so the first thing that package will do is look for the JavaScript based API that is the LMS' implementation of the SCORM RTE (Run Time Environment). So the message you are getting above is because the SCO is unable to locate the SCORM RTE API (because it isn't implemented by your page). Whether the rest of the content will "play" is very content specific, some will, some likely won't. Most SCORM content will have additional calls to the SCORM RTE to do things like capture completion, success (pass/fail), a score, etc. Some content may work in a "standalone" fashion where the calls that it would make to the LMS' SCORM implementation are turned into no-ops, but a learner would not receive credit for having consumed the content.
https://scorm.com/scorm-explained/technical-scorm/run-time/ is a good resource for more about how SCORM content functions.

whats the best way to connect Actionscript 3 in flash to a database?

I am currently creating a platform side-scrolling game. I want to know if is there some kind of tutorial where you can connect AS3 in flash cc to a database server because this is for my high score section and I looked online and majority of the tutorials I found barely work anymore. Is there a way to do it using MySQL and phpMyAdmin?
Certainly!
You can view the flash var concept Here
So, in my particular instance I created an .asp page that was connected to a database and had the .swf in the same page surround by the flash published object tag. I then fed in a courseNum variable in the url header, that allowed me to get specific data from the database.
Now that I knew I could connect to my db, I had to create external variables for Flash to communicate with the db information. In order to do that, you need to follow the this particular parameter syntax, and insert this into your object tag.
<param name=FlashVars value="myVariable=Hello%20World&mySecondVariable=Goodbye" />
Where as myVariable and MySecondVariable denotes the value you want to pass to flash.
In my particular case I used:
response.Write("<param name=FlashVars value='courseNum="&(RS1.Fields.Item("courseNum").Value)&"'/>"))
Which wrote <param name=FlashVars value="courseNum=000"/> into the object tag.
Now that I had everything set up on my page. I could then go into flash and communicate with these variables using:
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters.courseNum;
again making sure I was matching the variable name listed in my flash vars(courseNum) with the same parameter name in my flash code. And that's all there is to it. Just simulate this same process of:
Creating a page that can talk to the database
Implement your flash file into the page via the object tag
Write the flashvar param syntax to your object tag using PHP writing methods(not sure what those are echo maybe??)
And allow flash to communicate to this information using var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters.myVariable; with "myVariable" matching what you have listed in your flashvars object tag variable name.
Hope this helps in some way, take care!
I think the best way for you is to use php on server side, and just call the created scripts.
In php you create connection with database.
And from AS3 you just pass parameters through HTTP GET or POST methods.
Here you have a nice tutorial
and here is a video tutorial
Hope that helps...

Parsing a flash json response (Delphi/ TWebbrowser)

I have a flash game and get updates after pressing a button. Only a table inside the flash gets updated and the changes are not shown in the html source (well, its flash after all). Logging with Fiddler shows first one encrypted package (containing all data of the table after decoding with Fiddler) followed by 16x json packages (single entry of the table).
What i want to know is how to get those single packages in Delphi.
I do not want to alter the data, i simply want to read them. I cant make any changes to anything (webserver, flash, etc).
You could try proxying like Arioch suggested. I'm not too sure it would work, though.
If I were to do it this would be how:
Create a shared library in C (or C++) where you can hook up various dest/origin addresses and ports using WinPcap
Have it call your application when something get's caught
Process/manipulate the packet data as needed
Pass it on
Unfortunately there's no working WinPcap "headers" (or components) for Delphi, so there's no other way (other than porting all the headers to Delphi ...).
Here's a tutorial on how to use WinPcap.

Pass file from AS3 into embedded AS2 wrapper to load

I have a Flash AS3 application that uses FileReference.browse() to request a SWF from the user. If the chosen SWF is AS3, I'm good to go. However, if it's AS2, I need to load it into an AS2 wrapper first (so my app can alter it). All of these files (including my app and wrapper) are intended to exist locally on the user's machine, but the file they select can exist in any directory. So to be clear: Main application (AS3) -> Wrapper (AS2) -> User's file (AS2)
I know how to get the uploaded file's ActionScript version from the Loader's loaderInfo.actionScriptVersion variable, and that's working correctly. My issue is how to pass the file from the AS3 application to the AS2 wrapper so it can load it.
My first thought was to dump the ByteArray from the FileReference's load() function into a SharedObject "cookie". This method seemed pretty bad from a user-experience point of view, but it seemed most likely to work. However, I've been unable to find any method within AS2 to load the ByteArray as a movie (in fact, AS2 doesn't even seem to have a ByteArray class). So the first potential solution to my problem would be if anyone knew of a method for loading a movie from a ByteArray in AS2.
My second thought was to pass the uploaded file's path to my wrapper via the already-setup LocalConnection bridge, and then just have it load the file from that. However, I can't find any way to get the file's path, and my Googling suggests the security model intentionally prevents it. Not to mention, I'm not sure I can load an arbitrary file from the user's machine.
My "hands up in the air; I give up" solution was to just create separate buttons for loading AS3 and AS2 files (leaving it up to the users to guess which it is!) and have the AS2 button actually within the AS2 wrapper. However, it looks like AS2 doesn't have a file browsing uploading API, and the PHP-hybrid solutions I've found aren't an option (because this is meant to be run locally).
So, I would be eternally grateful if anyone could point me in the right direction for solving any of these three roadblocks. Alternative workarounds are of course welcome.
(Edit)
Ok, I found the documentation for AS2's version of the FileReference class. It supports the same file-browsing capability, but does not support directly loading the selected file into the SWF.
However, the security sandbox doesn't seem as strict for local files as I expected, and it looks like I can load any SWF on the user's machine once I have a path to it. So I should be able use JavaScript and an HTML form with a file input to get and pass the file path to my application. It's not ideal having to do all of this from within a web browser, but it should work. If it turns out satisfactorily I'll submit it as an answer.
(Edit 2)
Scratch the HTML-form idea. Looks like the path is hidden from JavaScript for the same reasons Flash hides it. The only option I can think of now is to have the user copy and paste the path to the file...
After reading over your post, you may be able to retry one of your previous attemps with some new information. Actionscript 2 DOES have a method for looking up files from a browser, same as AS3 does. AS2 also has a FileReference class. Check out the documentation here:
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001040.html
Also, here is a tutorial:
http://markshu.ca/imm/flash/tutorial/fileReference.html
Well, all of my other leads have dried up, so I'm submitting the two answers that will actually work, although neither is ideal:
A) Use Adobe AIR, which will give more access to the filesystem (such as for getting path info) at the cost of requiring the separate AIR runtime to be installed.
B) Have the user enter the path to the file themselves (cumbersome for the user)

How do I add an event to URLLoader Class?

Keeping into consideration the Actionscript 3 event HTTPStatusEvent:HTTP_RESPONSE_STATUS, which is ONLY AVAILABLE for AIR (and not Flash 9/10)
Quote from site:
Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Lite 4
I would like to add the same EVENT by extending the HTTPStatusEvent Class of Actionscript 3 for Flash (9/10).
I'm working on Adobe Flash CS3 and I'm trying to get the "last" location of a URL loader (I'm calling a php with a header("Location: ..."); ) so I need the location after it changes. This should be made directly by flash and I cannot use php proxies not other.
Also, I cannot find the source code of the AIR HTTPStatusEvent Class, which I need to get the event (specifically, the responseHeaders and responseURL properties that the AIR class has).
Of course, if you know of any other way to accomplish this, feel free to share it.
You can't do it this way.
Think about it: You are trying to add behavior to the URLLoader class by extending an event class that is thrown from there. Figuratively speaking, it's a bit like changing the paper size when you've only written letters to your next door neighbor, and now you want them to go overseas - unless you also give them to the mail main, that's not going to be very successful...
I've stumbled across a number of forum threads discussing this, and most of them seem to agree that Adobe prevented access to response headers in Flash versions prior to FP10 / AIR due to some sort of security issue. I'm not sure how much of this information is accurate, but I am quite confident that there is no way to get around this - you can't get the Location:header in older Flash versions.
You will have to find some other workaround. For example, if you have access to the PHP script, you could add an HTML comment containing the redirect location, and parse that value in ActionScript.
<!-- Location: http://google.com/ -->