Saturday, September 1, 2007

Slogans On Toothpaste

Flash and XML



In this tutorial does not present a basis for XML'a jednynie his support in Flash. Therefore, if someone does not know this technology it is worth to know its basics.
Along with Flash 5, there are two new classes of ActionScript. The first of them, thanks to which it is possible to load an XML document and performing some surgery on it is called XML . The second named XMLSocket enables communication via sockets (socket) between Flash and a server. In Flash MX added property ignoreWhite , contentType and methods getBytesLoaded , getBytesTotal XML object and event and onData objects and XML XMLSocket ( ingnoreWhite, contentType and onData were also implemented in later versions of Flash Player 5).


Now a few words about how the processing of the document in Flash. When loading the object XML document is parsed (analyzed its syntax) and it creates a tree representation. The parser only checks whether the document is properly constructed (well-formed), but does not check its compliance with the DTD (given that the the document was a declaration of a DTD), ie whether it is valid (valid).
tree is built from the nodes, which can include the tags and text. XML declaration, document type, DTD, comments are not included in its composition. Tags are nodes of type 1, have a name, have no value, the text is a node of type 3 has no name, has the value. Parser for creating the tree may or may not, depending on the value of property ignoreWhite , include white space between tags or tag of the initial and final inception. If the value of this property is false, these characters are taken into account and are created with one type 3 nodes



