Archive for April 5th, 2011

Flash AS3 Laser Lab Code

As promised, here is the code for Laser Lab. In order to run this code successfully, you'll need to have Slider and Color Picker controls in your file library. Everything else is pretty simple, just paste the code into first frame of your FLA file and that's it.

Original document dimensions are 550x400. That is why loop function exist to avoid drawing over control elements.

If you extend this example even more, do let me know.

// laser effect playground
// author http://flanture.blogspot.com
// based on code by www.eyes-squared.co.uk
// march 2011

import flash.display.Sprite;
import flash.filters.GlowFilter;
import flash.events.MouseEvent;
import flash.events.Event;
import fl.controls.ColorPicker;
import fl.controls.Slider;
import fl.events.ColorPickerEvent;
import fl.events.SliderEvent;

// starting values
var baseColor = 0xFFFFFF;
var glowColor = 0xFF0000;
var baseStrength = 3;
var glowStrength = 4;
var glowBlur = 8;

var sprite:Sprite = new Sprite();
addChild(sprite);

function updateFilter() {
var gf:GlowFilter = new GlowFilter(glowColor);
gf.quality = 3;
gf.strength = glowStrength;
gf.blurX = gf.blurY = glowBlur;
var fils = new Array();
fils.push(gf);

sprite.filters = fils;
}
updateFilter();

stage.addEventListener(MouseEvent.MOUSE_DOWN, startFire);
stage.addEventListener(MouseEvent.MOUSE_UP, stopFire);

function startFire(m:MouseEvent) {
sprite.graphics.lineStyle(baseStrength, baseColor);
sprite.graphics.moveTo(mouseX, mouseY);
addEventListener(Event.ENTER_FRAME, loop);
}

function stopFire(m:MouseEvent) {
removeEventListener(Event.ENTER_FRAME, loop);
}

function loop(e:Event) {
// avoid drawing on control elements
if (mouseX < 400) {
sprite.graphics.lineTo(mouseX, mouseY);
}
}

var cp1:ColorPicker = new ColorPicker();
cp1.width = 100;
cp1.height = 25;
cp1.x = 420;
cp1.y = 30;
addChild(cp1);

var cp2:ColorPicker = new ColorPicker();
cp2.width = 100;
cp2.height = 25;
cp2.x = 420;
cp2.y = 200;
addChild(cp2);

var sl1:Slider = new Slider();
sl1.x = 430;
sl1.y = 100;
sl1.liveDragging = true;
sl1.minimum = 1;
sl1.maximum = 10;
sl1.tickInterval = 1;
addChild(sl1);

var sl2:Slider = new Slider();
sl2.x = 430;
sl2.y = 280;
sl2.liveDragging = true;
sl2.minimum = 1;
sl2.maximum = 10;
sl2.tickInterval = 1;
addChild(sl2);

var sl3:Slider = new Slider();
sl3.x = 430;
sl3.y = 350;
sl3.liveDragging = true;
sl3.minimum = 1;
sl3.maximum = 7;
sl3.tickInterval = 1;
addChild(sl3);

cp1.addEventListener(ColorPickerEvent.CHANGE, changeHandler1);
function changeHandler1(event:ColorPickerEvent):void {
sprite.graphics.clear();
baseColor = event.target.selectedColor;
}
cp2.addEventListener(ColorPickerEvent.CHANGE, changeHandler2);
function changeHandler2(event:ColorPickerEvent):void {
glowColor = event.target.selectedColor;
sprite.graphics.clear();
updateFilter();
}
sl1.addEventListener(SliderEvent.CHANGE, changeSlider1);
function changeSlider1(event:SliderEvent):void
{
baseStrength = event.target.value;
sprite.graphics.clear();
}
sl2.addEventListener(SliderEvent.CHANGE, changeSlider2);
function changeSlider2(event:SliderEvent):void
{
glowStrength = event.target.value;
sprite.graphics.clear();
updateFilter();
}
sl3.addEventListener(SliderEvent.CHANGE, changeSlider3);
function changeSlider3(event:SliderEvent):void
{
var temp = 1;
for(var i=0; i<event.target.value; i++){
temp = 2 * temp;
}
glowStrength = temp;
sprite.graphics.clear();
updateFilter();
}


*_*

Flash AS3 Laser Lab Code

As promised, here is the code for Laser Lab. In order to run this code successfully, you'll need to have Slider and Color Picker controls in your file library. Everything else is pretty simple, just paste the code into first frame of your FLA file and that's it.

Original document dimensions are 550x400. That is why loop function exist to avoid drawing over control elements.

If you extend this example even more, do let me know.

// laser effect playground
// author http://flanture.blogspot.com
// based on code by www.eyes-squared.co.uk
// march 2011

import flash.display.Sprite;
import flash.filters.GlowFilter;
import flash.events.MouseEvent;
import flash.events.Event;
import fl.controls.ColorPicker;
import fl.controls.Slider;
import fl.events.ColorPickerEvent;
import fl.events.SliderEvent;

// starting values
var baseColor = 0xFFFFFF;
var glowColor = 0xFF0000;
var baseStrength = 3;
var glowStrength = 4;
var glowBlur = 8;

var sprite:Sprite = new Sprite();
addChild(sprite);

function updateFilter() {
var gf:GlowFilter = new GlowFilter(glowColor);
gf.quality = 3;
gf.strength = glowStrength;
gf.blurX = gf.blurY = glowBlur;
var fils = new Array();
fils.push(gf);

sprite.filters = fils;
}
updateFilter();

