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;
}
}
}

Actionscript 3.0 - MoveSmiley 3

var speed:Number = 6;
var key:Number;

stage.addEventListener(KeyboardEvent.KEY_DOWN, animate);
stage.addEventListener(KeyboardEvent.KEY_UP, stopAnimation);

function animate(event:KeyboardEvent):void
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, animate);
key = event.keyCode;
smiley_mc.addEventListener(Event.ENTER_FRAME, moveSmiley);
}

function stopAnimation(event:KeyboardEvent):void
{
if (key == event.keyCode)
{
smiley_mc.removeEventListener(Event.ENTER_FRAME, moveSmiley);
stage.addEventListener(KeyboardEvent.KEY_DOWN, animate);
}
}

function moveSmiley(event:Event):void
{
switch (key)
{
case 37:
smiley_mc.x -= speed;
break;
case 38:
smiley_mc.y -= speed;
break;
case 39:
smiley_mc.x += speed;
break;
case 40:
smiley_mc.y += speed;
break;
default:
break;
}
}

/*
var myNumber:Number = 80;

if (myNumber == 10)
{
trace("myNumber equals 10");
}
else if (myNumber == 8)
{
trace("myNumber equals 8");
}
else
{
trace("myNumber does not equal 10 OR 8");
}
*/

/*var myLetter:String = "b";

switch (myLetter)
{
case "a":
trace("a");
break;
case "b":
trace("b");
break;
case "c":
trace("c");
break;
default:
break;
}*/

Actionscript 3.0 - Easing

import fl.transitions.Tween;
import fl.transitions.easing.*;

new Tween(circle_mc, "alpha", Regular.easeOut, 0, 1, 2, true);


/*
new Tween(circle_mc, "x", None.easeNone, circle_mc.x, 450, 40, false);
new Tween(circle_mc, "y", Bounce.easeOut, circle_mc.y, 320, 40, false);
*/

Actionscript 3.0 - Tween

import fl.transitions.Tween;
import fl.transitions.easing.*;

new Tween(circle_mc, "x", Strong.easeOut, circle_mc.x, 450, 24, false);
new Tween(circle_mc, "y", Strong.easeOut, circle_mc.y, 350, 24, false);

Actionscript 3.0 - Interactive-animation

var myTimer:Timer = new Timer(20);
myTimer.addEventListener(TimerEvent.TIMER, moveBall);
stage.addEventListener(MouseEvent.MOUSE_DOWN, triggerTimer);

var speed:Number = 20;
var startX:Number;
var startY:Number;
var endX:Number;
var endY:Number;
var i:Number;

function triggerTimer(event:MouseEvent):void
{
startX = ball_mc.x;
startY = ball_mc.y;
endX = stage.mouseX;
endY = stage.mouseY;
i = 0;
myTimer.start();
}

function moveBall(event:Event):void
{
if(i < speed)
{
ball_mc.x += (endX - startX) / speed;
ball_mc.y += (endY - startY) / speed;
}
else
{
myTimer.stop();
}
i++;
}

Actionscript 3.0 - Destionation-animation

var myTimer:Timer = new Timer(80);
myTimer.addEventListener(TimerEvent.TIMER, moveBall);
myTimer.start();

var speed:Number = 20;
var startX:Number = ball_mc.x;
var startY:Number = ball_mc.y;
var endX:Number = 400;
var endY:Number = 300;
var i:Number = 0;

function moveBall(event:Event):void
{
if(i < speed)
{
ball_mc.x += (endX - startX) / speed;
ball_mc.y += (endY - startY) / speed;
}
else
{
myTimer.stop();
}
i++;
}

Actionscript 3.0 - Timer

var myTimer:Timer = new Timer(40);
myTimer.addEventListener(TimerEvent.TIMER, moveBall);
myTimer.start();

function moveBall(event:Event):void
{
if (ball_mc.x < stage.stageWidth - ball_mc.width && ball_mc.y < stage.stageHeight - ball_mc.height)
{
ball_mc.x += 5;
ball_mc.y += 1;
}
else
{
myTimer.stop();
}
}

Actionscript 3.0 - EnterFrame

ball_mc.addEventListener(Event.ENTER_FRAME, moveBall);

function moveBall(event:Event):void
{
if (ball_mc.x < stage.stageWidth - ball_mc.width && ball_mc.y < stage.stageHeight - ball_mc.height)
{
ball_mc.x += 5;
ball_mc.y += 1;
}
else
{
ball_mc.removeEventListener(Event.ENTER_FRAME, moveBall);
}
}

Actionscript 3.0 - For ciklus

var myArray:Array = new Array();

for (var i:Number = 1; i <= 50; i++)
{
myArray.push(i);
}

for (var j:Number = 0; j < myArray.length; j++)
{
trace(myArray[j]);
}

Actionscript 3.0 - While, Do-While

var i:Number = 1;

while (i <= 5)
{
trace(i);
i++;
}

var j:Number = 0;

do
{
trace(j);
j++;
}
while (j < 5);

Actionscript 3.0 - Tömbök

var myArray:Array = new Array();

myArray[0] = "oranges";
myArray[1] = "steak";
myArray[2] = "salt";
myArray[3] = "flour";
myArray.push("sugar");


