Actionscript 3.0 for beginners: lesson # 4

Tuesday, 11 November, 2008

Resume our sample code of TicTacToe (which is entirely on Google Code) and we start to analyze it in detail.

Import definitions

With Actionscript 3.0 has been done a great job of cleaning and arrangement of classes nell'alberatura (contained in the package package) used during development. In other programming languages, like C for example, when you want to use a feature must explicitly "import" in the code. This operation "import" is necessary to allow the compiler to have all the codes and definitions related features that we want to use. In Actionscript 3.0, however, Education import should not be confused with the standard C / C + #include # #include Actionscript 3.0 provides education include that is identical to #include the C / C + +. The latter include "actual code that, if used or not, is compiled into the final. Education import is the highest level and is more "intelligent" being compiled. It serves primarily to access classes without having to specify the full name. In Alré words instead of using forms like this:

Actionscript:
  1. . MovieClip = new flash. display . MovieClip ( ) ; var myMC: flash. display. MovieClip = new flash. display. MovieClip ();

Continue reading ... "

Related Post

Wordpress: remove the menu

Saturday, November 1, 2008

It may be useful, sometimes, "obscure" some of the menu of Wordpress, especially if you developed a website / blog for a client and do not want to allow access to sensitive features. There Plugin already performing this function, but to have a personal and complete control, we see in detail how this feature.
As always exploit the useful Action made available by Wordpress, in this case admin_menu Through the global variable $menu can access the list of the menu. We can find the menu to "remove" in two ways: through the label or via the link that it points (see commented shares in the example below). The proposal is "obscured" menu items Design, Settings and Plugins:

PHP:
  1. remove_menu_item function () (
  2. ; global $ menu;
  3. / / By label
  4. ( 'Design' , 'Impostazioni' , 'Plugins' ) ; $ removes = array ( 'Design', 'Settings',' Plugins');
  5. / / Through links
  6. / / $ Removes = array ( 'themes.php', 'options-general.php', 'plugins.php');
  7. $removes as $todel ) foreach ($ removes as $ todel)
  8. $menu as $key => $sm ) if ( $sm [ 0 ] == $todel ) { unset ( $menu [ $key ] ) ; break ; } foreach ($ menu as $ key => $ sm) if ($ sm [0] == $ todel) (unset ($ menu [$ key]); break;)
  9. / / Through links
  10. / / Foreach ($ menu as $ key => $ sm) if ($ sm [2] == $ todel) (unset ($ menu [$ key]); break;)
  11. )
  12. / /
  13. , 'remove_menu_item' ) ; add_action ( 'admin_menu', 'remove_menu_item');

Using the links as key to the removal $sm[2] in parts commented code surprise here), is useful when there is certainty of language - location - with which you installed Wordpress. With this technique, however, the menu is removed only at the interface, so you can still access the page via a direct link.

Related Post

Very short trick: undefined values in Javascript

Wednesday, 22 October, 2008

There is an abbreviated form for assigning "in flight" a value to a variable if another is not defined (undefined), using the logical OR operator (| |) - Double-pipe:

JavaScript:
  1. / / Pluto is undefined
  2. var pluto;
  3. ; var foo = pluto | |'5 ';
  4. pippo ) ; alert (foo);
  5. / / Result: 5

This technique is useful for writing functions with parameters:

JavaScript:
  1. param ) { miaFunc function (param) (
  2. ; var p1 = param | | 'benchmark';
  3. / / ...
  4. )

But we must be careful to use this form as zero values such as 0 false are misinterpreted, because of "guilt" of the OR logic used:

JavaScript:
  1. ; pluto var = 0;
  2. ; var foo = pluto | |'5 ';
  3. pippo ) ; alert (foo);
  4. / / Result: 5
  5. ; pluto var = false;
  6. ; var foo = pluto | |'5 ';
  7. pippo ) ; alert (foo);
  8. / / Result: 5
  9. ; pluto var = 1;
  10. ; var foo = pluto | |'5 ';
  11. pippo ) ; alert (foo);
  12. / / Result: 1

Related Post

Very short trick: avoid error message in PHP

Wednesday, October 8, 2008

If we do not want a PHP issue any error or warning, just enter the first call to the function of the snail - or at - (@):

PHP:
  1. / / Instead of using the canonical form
  2. ; $ res = miaFunc ();
  3. / / You can use
  4. ; $ res = @ miaFunc ();

Related Post

Very short trick: PHP cars echo

Thursday, October 2, 2008

In PHP you can use an abridged form, or contracted, to see returns of variable or functions:

PHP:
  1. / / Instead of
  2. $miavar ?> <? php echo $ miavar?>
  3. / / You can write
  4. ?> <? = $ Miavar?>
  5. / / Instead of
  6. miaFunc ( ) ?> <? php echo miaFunc ()?>
  7. / / You can write
  8. ?> <? MiaFunc = ()?>

Related Post

Actionscript 3.0 for beginners: lesson # 3

Sunday, September 28, 2008

We continue analyzing the example of the game Tic Tac Toe, in Actionscript 3.0 for beginners: lesson # 2. We had arrived at the function that creates the grid of game:

Actionscript:
  1. / **
  2. * Drawing graphically the grid (3x3) on screen
  3. *
  4. * @ Param void
  5. * @ Return void
  6. * @ Private
  7. * /
  8. createGrid ( ) : void { createGrid private function (): void (
  9. / / Pointer to a temporary object MovieClip
  10. / / Note: here you could also use an object Sprite
  11. / / But in this case I need to be able to extend object
  12. / / Adding some personal proproetà. The object Sprite
  13. / / A class is closed and therefore not extended runtime, while
  14. / / MovieClip class is a class dynamic and therefore makes
  15. / / Possible addition of properties runtime
  16. , i:uint = 0 ; var tm: MovieClip, i: UINT = 0;
  17. / / Add a 3x3 in the MovieClip
  18. ; i < 9 ; i++ ) { for (i <9; i + +) (
  19. ( ) ; tm = new MovieClip ();
  20. ; addChild (tm);
  21. i% 3 ) * ( PLAYER_WIDTH+PLAYER_OFFSET ) ) tm. OFFSETX = x + ((i% 3) * (PLAYER_WIDTH + PLAYER_OFFSET))
  22. . floor ( i/ 3 ) * ( PLAYER_HEIGHT+PLAYER_OFFSET ) tm. offsety + y = Math. floor (i / 3) * (PLAYER_HEIGHT + PLAYER_OFFSET)
  23. tm._index = i;
  24. ) ; drawPlayer (tm, 0);
  25. )
  26. / / Drawing veriticali the 2 lines and 2 horizontal
  27. this . graphics ) { with (this. graphics) (
  28. 6 ,0x666666 ) ; LineStyle (6, 0x666666);
  29. OFFSETX,OFFSETY+ ( PLAYER_HEIGHT+ 15 ) ) ; moveTo (OFFSETX, offsety + (PLAYER_HEIGHT + 15));
  30. OFFSETX+ ( ( PLAYER_WIDTH+ 20 ) * 3 ) ,OFFSETY+ ( PLAYER_HEIGHT+ 15 ) ) ; lineTo (OFFSETX + ((PLAYER_WIDTH + 20) * 3), offsety + (PLAYER_HEIGHT + 15));
  31. OFFSETX,OFFSETY+ ( PLAYER_HEIGHT+ 20 ) * 2 ) ; moveTo (OFFSETX, offsety + (PLAYER_HEIGHT + 20) * 2);
  32. OFFSETX+ ( ( PLAYER_WIDTH+ 20 ) * 3 ) ,OFFSETY+ ( PLAYER_HEIGHT+ 20 ) * 2 ) ; lineTo (OFFSETX + ((PLAYER_WIDTH + 20) * 3), offsety + (PLAYER_HEIGHT + 20) * 2);
  33. OFFSETX+ ( PLAYER_WIDTH+ 15 ) ,OFFSETY ) ; moveTo (OFFSETX + (PLAYER_WIDTH + 15), offsety);
  34. OFFSETX+ ( PLAYER_WIDTH+ 15 ) ,OFFSETY+ ( ( PLAYER_HEIGHT+ 20 ) * 3 ) ) ; lineTo (OFFSETX + (PLAYER_WIDTH + 15), offsety + ((PLAYER_HEIGHT + 20) * 3));
  35. OFFSETX+ ( PLAYER_WIDTH+ 20 ) * 2 ,OFFSETY ) ; moveTo (OFFSETX + (PLAYER_WIDTH + 20) * 2, offsety);
  36. OFFSETX+ ( PLAYER_WIDTH+ 20 ) * 2 ,OFFSETY+ ( ( PLAYER_HEIGHT+ 20 ) * 3 ) ) ; lineTo (OFFSETX + (PLAYER_WIDTH + 20) * 2, offsety + ((PLAYER_HEIGHT + 20) * 3));
  37. )
  38. )

Continue reading ... "

Related Post

jQuery: how to build an extension Plugin

Tuesday, September 23, 2008

Like all libraries of this kind also jQuery can extend its basic functionality using real plugin. Respecting the rules of its operation, namely restituiendo always a pointer to the selected or jQuery itself, you can write a plugin with a few lines of code. Take as an example the code proposed in jQuery against everyone: a benchmark with 5 browser that was (after the correction reported by Luca):

JavaScript:
  1. ) . css ( 'cursor' , 'pointer' ) . click ( $ ( 'H2.dropdown'). Css ( 'cursor', 'pointer'). Click (
  2. function () (
  3. $ ( this ) . next ( ) . is ( ':hidden' ) ) $ ( this ) . next ( ) . slideDown ( ) ; else $ ( this ) . next ( ) . slideUp ( ) ; if ($ (this). next (). is ( ': hidden')) $ (this). next (). slideDown (); else $ (this). next (). slideUp ();
  4. )
  5. );

Continue reading ... "

Related Post

Actionscript 3.0 for beginners: lesson # 2

Wednesday, September 3, 2008

As promised here is the second lesson on ActionScript 3.0! Today we begin the analysis of a simple project that plays the game of Tic Tac Toe or Tic Tac Toe. I tried to include in this example, some features of ActionScript 3.0, trying to make room for understanding, not style. It follows that if I had to write the "game" really, probably would have structured so much different, but in this case I have tried to mediate between a classical programming compact and tight with a more understandable for beginners. I made a single class document, a procedure not necessary but useful to keep in line with the previous lesson.

Tic Tac Toe

Loading Flash Player ...

Continue reading ... "

Related Post

Simple Accordion with the class USimpleTabStrip

Wednesday, August 20, 2008

The class USimpleTabStrip submitted unobtrusive Simple TabStrip, can also be used to create a simple menu Accordion.
Using the effects of BlindUp() BlindDown() offered by Scriptaculous:

JavaScript:
  1. function init () (
  2. ; UTS = new USimpleTabStrip ();
  3. ; UTS. Init ();
  4. ( e ) { UTS. onShow = function (e) (
  5. ( e ) ; new Effect. BlindDown (e);
  6. )
  7. ( e ) { UTS. onHide = function (e) (
  8. ( e ) ; new Effect. BlindUp (e);
  9. )
  10. )

And put it back on the HTML (HTML source):

HTML:
  1. > <div class = "accordion">
  2. > Accordion 1 </a> <a href = "#acc1"> Accordion 1 </ a>
  3. > </a> <a name = "acc1"> </ a>
  4. <h1> Content # 1 </ h1>
  5. <p> Bla bla bla .... </ p>
  6. </ div>
  7. > Accordion 2 </a> <a href = "#acc2"> Accordion 2 </ a>
  8. > </a> <a name = "acc2"> </ a>
  9. <h1> Content # 2 </ h1>
  10. <p> Bla bla bla .... </ p>
  11. </ div>
  12. > Accordion 3 </a> <a href = "#acc3"> Accordion 3 </ a>
  13. > </a> <a name = "acc3"> </ a>
  14. <h1> Content # 3 </ h1>
  15. <p> Bla bla bla .... </ p>
  16. </ div>
  17. </ div>

You get a simple menu Accordion that can be used in very fast.

Related Post

Simple unobtrusive TabStrip

Thursday 14 August, 2008

USimpleTabStrip is an unobtrusive Javascript to improve classici link anchor (yet) within an HTML page. This source is an improvement of the function presented in TabStrip unobtrusive. In this version also align the code to release 1.6 of prototype.js was created a real class to manage the TabStrip. The release here is very simple and straightforward. Its main work lies in adding an event click the link anchor normal. Not be submitted CSS styles, just to leave the maximum freedom of action, but you can get an effective TabStrip with a few lines of code add CSS, see Adding CSS styles below.

HTML

The class USimpleTabStrip working on a very simple HTML, the anchor sftuttando <a name></a>

HTML:
  1. <! - Simple list of links on the page ->
  2. > Link 1 </a> </li> <li> <a href = "#tbs1"> Link 1 </ a> </ li>
  3. > Link 2 </a> </li> <li> <a href = "#tbs2"> Link 2 </ a> </ li>
  4. > Link 3 </a> </li> <li> <a href = "#tbs3"> Link 3 </ a> </ li>
  5. </ ul>
  6. <! - Blocks / tabs ->
  7. > </a> <a name = "tbs1"> </ a>
  8. <h1> Card # 1 </ h1>
  9. <p> Bla bla bla .... </ p>
  10. </ div>
  11. > </a> <a name = "tbs2"> </ a>
  12. <h1> Card # 2 </ h1>
  13. <p> Bla bla bla .... </ p>
  14. </ div>
  15. > </a> <a name = "tbs3"> </ a>
  16. <h1> Card # 3 </ h1>
  17. <p> Bla bla bla .... </ p>
  18. </ div>

The tag div just below the anchor a work from the container.

Continue reading ... "

Related Post