As was shown above example, the tags are named "book" and "author", there are signs of new lines and spaces. You may have created a knot of type 3, which will be located at the same level in the tree tags as "author" and "title". These nodes are insignificant and are usually undesirable elements. In Flash MX can easily be eliminated by assigning ownership ignoreWhite true value , before loading the document into an XML object . In Flash 5 the situation is somewhat worse because the property ignoreWhite has been implemented only since version 5.0.41.0 of Flash Player. The problem can be solved by editing the XML document and remove all unnecessary white space, or programmatically using ActionScript (it's a bit difficult to write code and slows down the script). You can also use a ready solution. These are two functions stripWhitespaceTraverse and stripWhitespaceDoublePass written by Colin Moock'a. They remove the xml object as an argument forwarded them all superfluous text nodes containing only whitespace. They can be found at the author www.moock.org . Another solution to this problem, by overriding the method parseXML , proposes Branden Hall. Source XMLNitro called and can be found at chattyfig.figleaf.com .


Below is the code with which we can easily find out which version of Flash Player work (examples: xml_1_1.fla for the Flash MX xml_1_2.fla 5):


   version =   getVersion (); 
temp = version. split (", ");
MajorVersion = temp [0]. substr (temp [0]. length -1.1); / / Major version
MinorVersion = temp [2]; / / minor version

With getVersion we uzykać information operating system and version of Flash Player. The variables MajorVersion and MinorVersion are laid major version and minor version of the player, shelled from a string returned by the function getVersion . If you start up the presentation in Flash 5 using Ctrl + Enter these properties will be equal to 5 and 30, in the case of Flash MX will be a 6 and 21 In the case of a web browser will be different and probably will be the latest version. (This happens in the case of IE, flash plugin is installed mostly "silent" and automatically, in case other have to install manually. The latest version of the player can always be downloaded from the manufacturer ). The distinction version will allow us to apply the appropriate script. This is important if we want to maintain compatibility with older versions playerów and also faster on the latest.


time to return to read the document. Here's how the steps are as under which the file is fully loaded with an XML document:



  1. Define the function performed after the operation load of the document.

  2. Create an instance of class XML.

  3. Assigning property values \u200b\u200b ignoreWhite (default is false ).

  4. Override default method onLoad .

  5. load data into an XML object .


Ad. 1. Function definition should look like this:


   function funcname (nazwa_argumentu) {
/ / function body}


nazwa_argumentu argument passed when the function call is of type boolean and assumes a value of true load the document if the operation succeeded, or false
in the opposite case. You can define instructions to be executed automatically immediately after loading the document.


   loaddata function (ok) {
if (ok) {
plainout = " file was loaded correctly. "
} else {
plainout = " errors occurred when loading a file! ";

}}

In this example, defined a function called loaddata . Her sentence is limited to display in the dynamic information on whether the file was loaded or not. To this end, the argument passed is checked
functions and depending on its variable plainout is assigned a message displayed in the dynamic field of the output.


Ad. 2. Obietku XML class instance is created with the help of the constructor new XML () . Is obtained when an empty object, in this example:


  xmldoc = new XML    (); 

You can also use a different syntax new XML (data) where data are chain-forming document XML.


  xmDoc = new XML    (   John Doe   gather chestnuts    "); 

using this syntax is an object in kórym is immediately created a tree. We have to reckon with the fact that the document would be parsed with the white space (ownership ignoreWhite default or false) and that you can not use the function performed automatically after loading the document.


Ad. 3. The property ignoreWhite already mentioned. You can assign it a value until you create an XML object to have an impact on the construction of a tree it must be done before parsing document.


Ad. 4. Overriding methods onLoad done by assigning the function name defined in point. 1 (the default implementation of the method is inactive).


Ad. 5. The document can be loaded by the method load (url) where url is the address pointing to an XML document. If you already have an object from a tree, it will be replaced.


In this example, all the points except the first are in the cage first. Load the document itself is done by pressing the "load" and calling the same function loadFile :


 ... 

xmldoc = new XML (); / / Create an XML class called xmldoc
xmldoc. ignoreWhite = true; / / Ignore whitespace unnecessary
xmldoc. onLoad = loaddata; / / Assign function

...

function loadFile () {
if (infile == null ) {/ / If no file name
out = " No file name! "
} else {
xmldoc. load (infile); / / Load the file

}}

rest of the buttons include call other functions, as defined in the first frame. Here is how to present such exercises:



In the "File Name" enter the name of one of the files to spis_5.xml spis_1.xml. These files are different code page. One of the tags contains the text of the form: Polish characters on the keyboard: żźćńąśłęóŻŹĆŃĄŚŁĘÓ . You can see how the player will display them for different code pages:



  • spis_1.xml UTF-8

  • spis_2.xml ISO-8859-2

  • spis_3.xml Windows-1250

  • spis_4.xml Macca

  • spis_5.xml UTF-16


After reading the file and use the full object xmldoc you're ready to check his property. The results are presented in two dynamic fields: the upper "plainout" is a simple text box to display a simple
text, the bottom "htmlout" is a field in which they interpret certain HTML tags (activated option "render text as html".)
keys and plugged in to their functions:


first Button memorized? ". Is contained in the function call, which, under the ownership of loaded checks whether the object has been loaded document. If loaded is equal true to say that, yes.


   isLoaded function () {if 
(xmlDoc. loaded )
plainout = " Yes. "
else
plainout = " No. ";}


2," XML declaration "- read property values \u200b\u200b xmlDecl . If you loaded the xml document contains a declaration of thanks for this property can be read, it may be, for example .


   showXMLDecl function () {if 
(xmlDoc. xmlDecl ! = null )
plainout = xmldoc. xmlDecl ;
else
plainout = " no";}


third "DTD declaration - if the document contains the document type declaration with a DTD is Property docTypeDecl it is possible to read it. This figure includes (of course, if the document contains a) a public identifier, system, and an internal subset of declarations of individuals.


   showTypeDecl function () {if 
(xmlDoc. docTypeDecl ! = Null )
plainout = xmldoc. docTypeDecl ;
else
plainout = " no";}


4th "Status" - status property holds the number indicating the result of parsing. If a document is properly constructed is zero, in the case of an error is a negative number. The following function uses the manual switch to check the status of property values \u200b\u200b and on this basis, the deregistration of the appropriate message. For older versions of player 5 may be necessary to use an if else instead of the switch.


   showStatus function () {if 
(xmlDoc. status == null )
return;
switch (xmlDoc. status) {case
0 :
plainout = " document is properly constructed (well-formed). "
break;
case -2:
plainout =" Incorrect completion of a CDATA section. "
break;
case -3:
plainout =" Invalid end XML declaration. "
break;
case -4:
plainout =" Invalid end DOCTYPE declaration. "
break;
case -5:
plainout =" Incorrect ended comment. "
break ;
case -6:
plainout = "Invalid form of an XML element. "
break;
case -7:
plainout = " Out of memory. "
break;
case -8:
plainout = " Improperly completed attribute value. "
break;
case -9:
plainout = " No end tag for one of the elements. "
break ;
case -10:
plainout = " encountered tag The final, which does not correspond to any start tag. "

}}

fifth" tree "- this button provides a call to a function that traverses the nodes of displaying their name or value.


   traverseTree function () {
htmlout = "";
traverse (xmlDoc. firstChild, 0);}


playerów code for the version below, 5.0.41.0 (file xml_1_2.fla):


   traverseTree function () {
htmlout = "";
root = xmldoc. firstChild;
while (root. nodeType! = 1) {root = root
. nextSibling; / / nextSibling next node on the same level
}
traverse (root, 0);}


difference is that, as I mentioned at the beginning, that the earlier version of Player 5 when creating the tree and nodes are taken into account all the whitespace. Arise in this way, unwanted text nodes. To get to the root element of the tree, use the firstChild property (ie the first child or the child, if you will) of an object xmldoc
. That's enough for newer playerów or when the document starts right from the root element. For older playerów and if your document contains statements, comments, whitespace before the root element must be "shell" of them. At the top level nodes are created if type 3, or text and a node of type 1 or just the principal. With the while loop is made to assign the next adjacent node (property nextSibling ) to the time at which Type one of them will be first, equal Next the root node is transmitted traverse function, which it is mixed with the tree.


   traverse function (obj, space) {var 
indent = "";
for ( var i = 1; and <=space; i++) {
indent + = " ";
}
if (vol. nodeType == 3) { / / check node type if the type 3, or a text
/ / Displays the values \u200b\u200b
htmlout + = indent + "+ vol. nodeValue + "
"

} else if (v nodeType == 1) { / / if node type is a trench or a tag (element)
htmlout + = indent + " " + vol. nodeName + " " / / print node name
for (var attrib in vol. attributes) { / / and the attribute if it exists
htmlout + = ' "+ attrib +" = "+ vol. attributes [attrib] + " ";}

htmlout + = '
";}

if (v firstChild! = null) {
traverse (v firstChild , + + space); / / recursion to recall the same function for the first child node
}
if (v nextSibling! = null) {
traverse (v nextSibling , space); / / recursion, the call feature for the next node on the same level

}}

nodes are objects for which you can use certain methods and properties of the objects of the class of XML. Here are some of the properties, which make it possible to move around the tree:



  • attributes - returns an associative array containing the names of attributes and their values \u200b\u200b

  • childNodes - returns an array containing references to child nodes

  • firstChild - contains a reference the first child node

  • lastChild - a reference to the last child node

  • nextSibling - contains a reference to an adjacent node, or to the next node on the same level

  • previousSibling - contains a reference to a neighboring node, to the previous node on the same level

  • nodeName - returns the name tag or null if it is a text node

  • nodeValue - returns a text node or text, or null if it is a tag

  • nodeType - returns a number indicating the type of node: one is an element or tag, 3 is a text node

  • parentNode - the parent returns (each node can have only one parent)

  • hasChildNodes - the method returns true if the node has children)


text box with the html option in the player against six white space behaves just like a browser, such as contrast, interprets it in the player 5 displays all the whitespace and hence does not interpret difference in the code for examples.
result is displayed in this field is only to obtain a different font color for each node. Variables space, indent responsible for the proper indentation of nodes at different levels (something lame but it works so okryjmy a veil of silence:) So, after entering the function is displayed if the node is a text node, or its name if it is tag.
Next followed a recursive function call if the node has a child or sibling.
Property attributes returns an associative array pair: the name of the attribute and its value. For the value of each attribute can be reached in two ways:


  / / as the property of the object attributes 
. Nazwa_atrybutu
/ / or as elements in an array
attrubutes [" nazwa_atrybutu " ]

Read the entire associative array allows us to design:


   for (var   key  in  array) 
{/ / key - contains the name, array [key] - contains the value
}

6th "String" - a text representation of the object xmldoc - toString method . Showing is virtually the same as the xml file contains. One note after re-reading the document to the previous declarations of the object are preserved somewhere, although the new tree is created. If you want to avoid this, re-create the object and load the file to it.


   showString function () {
plainout = xmldoc. toString ();}


second issue in the player MX toString method works a little differently than in the player 5th The change is noticeable in CDATA sections, characters such as < > & '"are converted to equivalent ie \u0026lt;> &'" It should be remembered so that the value of text nodes are always referenced using the nodeValue or overwrite method toString :


  XMLNode .   prototype.  toString  =   function () {return 
this . nodeValue;}



Encoding For encoding was a big change between 5 and MX because it supports Unicode (UTF-16LE, UTF-16BE, and UTF-8). For Flash 5 text variables in the swf files were stored in the code latin1 (ISO-8859-1), whereas in the case of MX are converted to Unicode (this raises the problem as text variables, using the example of Polish characters, recorded in the swf MX 's are incorrectly read by the player in version 5). Similarly, the data read-off from EXTERNAL sources. Flash Player 5 treated all of them if they were in the code page of the operating system while the MX player treats them (by default) if they were in Unicode. To change this to use the statement:


   system. UseCodePage =   true; 

player 6

Then when reading external data will behave exactly like the 5th However, the application itself Flash MX for the read data command # include assumes that the files are in the code page of the operating system. Therefore, to tell her that the data is in Unicode should be the first line in the file put switchable recording, eg


//!-- UTF8

In the case of 5 when reading data from external sources on the screen to see the flower stalk and bushes had not used the code page of the data suitable for the system, eg Windows xml file should be in the code page system that is Windows-1250 for maca in the code page, etc. In the case of Macca MX sufficient data to be stored in Unicode, and should display correctly on all systems (provided, of course, choose the font, having tails). In the script, the values \u200b\u200bof text variables can be used Unicode encoding Polish letters or in the form of uNNNN . For example, these characters are used in the chain attributed to the variable plainout versus loaddata .



Letter Unicode
uNNNN
& # xNNNN;

Unicode & # NNN;
Letter Unicode
uNNNN
& # xNNNN;

Unicode & # NNN;
hex
decimal
Ą 0104 260 ń 0144 324
ą 0105 261 Ó 00D3 211
Ć 0106 262 ó 00F3 243
ć 0107 263 Ś 015A 346
Ę 0118 280 ś 015B 347
ę 0119 281 Ź 0179 377
Ł 0141 321 ź 017A 378
ł 0142 322 Ż 017B 379
Ń 0143 323 ż 017C 380

Character Entities


Flash does not include the DTD so that all definitions of units are not taken into account, and appeal to them in the xml document are treated as plain text. Are interpreted predefined character entities (& '> \u0026lt;') and numbered units are not interpreted correctly (see the table in the form of Unicode characters & # & # NNN and xNNNN). These units are also called entities see znakowymi, easily displayed by the browser, EKO, and converted to Polish letters. So maybe someday he would do it and Flash.


Useful links

Do You Need To Use Bait With A Swedish Pimple

ActionScript Basics - Loops.

Loop is a structure to implement the loop body down number of times, where the number of times depends on the parameters "transferred" loop. The
difficult? After reading this tutorial will provide a simple and logical because the loops are designed to automate your work. Use them whenever you need to manage similar properties similar objects, when you want to duplicate MovieClip'y which will serve a menu to assign the MovieClip'om onRelease events, etc, etc. Use a loop to view, content objects, strings and arrays. After some time you will see that the knowledge of your programming loop was the way by the passion, where he probably wrote the
  array = new Array    () 
array [0] = this [" klip0_mc "]
array [1] = this [" klip1_mc "]
array [2] = this [" klip2_mc "]
array [3] = this [" klip3_mc "]
array [4] = this [" klip4_mc "]
array [5] = this [" klip5_mc "]
/ / etc
array [0]. onRelease = function () {trace
( this . _name)}

array [1]. onRelease = function () {trace
( this . _name)}

array [2]. onRelease = function () {trace
( this . _name)

} / / etc, etc, etc. ..
... and you were proud to have written "tyyyle" code;)
And do not be simpler?
  var  ileKlipow = 10 
var array = new Array ();

for ( var j = 0, j <=ileKlipow; j++){ tablica[j] = this [" clip " + j + " _mc "]
array [j]. onRelease = function () {trace
( this . _name)
}}

}


Let's get to the point:)

loop
Description loop structure for .
  for  (initialization, warunek_ilości, iteration) {
/ / loop body}


The use of the loop for looks like this ...
  / / loop in action ... 
for (i = 0; and <10; style="color: rgb(0, 153, 255);"> trace (i)}


If this code is executed is a description of its operation (in a simplified) will look something like this: first
Loop is initiated on the value of i = 0, (remember that the variable name and it really is free).
second Then the condition if and <10> true (that is, if and is less than 10) the loop body is executed.
third Then the value and is incremented by 1 (with notation i + +).
4th Then everything begins again and continues until the test condition and <10> and loop is decremented (reduced), with the difference that you can use a different record structure of the loop.
  / / eg instead 
for (i = 10, and> 2, i -) {
trace (i)}

/ / you can write to shorten
for (i = 10; -; ) {
trace (i)}

As you can see, in the latter case you do not need to declare when the loop has to stop because when a variable and will be zero this value will be converted to a boolean value false the same loop will be aborted.
Please note that if a condition is not met for the first time, body of the loop is not executed even once.

Remember that if you construct a loop in which the condition never returns false , the publication of your movie will start an infinite loop, causing a compile error or even worse things.)
Example:
  / / Do not try this at home;] 
for (i = 0; and <3; color="#0099ff"> trace (i)}

look ... In every repetition of the loop condition is checked whether the variable and is less than 3, therefore, that the variable and was initiated with a value of 0 and during each cycle of its value is reduced by 1, this condition will never be satisfied, thus a compile error.

worth mentioning, before continuing the theme that, in each loop, we can use the increment or decrement is not based on the change in value by 1, but with any value.
eg
   for (i = 30, and> 3;  i-= 3 ) {
trace (i)}



while loop
Another example loops are loops while and to ... while (which a little below), basically the way they work is almost identical to the for .
   with var = value  / / equivalent initialization 
while (condition) {
/ body condition, and iteration
}
What can be translated into human language as
 until ( This condition is true) {
perform what is here
}

Generally in the while loop checks the condition that if it returns true (or can be converted to true) is executed body condition, and then loops, and so until the condition is not met.
  / / while in practice 
var c = 0
while (c <= 8){ trace (c)
c + +
}

/ / We can also shorten a little the record
var c = 0
while (c + + <= 8){ trace (c)
}
Another approach to the while loop can also be an example
   var x = 8 
while (x -) {
trace (x)}


/ / or
var x = 8
while (x) {trace
(x)
x -
}
As you can see, thanks knowledge of the initial value of the variable x we \u200b\u200bcan dekrementować directly in the loop condition while or outside of being certain that the loop is not infinite, because the reduced value of the variable will eventually reach 0, which will be converted to a boolean value false.
As for loop if the condition is not met for the first time, body of the loop is not executed even once.

Loop ... while
To prevent non-execution of the loop body we can use to ... while loop. Construction of the loop while to ... looks like
  to  
{/ / loop body}
while (condition)
which can be translated "the Polish" follows
 execute {
everything is here
} until (this condition is true)

using this type of loop, we are sure that the body loop is executed at least once.

loop ... in
loop type for ... in is used to calculate the properties (methods, etc) associated with the object, and it is so much interesting construction that does not require knowledge of where these properties really are.
construction of such a loop is as follows
  for  (property of  in  jakisObiekt) {
do it
}
Przykładzik:
   var person = new     Object () 
osoba.nazwisko = " Copernicus'
osoba.imie = "Nicholas "
osoba.wiek = " near pięćsetki "
osoba.zawod = " baker "

for (j in person) trace (" property: "+ j +" \\ nma value: "+ person [j] +" \\ n )

/ / Another example
array = new Array ( cat "" dog "," parrot "," Copernicus )
for (j in array) {trace
( index "+ j +" \\ nma value: "+ array [j] +" \\ n )
}

If this is not for you to completely clear this easy ... if a little pokombinujesz on their examples, similar to the above, you understand what's going on in the iteration object properties.

command break and continue
Two specific keywords that are associated with the use of loops are break and continue.

break
placement in the body of the loop break keyword causes immediately leave the loop and stop the further execution. For this reason, use this command has a justification in case of a specific condition.
Example of command break:
   for (i = 0; and <6; style="color: rgb(0, 153, 255);">  trace (i) 
if (i == 3) {break
;
trace ("this is not appears )
}}


As you can see the keyword break is similar in its action to the command return to functionality. You can add, moreover, that the use of return for the use of loop the function body will interrupt the performance of the loop, which in principle is clear because the immediate discontinuation of return will perform the same function .... Here is a moment to reflect on "what I just read?" and read this paragraph again;]

Example:
   check function () {
var i = 4
while (i -) {
if (i == 2) return;
trace (i)

}}
check ()


continue
Keyword continue used in the body of the loop causes an immediate exit from the body of the loop, the difference (in relation to the break) is that the loop is not stopped, but resumed the next natural cycle. Here
continue the use of command should also be dependent on the occurrence of a particular condition.
   var i = 5 
while (i -) {
if (i == 2) {continue
;
trace (" is not displayed ");
}
trace (i)}


Nesting loops.
very easy solution to save your job is to use nested loops.
Here's an example:
  for  ( var  i = 1; and <5; style="color: rgb(0, 153, 255);"> trace  (i + " CYCLE main loop. \\ N ) 
for (j = 1, j <5; style="color: rgb(0, 153, 255);"> trace ( 5 * (i-1) + j + "a series of nested )
if (j == 4) trace (" *************** \\ n ")

}}


Finally, it should be added that:
Remember that loops is not a tool to animate MovieClipów or engaging in activities that are based on time "class =" BlueLnk "> Remember that loops is not a tool to animate MovieClipów or engaging in activities that are based on time, so the thought of the loops as if they were executed "immediately." With the loop does not change the "smooth" the color of the clip, its location, size, transparency, or as loops not to serve . The manipulation of the properties MovieClipów Use setInterval and listener event handler MovieClip.onEnterFrame () which was widely and repeatedly discussed at the forum:)

So much the topic of the loop. If you have any questions regarding this tutorial, click on "comment on the forum" at the top right side:).

Lindsey Dawn Mc Kensey

Introduction to Flash Remoting AMFPHP

times are changing, changing versions of Flash, but most users do not change their habits, still using the methods which will soon be deprecated, or require a lot of the west for larger projects.



Technology Flash Remotingu is available from 6 versions of Flash. However, due to low availability for the average developer and a lack of materials on this flashed quietly not paying attention. This technology has its implementations. NET, Java, ColdFusion and other languages \u200b\u200bserverside built by default, or as separate library, low percentage of users of these technologies led to the remoting does not become too popular. However, some time is available for free (which is important) implementation in PHP



And here our story begins.



What is remoting?



Remoting is a simple way to exchange data between Flash and server language. What is different from LoadVars, etc.? There is a lot of arguments.
when transferring to a Flash one, two variables is not a problem. When you want to send a larger package of data using xml. And what if you want to use the database?
calling the server side sql query, translates it to XML (or even a string) you upload to Flash where you change into the back of a string of variables, objects, arrays, etc.

For such a simple thing is a bit of a long road. A significant loss of time and resources on a simple exchange of information.



Flash Remoting is a toolkit which includes a gateway server, a set of components, classes, and debugger. On the side of a set of classes you have Flash to encode and decode data. Similarly, a server-side gateway that performs the same task, and calls the desired method. Data is exchanged in binary format inspired by the AMF SOAP. Both gate and flash the class translate the data on neutral format, and it allows for the exchange of data between the various technologies behind the scenes.




What boils down to one thing - the exchange of data between the flash and in our case PHP is fast and simple.





So what advantages remotingu decide to abandon completely the other methods?

three basic factors should persuade you to do so - the behavior of variable types (String, Number, Array, Object [hash associative array if you like]), real objects returned by the sql query (there are no fetch_array etc.) and mapping of the classes ( What we develop here is not, unfortunately)



After all the raptures of technology, let's get down to particulars


Requirements AMFPHP

For correct operation is required PHP 4.3 and higher to 5 inclusive. It's official requirements, but in our situation can be said about needed for iconv library version 4.3 is available here to the correct handling of Polish characters. However, it is usually available on the servers, and PHP 5 is installed by default.

update to JanekCanI
You do not need to have installed any libraries that converts characters between other systems, if you have access to php.ini, and you can change the default encoding php pages. Then simply
$ gateway-> setCharsetHandler ("none", "utf-8", "utf-8");



Installation



installation pack downloaded the latest version of AMFPHP here or directly from the project download section.

Update:
AMFPHP 1.9 beta version can be downloaded here
But remember that this version differs from that described in the tutorial, no methodTable min and deactivated several typical ficzersów.




side

PHP server-side installation is reduced to copying the contents of the installation directory on the server. Ensure the proper functioning of the settings in the file gateway.php. The main change that we must introduce is to find this line




/ / $ gateway-> setCharsetHandler ("utf8_decode", "ISO-8859-1", "ISO-8859-1");



and replace the


$ gateway-> setCharsetHandler ("iconv", "ISO-8859-2", "ISO-8859-2");





What will enable us to support Polish characters. If this setting it does not work for Polish characters, you can try other versions, or replace this line at




$ gateway-> setCharsetHandler ("iconv", "UTF-8" "UTF-8");







If you feel that everything was done as it should, and later calling the methods of flah it does not work (even though in the debugger you can see that it was successful) check that you have iconv library installed, in the absence thereof, and such a setting in gateway.php AMFPHP does not need to return an error.
After preparing everything, run the file in your browser gateway.php possibly in search of errors. If your browser tries to download a file, it means that everything went as expected. Remember to leave all the files on the server, they are required for the proper functioning of the Federation. Only the Service Browser is advisable not to place on the final server, because it contains a preview of all the methods.

Remember that one installation supports an unlimited AMF (never given a limit) the number of services, including one plant can be used in parallel to many projects.





File debuggateway.php used to test and return a greater number of errors, but remember that when you start the system to switch system on gateway.php, because it is much more efficient.





side flash

remotingu access to classes and get after installing the extension that can be downloaded here



After installing this extension you get 5 basic elements



  • NetConnection debugger, the movie flash, which shows the course of inquiries in both directions. You can find C: \\ Documents and Settings \\ {username} \\ Local Settings \\ Application Data \\ Flash {in} \\ {language} \\ Configuration \\ WindowSWF \\ NetConnection Debugger.swf in flash or Window> Other Panels> NetConnection Debugger

  • Service Browser, which helps to view your services (like on-line version built into AMFPHP)

  • Help files, slightly protruding from the conventions of other parties to help, but they are a major source of information.

  • remotingu class libraries available in flash under Window> Common Libraries> Remoting or Window> Others> Libraries> Remoting

  • available
  • Component Connector Components> Data Components> RemotingConnector.




sure to include both packages (RemotingClasses and RemotingDebugClasses) in the library of every movie that uses FR






Testing


When all elements of time to test the system.

so the first will create a service (Service) server-side. Create a file HelloWorld.php and type in the


 


class HelloWorld {



function HelloWorld () {



$ this-> methodTable = array

(

"Scream" => array

(

"access" => "remote",

"description" => "Returns the sent message"

)

);}





function yell ($ message) {



return 'Dre' button. $ Message;



}}

?>


Thus prepared, place the php file in the folder of your installation services in AMFPHP

In this folder you must place all prepared for its services. You can view them by going in the folder browser, which is placed a simple and functional web browser of your services, together with the generated AS code to use.





Now in Flash, create a new document, go to Window> Common Libraries> Remoting
(or Window> Others> Libraries> Remoting depending on the version of flash) and drag the two parcels on the scene. Of course, even though they are visible they are not their graphical representations after the publication of the film.

Then in the first frame of the movie, paste the following code


 

mx.remoting import .*;

mx.rpc import .*;

import mx.remoting.debug.NetDebug;



gatewayUrl var: String = "http://localhost/flashservices/gateway.php" / / here, of course, the path to your installation AMF file instead gateway.php better when testing debuggateway.php use file, which is located in the same folder, and send more information to NetDebugerra



NetDebug.initialize ();

var _service: Service = new Service (gatewayUrl, null, 'HelloWorld', null, null) / / arguments are accepted: [path to goal, logger, the name of a method call, the responder]

/ / logger

/ / object in which the logs will be created, more information in the search for Log class

/ / call

/ / allows you to use an existing connection, such as nazwaUslugi.connection,

/

responder / responder object containing methods to support the results and errors



var pc: PendingCall = _service.krzycz ("Hello world !");// call a method and passing it some arguments, remember that you can communicate not only strings but virtually all of the available types of Tablets, including



pc. responder = new RelayResponder (this, "OnRezultat", "onError ");//

/ responder object is forwarded to it by calling the methods / functions after receiving a response from the server

/ / first argument is an object that receives the response, usually corresponds to the time line which includes the functions that support the results

/ / If this path is incorrect script does not react to the response from the server, which is a common mistake in the beginning.



onRezultat function (re: ResultEvent) {/ / This function is passed an object with the result returned by the method, eg the result of sql query, but more on that later

trace ('What drzesz,' + re.result);}





function onError (fe: FaultEvent) {/ / here with railways shall be forwarded to the error object

trace ('An error occurred, with the following Content: '+ fe.fault.faultstring) / / and so you can get to the content

}



Test the movie and displays a look at your Output window. You should get "What drzesz, Dre in Hello world!"




If, however, resulted in a prompt messages:


If you have information ** Error ** Scene = Scene 1, layer = Layer 1, frame = 1: Line 8: The class 'Service' could not be loaded. (...) You have not added correctly
classes for the film Choose Window> Common Libraries> Remoting (or Windows> Others> Libraries> Remoting) and drag the two classes on the scene, and later you can delete them, were important to the library of the film.



Error opening URL "http://localhost/flashservices/gateway.php"
incorrectly entered the path to the goal, or the server is not running.



"An error, which reads as follows: (...)"
Check the contents of error or look in the NetConnection Debugger window. You've made an error in the PHP class, or you do not type method to methodTable



If you do not receive any message, and the film after sending a query (which is seen in the debugger) does not correspond, check, written in PHP classes (by calling it in your browser), or check whether the firewall is not blocking requests.


types of data to be transferred



As mentioned several times before remoting allows to conduct the types of variables sent to both parties. The following table and are served with various types of restrictions.


























































array Array

types supported
Type in a flash `u type in PHP comments Auto Service
null null
so
Boolean (boolean) boolean
so
String string
so
Date float Unix timestamp, set the return type of the variable on the Date not

so
Object associative array
so
XML String Set return type to the XML variable to send to AS not
Recordset Resource Only from PHP to AS, not vice versa as


For types with automatic operation is not necessary to declare the return type. In another case
you need to apply a solution similar to that here


 


class RemoteData

{

RemoteData function () {



$ this-> methodTable = array (

"getRemoteDate" => array (

"description" => "Returns the server time as a Date object to flash",

"access" => "remote",

"returns" => "Date"

), / / \u200b\u200breturns determines the type of the return variable

"getRemoteDateString" => array (

'description' => 'Returns the time on the server in the form string in the format "Sun Mar 12 0:06:30 GMT 0800 2006 '',

"Access" => "remote",

)

"getTimezoneOffset" => array (

"description" => "Returns the difference in minutes, between universal time and the time server",

"access" => "remote",

)

);}





getRemoteDate function () {



/ / Note: you must return the time in milliseconds multiplied by the * 1000

return time () * 1000;

}



getRemoteDateString function () {



return date ('DM d H: i: s \\ G \\ M \\ IT Y', time ());}





getTimezoneOffset function () {



return date ('Z') / 60;



}}

?>




I hope that you are brought closer to the dimension of flash data exchange serverside, and encourage them to bid farewell to LoadCośtam.

Happy testing.

Female Genatalia Tattoos

based on variables in AS3 Preloader

variables


Apparently there is nothing to write about ... and yet, because, what can I talk to, without changing any programming language would be useless.

to the good stuff.
Generally speaking, the variable is a solution in which, since its creation, you can store virtually what you want: references to objects, properties, clips, numbers, functions, text, but which above all can use. With the help of variables and functions you can do what you want .. if you know how to go about it.: P

In Flash MX versions starting variables was divided into:
-
nonlocal variables - local variables
- global variables (Available from MX)
Here a closer look at


nonlocal variables are variables created in the timeline of the MovieClip'a or inside another object. The values \u200b\u200bin these variables are always stored in memory until the clip is in the player, (that is, until it is deleted or does not end its presence in the parent timeline) or variable (or object) will not be removed using operator delete .
in ActionScript is not required to declare a nonlocal variable by using the var keyword. Such variables are created at the time of naming them, or give them the character of the variable
 variable = 100 
trace (variable) / / output 100

For such variables, we have access not only to strip the current clip, we can come to It also appealed from anywhere in the film,
  / / on _root, declare a variable nonlocal 
var v = "abc "
/ / somewhere in the timeline clip nested
var text _root = . v + "def "
/ / Or
var text = _parent . _parent . _parent . V + "def "
trace (text)
/ / output: abcdef


Despite the fact that variable declaration does not require the use of the word var, it does use it in my mind, improves readability of the code and appears to be a good idea.

nonlocal variables can be declared in an object from another (say it) MovieClip'a
  / / example 
_root. JakisMC.zmienna = " hohoho "
in this case are prohibited words var.

following syntax:
_root.jakisMC.zmienna var = "hohoho"
... will compile error.


Local variables are temporary variables, declared in the function body and used when performing this function. Upon completion of the function variables such are removed from and does not pollute the memory of the player. The declaration of such variables did not differ from non-local variable declarations, except that if the declaration does not add the var keyword , this variable will be created as and after the non-local features will still be available, or changes the value of existing non-local variable of that name.
 show =   function () {
var a = "I'm " / / local variable declaration
trace (" in the function body: " + a)}

show ()

trace ("after the function : " + a)

in the output window, see:
functions in the body: I \u200b\u200bam
after the function undefined


If you've got the declaration of variable "a" word var would see the output window:
functions in the body: I \u200b\u200bam
after the function: I

In this particular case remains such a variable does not do us harm, but what if the memory is to us array is used to calculate some "matrix" with the 1500 indices, each consisting of 5 digit number?

not use the word var can also lead to non-local variable overwriting. Example
   var a = 1, b = 2, c = 3  / / declaration of variables nonlocal 
function show () {var
a = 25, b = 50; / / declaration of local variables
c = a + b}

show ()
trace (c) / / output 175

variable c has been overwritten.
If I would not use the word var in the function body would also be overwritten and b variables.
may be added that, as you noticed, a considerable ease of use is the following way variable declarations
  / / eg .. 
var a = 1, b = [], c = new LoadVars ();



Global variables are accessible from anywhere in the aforementioned film. Declaring, recall and change the value of such a variable is as follows:
  / / declaration of a global variable named "variab" 
_global . Variab = " value;

/ / change anywhere in the film
_global . variab = " completely different value "

/ / call the variable from anywhere in the film, using its value
MyText = Variab;
/ / or if on this timeline is variable
/ / with the same name as global variable (see explanation below)
MyText = _global . Variab;

Here it should be mentioned that if the timeline is another variable called "variab" will be read first of its value, the compiler will search the global object in the search for such a variable.
  / / example: 
_global . Variab = 5
variab = 100
var result = variab + 5
trace (result)
/ / output window, we see 105 instead of the "expected" 10
/ / variable variab was found in the timeline of the current clip

The use of global variables, if you really have a good reason.

link variables.


Note that variables are related to each other by value not by reference. Quickly let's see one example
   var a = 5 
var b = a a = 10

trace (b) / / output 5

The value of b has not changed although the changed value of the variable a. This is an instance variable with the value of links. The compiler does not remember "then" inherited value of the variable. The variable b given the value of another variable of the moment and this value was stored.

Referring to the variables.


Remember that the variable can be successfully appealed, if it exists. Example:
   var added = x + x 
var x = 5
trace (added) / / output: undefined

To refer to a variable, you must first create it.


Types in ActionScript is not required to comply with the data types stored in the variables. If you declare a variable which stores the data string is at any time you can override this variable so that kept the data type Number, or any other.
  / / example var 

angle = 270 angle = " dwieściesiedemdziesiąt "

compiler will not spit in this case, no error. However
Flash MX2004 from the introduction of language and ActionScript2 can control the data type using the syntax
   var angle:   String = " dwieściesiedemdziesiąt " 
If we try to put in the variable data, other than a String, (eg .: angle = 270), the compiler does not allow such an operation.

So much for the subject variables. I hope this brightened reels you some things.
Pozdr.

Reproduction Robe Titanic Kate Winslet



Preloader in AS3


in pure AS3 Since everything is placed in the first frame, You can not create prelodera because it will start only after everything is loaded in the first frame. What to do? There is a frame called metadata, which makes the class passed as a parameter is run in the first frame, and the whole is transferred to another cage. Unfortunately, there are drawbacks to light. Our preloader becomes the root. What does this mean? In our main class can not be appealed to the stage because they will get an error about not referring to an existing item (can get around this, but more on that later). Furthermore, everything that relates to stage such StageScaleMode must be preloaderze, probably SWF metadata is also (have not checked this). If you are using things like Google is Tweener.init Tweener () will also be placed in the preloader class.

First we create our preloader:

 com.kuzimski 
package {import
flash.display.DisplayObject;
import flash.display . MovieClip;
flash.display.StageAlign import, import
flash.display.StageScaleMode;
import flash.display.StageQuality;
import flash.events.Event;
import flash. utils.getDefinitionByName;
import caurina.transitions.Tweener;

public class Preloader extends MovieClip {

public function Preloader () {

Tweener. init (stage); / / these things that need to be root in this class we
stop (); / / we need to stay in the first frame
stage. scaleMode = StageScaleMode.NO_SCALE;
stage. align = StageAlign.TOP_LEFT;
Stage.showDefaultContextMenu = false ;
stage.quality = StageQuality.BEST;
addEventListener(Event.ENTER_FRAME, onEnterFrame );
}

private function onEnterFrame (event:Event):void
{

if (framesLoaded == totalFrames)
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame );
nextFrame ();
init ();
}
else
{
trace (root.loaderInfo.BytesLoaded+" / "+root.loaderInfo.BytesTotal);

}}

private function init (): void {

var mainClass: Class = Class getDefinitionByName ( SampleClass ")); / / create a class to instantiate our shit, we use getInstanceByName, so you do not have to add it in the first frame
if (mainClass) {

var app: Object = new mainClass (stage); / / here solved the problem of recourse to the stage, enough to pass the stage as a parameter to the main class, and there we can do with what we
addChild (app as DisplayObject); / / no, and finally add our main class of the scene. Here you should zwrocc note that in this way our class is not on top of the list wyswietalnych objects (for luck is a preloader)


}}}




now our principal class




package {

import flash.display . MovieClip;

[Frame (factoryClass = " com.kuzimski.Preloader ")] / / here we put our preloader to the first frame

public class SampleClass extends MovieClip {


private var myStage: Object ;

public function SampleClass (_stage: Object) {

myStage = _stage;
trace (MyStage.stageWidth);

}}}






do not know why I can not take advantage of events like the preloaderze
Progress and Complete (just do not odpalaja, fires only in August init) ... I would prefer it to be
on events because such a solution with totalFrames
not like me.



Based http://www.bit-101.com/blog/?p=946.
}