Tag Archive for Objects

objects into array

function objectsIntoArray($arrObjData, $arrSkipIndices = array())
{
    $arrData = array();
   
    // if input is object, convert into array
    if (is_object($arrObjData)) {
        $arrObjData = get_object_vars($arrObjData);
    }
   
    if (is_array($arrObjData)) {
        foreach ($arrObjData as $index => $value) {
            if (is_object($value) || is_array($value)) {
                $value = objectsIntoArray($value, $arrSkipIndices); // recursive call
            }
            if (in_array($index, $arrSkipIndices)) {
                continue;
            }
            $arrData[$index] = $value;
        }
    }
    return $arrData;
}

source

Meine Kleine Strasse

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import berdux.MeineKleineStrasseBasis;
import shape.ShapeBase;
import shape.Haus;
import shape.Baum;
import shape.HinterGr;


/**
 * GC - T1
 * 
 * Testat 4: Meine kleine Strasse
 * 
 * Stellt die Methoden zum Zeichnen der Strasse zur Verfügung.
 * Erweitert die Klasse MeineKleineStrasseBasis. Bei Mausklick
 * wird überprüft ob die geklickte Position ein Haus ist.
 * 
 * Veranlasst das erneute Zeichen über paint nach einem Mausklick.
 *  
 * @author Markus Tacker <<a href="mailto:m@tacker.org">m@tacker.org</a>>
 * @author Philipp Siegmund <<a href="mailto:philipp.siegmund@gmail.com">philipp.siegmund@gmail.com</a>>
 * @version $Id: MeineKleineStrasse.java 114 2010-01-22 10:36:07Z m $
 */

public class MeineKleineStrasse extends MeineKleineStrasseBasis 
{
	private ShapeBase[] shapes;
	
	/** 
	 * Übergabe der shape Argumente in ein Array zur Weiterverarbeitung von paint
	 *  
	 */
	public void start()
	{
		this.shapes = new ShapeBase [11];
		this.shapes[1] = new Baum(0, 200, 80, 180);
		this.shapes[0] = new Haus(40, 140, 190, 240, new Color(202, 225, 255));
		this.shapes[2] = new Haus(200, 170, 150, 210, new Color(255, 215, 0));
		this.shapes[3] = new Baum(320, 280, 100, 100);
		this.shapes[4] = new Baum(350, 180, 150, 200);
		this.shapes[5] = new Baum(400, 260, 100, 120);
		this.shapes[6] = new Haus(480, 0, 185, 380, new Color(205, 198, 115));
		this.shapes[7] = new Haus(640, 90, 150, 290, new Color(0, 205, 0));
		this.shapes[8] = new Haus(785, 10, 115, 370, new Color(143, 188, 143));
		this.shapes[9] = new Baum(875, 180, 150, 200);
		this.shapes[10] = new Baum(860, 260, 100, 120);
		
	}

	/** 
	 * Aufloesung der x, y-Position, an der Maus-Button betaetigt wurde.
	 * 
	 * Umsetzung der Methode
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
	 * 
	 * @param e Maus-Ereignis, das ausgeloest wurde 
	 */
	public void mouseClicked(MouseEvent e){
		int x, y;
		
		x = e.getX(); // x-Koordinate, an der Mausereignis stattgefunden hat
		y = e.getY(); // y-Koordinate, an der Mausereignis stattgefunden hat
		
		for(int i = 0; i < this.shapes.length; i++) {
			if (this.shapes[i] instanceof Haus) {
				Haus currentHaus = (Haus)this.shapes[i];
				currentHaus.lichtAendern(x, y);
			}
		}
		
		// nach jeder Veraenderung soll der Graphik-Kontext neu gezeichnet werden
		repaint();
	}
	
	/** 
	 * Erhält alle Argument, die nötig sind um alle Shapes zu zeichen. 
	 * Zeichnet alle Shapes aus dem Array ShapeBase auf die Zeichenfläche
	 * 
	 * @param g Grafik-Objekt
	 */
	public void paint(Graphics g)
	{
		g.clearRect(0, 0, g.getClipBounds().width, g.getClipBounds().height);
		HinterGr.draw(g);
		for(int i = 0; i < this.shapes.length; i++) {
			this.shapes[i].paint(g);	
		}			
	}
	

	/** 
	 * Zeichnet erneut Shapes auf die Zeichenfläche
	 * 
	 * @param g Grafik-Objekt
	 *  
	 */
	public void update(Graphics g){
		paint(g);
		
	}
}

source

Using sprites as an Array to hold Objects

for(var i:int = 0; i<someContainerSprite.numChildren; i++){
sTemp:Sprite = someContaier.getChildAt(i);
}

source

Deep Copy an Array or Object

function deepCopy(obj) {
if (Object.prototype.toString.call(obj) === '[object Array]') {
var out = [], i = 0, len = obj.length;
for ( ; i < len; i++ ) {
out[i] = arguments.callee(obj[i]);
}
return out;
}
if (typeof obj === 'object') {
var out = {}, i;
for ( i in obj ) {
out[i] = arguments.callee(obj[i]);
}
return out;
}
return obj;
}

source

Flipping objects with a Matrix

function flipHorizontal(dsp:DisplayObject):void {
var matrix:Matrix = dsp.transform.matrix;
matrix.a = -1;
matrix.tx = dsp.width + dsp.x;
dsp.transform.matrix = matrix;
}

function flipVertical(dsp:DisplayObject):void {
var matrix:Matrix = dsp.transform.matrix;
matrix.d = -1;
matrix.ty = dsp.height + dsp.y;
dsp.transform.matrix = matrix;
}

source

Persistingly Binding Wrapper Function

function createBoundedWrapper(object, method) {
return function() {
return method.apply(object, arguments);
};
}

source

Get All Objects in a Folder

#The objectValues() method returns a list of objects contained in a folder.
# If the context happens not to be a folder, nothing is returned

objs = context.objectValues()

source

Publish an object via PDO (aka Cocoa Distributed Objects)

NSConnection *theConnection =
[NSConnection defaultConnection];
[theConnection
setRootObject:serverObject];
[theConnection
registerName:@"ObjectName"];

source

drawing in a new object

// import necessary classes
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;

// instantiate object
yaddayadda = new objectname();

// importinkt! - you need to attach it to the drawing layer
// otherwise its content willnae show up
this.addChild(yaddayadda);

source

Data Slider v1.0

/**************************************
* Jonas Raoni Soares Silva
* <a href="http://www.joninhas.ath.cx" >http://www.joninhas.ath.cx</a>
**************************************/

(DataSlider = function(onchange, interval, args){ //v1.0
var i = DataSlider.instances = DataSlider.instances || [], o = this;
(o.c = 0, o.timer = null, o.interval = (o.onchange = (o.data = [].slice.call(
arguments, 0)).shift(), o.data.shift()), i[o.index = i.length] = o);
}).prototype = {
stop: function(){
clearTimeout(this.timer);
},
play: function(){
this.timer = setInterval("DataSlider.instances[" + this.index + "].next()", this.interval);
},
show: function(x){
this.c = x; this.onchange(this.data[ x ]);
},
previous: function(){
this.show(this.c > 0 ? --this.c : this.data.length-1);
},
next: function(){
this.show((this.c + 1) % this.data.length);
}
};

source