trace("index 0 = " + myArray[0]);
trace("index 1 = " + myArray[1]);
trace("index 2 = " + myArray[2]);
trace("index 3 = " + myArray[3]);
trace("index 4 = " + myArray[4]);

Actionscript 3.0 - AimTarget

top_mc.buttonMode = true;
bottom_mc.buttonMode = true;
arrow_mc.buttonMode = true;

top_mc.addEventListener(MouseEvent.MOUSE_DOWN, addProp);
bottom_mc.addEventListener(MouseEvent.MOUSE_DOWN, addProp);
arrow_mc.addEventListener(MouseEvent.CLICK, goToTarget);

function addProp(event:MouseEvent):void
{
arrow_mc.aimTarget = event.target;
}

function goToTarget(event:MouseEvent):void
{
if (arrow_mc.aimTarget)
{
arrow_mc.x = arrow_mc.aimTarget.x;
arrow_mc.y = arrow_mc.aimTarget.y;
}
}

Actionscript 3.0 - AimTarget

top_mc.buttonMode = true;
bottom_mc.buttonMode = true;
arrow_mc.buttonMode = true;

top_mc.addEventListener(MouseEvent.MOUSE_DOWN, addProp);
bottom_mc.addEventListener(MouseEvent.MOUSE_DOWN, addProp);
arrow_mc.addEventListener(MouseEvent.CLICK, goToTarget);

function addProp(event:MouseEvent):void
{
arrow_mc.aimTarget = event.target;
}

function goToTarget(event:MouseEvent):void
{
if (arrow_mc.aimTarget)
{
arrow_mc.x = arrow_mc.aimTarget.x;
arrow_mc.y = arrow_mc.aimTarget.y;
}
}

Actionscript 3.0 - MoveSmiley 2

stage.addEventListener(KeyboardEvent.KEY_DOWN, moveSmiley);

function moveSmiley(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case 37:
smiley_mc.x -= 10;
break;
case 38:
smiley_mc.y -= 10;
break;
case 39:
smiley_mc.x += 10;
break;
case 40:
smiley_mc.y += 10;
break;
default:
break;
}
}

/*
var myNumber:Number = 80;

if (myNumber == 10)
{
trace("myNumber equals 10");
}
else if (myNumber == 8)
{
trace("myNumber equals 8");
}
else
{
trace("myNumber does not equal 10 OR 8");
}
*/

/*var myLetter:String = "b";

switch (myLetter)
{
case "a":
trace("a");
break;
case "b":
trace("b");
break;
case "c":
trace("c");
break;
default:
break;
}*/

Actionscript 3.0 - MoveSmiley

stage.addEventListener(KeyboardEvent.KEY_DOWN, moveSmiley);

function moveSmiley(event:KeyboardEvent):void
{
if (event.keyCode == 39)
{
smiley_mc.x += 10;
}
else if (event.keyCode == 37)
{
smiley_mc.x -= 10;
}
}

var myNumber:Number = 80;

/*
if (myNumber == 10)
{
trace("myNumber equals 10");
}
else if (myNumber == 8)
{
trace("myNumber equals 8");
}
else
{
trace("myNumber does not equal 10 OR 8");
}
*/

Actionscript 3.0 - KeyboardEvent

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);

function keyPressed(event:KeyboardEvent):void
{
trace(event.keyCode);
}

Actionscript 3.0 - Eventlistener 2

button1_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonGrow);
button1_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonShrink);
button2_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonGrow);
button2_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonShrink);

function buttonGrow(event:MouseEvent):void
{
event.target.scaleX = event.target.scaleY = 1.1;
}

function buttonShrink(event:MouseEvent):void
{
event.target.scaleX = event.target.scaleY = 1;
}

Actionscript 3.0 - Eventlistener

button_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonGrow);
button_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonShrink);

function buttonGrow(event:MouseEvent):void
{
button_btn.scaleX = button_btn.scaleY = 1.1;
}

function buttonShrink(event:MouseEvent):void
{
button_btn.scaleX = button_btn.scaleY = 1;
}

Actionscript 3.0 - Függvény

function changeCircle(alphaNum:Number):void
{
circle_mc.alpha = alphaNum;
}

changeCircle(.3);

function addNumbers(num1:Number,num2:Number):Number
{
var resultNum:Number = num1 + num2;
return resultNum;
}

trace(addNumbers(2,3));

Actionscript 3.0 - Alapok

orb_mc.scaleX = orb_mc.scaleY = .5;

numbers_mc.gotoAndStop(5);

trace("2 + 2 = " + (2 + 2));
trace(2 - 2);
trace(3 * 3);
trace(3 / 3);
trace("----------------");
trace(11 / 3);
trace(Math.round(11 / 3));
trace(Math.floor(11 / 3));
trace(Math.ceil(11 / 3));
trace("----------------");
trace(1 + 3 * 2);
trace((1 + 3) * 2);
trace("----------------");
trace("modulus");
trace(10 % 3);
trace(9 % 3);
trace("----------------");
trace(Math.random());
trace(Math.random() * 100);
trace(Math.round(Math.random() * 100));
trace(Math.random() * 50 + 50);
trace(Math.random() * 50 + 30);


var circleAlpha:Number = .5;
var myMC:MovieClip = circle_mc;

myMC.alpha = circleAlpha;

var myString:String = "Craig";
trace(myString);