2009. február 28., szombat

PHP: Tömbök

<?php

// defining a simple array

$array1 = array(4,8,15,16,23,42);



// referencing an array value by its index

echo $array1[0];



// arrays can contain a mix of strings, numbers, even other arrays

$array2 = array(6,"fox", "dog", array("x", "y", "z"));



// referencing an array value that is inside another array

echo $array2[3][1];

?>

<br />

<?php

// Changing values in an array that has already been defined

// It's just like variables but you use the index to reference the array position

$array2[3] = "cat";

echo $array2[3];

?>

<br />

<?php

// You can also assign labels to each pocket (called "keys"),

$array3 = array("first_name" => "Kevin", "last_name" => "Skoglund");



// which will allow you to use the key to reference the value in that array position.

echo $array3["first_name"] . " " . $array3["last_name"] . "<br />";

$array3["first_name"] = "Larry";

echo $array3["first_name"] . " " . $array3["last_name"] . "<br />";

?>

<br />

A good way to see the values inside an array during development:<br />

<pre><?php print_r($array2); ?></pre>


                       

//Array Functions

Count: <?php echo count($array1); ?><br />

Max value: <?php echo max($array1); ?><br />

Min value: <?php echo min($array1); ?><br />

<br />


Sort: <?php sort($array1); print_r($array1); ?><br />

Reverse Sort: <?php rsort($array1); print_r($array1); ?><br />

<br />


            <?php

// Implode converts an array into a string using a "join string"

// Explode converts a string into an array using a "divide string"

?>

Implode: <?php echo $string1 = implode("---", $array1); ?><br />

Explode: <?php print_r(explode("---", $string1)); ?><br />

<br />

In array: <?php echo in_array(15, $array1); // returns T/F ?><br />

PHP: Számok

// jelmagy.: < = [[_ , > = _]]


[[_ html _]]
[[_ head _]]
[[_ title _]]Numbers[[_ /title _]]
[[_ /head _]]

[[_ body _]]
[[_ ?php
$num1 = 3;
$num2 = 4;
? _]]

+= : [[_ ?php $num1 += 4; echo $num1 ? _]] [[_ br / _]]
-= : [[_ ?php $num1 -= 4; echo $num1 ? _]] [[_ br / _]]
*= : [[_ ?php $num1 *= 4; echo $num1 ? _]] [[_ br / _]]
/= : [[_ ?php $num1 /= 4; echo $num1 ? _]] [[_ br / _]]
increment: [[_ ?php $num1 ++; echo $num1 ? _]] [[_ br / _]]
decrement: [[_ ?php $num1 --; echo $num1 ? _]] [[_ br / _]]


//Floating Point Numbers
[[_ br / _]]
[[_ ?php $myFloat = 3.14; ? _]]
Round: [[_ ?php echo round($myFloat,1); ? _]] [[_ br / _]]
Ceiling: [[_ ?php echo ceil($myFloat); ? _]] [[_ br / _]]
Floor: [[_ ?php echo floor($myFloat); ? _]] [[_ br / _]]

Absolute value: [[_ ?php echo abs(-500); ? _]] [[_ br / _]]
Exponential: [[_ ?php echo pow(2,4); ? _]] [[_ br / _]]
Square root: [[_ ?php echo sqrt(100); ? _]] [[_ br / _]]
Modulo: [[_ ?php echo fmod(20,7); ? _]] [[_ br / _]]
Random (any): [[_ ?php echo rand(); ? _]] [[_ br / _]]
Random (min, max): [[_ ?php echo rand(1,10); ? _]] [[_ br / _]]

[[_ /body _]]
[[_ /html _]]

2009. február 17., kedd

Actionscript 3.0 - Video

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.play("01.flv");

var myVideo:Video = new Video(320,240);
myVideo.attachNetStream(ns);
addChild(myVideo);

var stop_btn:Stop = new Stop();
var play_btn:Play = new Play();
stop_btn.x = 170;
stop_btn.y = 250;
play_btn.x = 140;
play_btn.y = 250;
addChild(stop_btn);
addChild(play_btn);

stop_btn.addEventListener(MouseEvent.CLICK, stopVid);
play_btn.addEventListener(MouseEvent.CLICK, playVid);

function stopVid(event:MouseEvent):void
{
ns.pause();
}

function playVid(event:MouseEvent):void
{
ns.resume();
}

Actionscript 3.0 - Fruit class

Fruit.as
--------

package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;

public class Fruit extends MovieClip
{
public var _hitTarget:MovieClip;
public var _startX:Number;
public var _startY:Number;

public function Fruit()
{
_startX = this.x;
_startY = this.y;
this.buttonMode = true;
this.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);
this.addEventListener(MouseEvent.MOUSE_UP, dropIt);
}

private function dragIt(event:MouseEvent):void
{
this.startDrag();
}

private function dropIt(event:MouseEvent):void
{
this.stopDrag();
}
}
}

Actionscript 3.0 - MatchingGame class

MatchingGame.as
-------------------


package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import Fruit;
import Win;
import flash.net.URLRequest;
import flash.events.Event;
import flash.media.Sound;

public class MatchingGame extends MovieClip
{
private var _numFruit:Number = 3;
private var _currentScore:Number = 0;
private var mySound:Sound;

public function MatchingGame()
{
txtBanana_mc._hitTarget = banana_mc;
txtApple_mc._hitTarget = apple_mc;
txtOrange_mc._hitTarget = orange_mc;
txtBanana_mc.addEventListener(MouseEvent.MOUSE_UP, score);
txtApple_mc.addEventListener(MouseEvent.MOUSE_UP, score);
txtOrange_mc.addEventListener(MouseEvent.MOUSE_UP, score);

var soundRequest:URLRequest = new URLRequest("blip.mp3");
mySound = new Sound();
mySound.load(soundRequest);
}

private function score(event:MouseEvent):void
{
if(event.target.hitTestObject(event.target._hitTarget))
{
_currentScore++;
event.target.visible = false;
event.target._hitTarget.visible = false;
mySound.play();

if (_currentScore >= _numFruit)
{
var win:Win = new Win();
win.x = stage.stageWidth/2;
win.y = stage.stageHeight/2;
addChild(win);
}
}
else
{
event.target.x = event.target._startX;
event.target.y = event.target._startY;
}
}
}
}

Actionscript 3.0 - ButtonApp class

ButtonApp.as
--------------


package
{
import flash.display.MovieClip;
import GreenButton;

public class ButtonApp extends MovieClip
{
public function ButtonApp()
{
var green_mc:GreenButton = new GreenButton();
green_mc.x = 200;
green_mc.y = 50;
this.addChild(green_mc);

var blue_mc:BlueButton = new BlueButton();
blue_mc.x = 200;
blue_mc.y = 150;
this.addChild(blue_mc);

var red_mc:RedButton = new RedButton();
red_mc.x = 200;
red_mc.y = 250;
this.addChild(red_mc);
}
}
}

Actionscript 3.0 - Button class

Button.as
----------


package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;

public class Button extends MovieClip
{
public function Button()
{
this.buttonMode = true;
this.addEventListener(MouseEvent.MOUSE_OVER, expand);
this.addEventListener(MouseEvent.MOUSE_OUT, contract);
}

private function expand(event:MouseEvent):void
{
this.scaleX = this.scaleY = 1.1;
}

private function contract(event:MouseEvent):void
{
this.scaleX = this.scaleY = 1;
}
}
}