stage.addEventListener(MouseEvent.MOUSE_DOWN, startFire);
stage.addEventListener(MouseEvent.MOUSE_UP, stopFire);

function startFire(m:MouseEvent) {
sprite.graphics.lineStyle(baseStrength, baseColor);
sprite.graphics.moveTo(mouseX, mouseY);
addEventListener(Event.ENTER_FRAME, loop);
}

function stopFire(m:MouseEvent) {
removeEventListener(Event.ENTER_FRAME, loop);
}

function loop(e:Event) {
// avoid drawing on control elements
if (mouseX < 400) {
sprite.graphics.lineTo(mouseX, mouseY);
}
}

var cp1:ColorPicker = new ColorPicker();
cp1.width = 100;
cp1.height = 25;
cp1.x = 420;
cp1.y = 30;
addChild(cp1);

var cp2:ColorPicker = new ColorPicker();
cp2.width = 100;
cp2.height = 25;
cp2.x = 420;
cp2.y = 200;
addChild(cp2);

var sl1:Slider = new Slider();
sl1.x = 430;
sl1.y = 100;
sl1.liveDragging = true;
sl1.minimum = 1;
sl1.maximum = 10;
sl1.tickInterval = 1;
addChild(sl1);

var sl2:Slider = new Slider();
sl2.x = 430;
sl2.y = 280;
sl2.liveDragging = true;
sl2.minimum = 1;
sl2.maximum = 10;
sl2.tickInterval = 1;
addChild(sl2);

var sl3:Slider = new Slider();
sl3.x = 430;
sl3.y = 350;
sl3.liveDragging = true;
sl3.minimum = 1;
sl3.maximum = 7;
sl3.tickInterval = 1;
addChild(sl3);

cp1.addEventListener(ColorPickerEvent.CHANGE, changeHandler1);
function changeHandler1(event:ColorPickerEvent):void {
sprite.graphics.clear();
baseColor = event.target.selectedColor;
}
cp2.addEventListener(ColorPickerEvent.CHANGE, changeHandler2);
function changeHandler2(event:ColorPickerEvent):void {
glowColor = event.target.selectedColor;
sprite.graphics.clear();
updateFilter();
}
sl1.addEventListener(SliderEvent.CHANGE, changeSlider1);
function changeSlider1(event:SliderEvent):void
{
baseStrength = event.target.value;
sprite.graphics.clear();
}
sl2.addEventListener(SliderEvent.CHANGE, changeSlider2);
function changeSlider2(event:SliderEvent):void
{
glowStrength = event.target.value;
sprite.graphics.clear();
updateFilter();
}
sl3.addEventListener(SliderEvent.CHANGE, changeSlider3);
function changeSlider3(event:SliderEvent):void
{
var temp = 1;
for(var i=0; i<event.target.value; i++){
temp = 2 * temp;
}
glowStrength = temp;
sprite.graphics.clear();
updateFilter();
}


*_*

SQL Azure Use Case: Shared Data Hub

This is one in a series of posts on when and where to use a distributed architecture design in your organization's computing needs. You can find the main post here: http://blogs.msdn.com/b/buckwoody/archive/2011/01/18/windows-azure-and-sql-azure-use-cases.aspx

Description:

Organizations often need to share all or part of a data set, which is consumed by other systems. These systems can be on-premise or at another location, or even at a different organization.

Many times these systems use a well-defined data interchange system, such as EDI or other standards. In the case of a trusted system, simply using a direct connection into another database is the process used to transfer data. This process might be one-way or bi-directional.

But there are systems that transfer data back and forth in stages using intermediate systems. A typical data flow in this case looks similar to the following:

SADH-1

In this example, the owning system contains data set A. This is set to a staging system or server, where the receiving system collects it. The receiving system contains data set B and works with data set A to create a new data set, C. This new data is consumed by the original system to complete the cycle. A concrete example is an inventory control system. Data set A is the original inventory list, shipped to a manufacturer. The manufacturer consumes the inventory available, orders and components, and returns the ordering bid with any changes to the staging server as data set C. The data is consumed by the originating system and components are noted in the overall flow of data set A.

Note: Normally this is solved with a full EDI implementation, but this process is still a common practice.

There are other examples, but the general concept is one where the need is for two, possibly untrusted systems to share a common source of data.

Implementation:

One possible solution is to segregate the data that is being transferred into an agree-upon set of entities that can be added or edited real-time, where both systems (or many) feed from the same data set instead of shipping the data. This removes latency, improves data quality, and shares the cost of the data. Also, security is increased because there are no shared logins - each firm gets its own.

SADH-2

One consideration with this layout is that the source systems must be altered to use a shared data set. If this is not possible, this is still a possibility as the system can be used as it was before - a data transfer - but the data can be cleansed real-time by both systems. It’s also a more secure and shared-cost system even if used in the original manner.

Resources:

Security is a concern in this arrangement, so it’s best to understand exactly how the security works in SQL Azure: http://msdn.microsoft.com/en-us/library/ff394108.aspx 

Another possibility to solve this pattern is to use Data Sync, in many different arrangements that involve SQL Azure. You can learn more about it here: http://blogs.msdn.com/b/sync/archive/2010/10/07/windows-azure-sync-service-demo-available-for-download.aspx


  • Sponsored Links

  • April 2011
    M T W T F S S
    « Mar   May »
     123
    45678910
    11121314151617
    18192021222324
    252627282930  
  • .

    Copyright © 1996-2010 Answer My Query. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress