React

React
Fundamental of React Js

Thursday, December 13, 2007

ActionSript 2.0 - worddrag

In actionScript, we discus abt the worddrag...

In this, first we have create a EmptyMovieClip for store a words... in the listItem Array
from this Array have to crate one more subArray as Letters..

Steps:

1: create a Flash document with Actionscript2.0
2: press F9 and open the open Actionscript Window
3: write a code ...


Logic:
******
Here wat r the item need.....

1: Movieclip
2: TextField
3: splited Movieclip [ Splited letter are stored here ]
4: Dymanic Box
5: Checking Button


first.. create a Empty Movie Clip

Here the complete code .....

import mx.transitions.Tween;

var listArray:Array = new Array("Verb", "Orange", "Wax", "Eye", "Line");
var Obj:Object = new Object();
Boxes();
btns();
var temp:TextField = new TextField();


this.createEmptyMovieClip('listItem',1);
this.listItem.createTextField('words',1,0,0,100,20);
this.listItem.words.text = listArray[0];
this.createEmptyMovieClip("Letters",0);//xxxxxxxxxxxxxxxxxxxxd
this.createEmptyMovieClip("joinchr",3);
this.listItem.count = 0;

Obj.onMouseMove = function() {

var tx = new Tween(_root.listItem, '_x', null, _root.listItem._x, _root._xmouse, 3, false);
var tx1 = new Tween(_root.listItem, '_y', null, _root.listItem._y, _root._ymouse, 3, false);
};
Mouse.addListener(Obj);
Obj.onMouseDown = function() {
splier();

};

function removeEvent() {
Mouse.removeListener(_root.Obj);
}
var draggedClip:Array = new Array();
function splier() {

_root.listItem.count++;
if (_root.listArray.length>=_root.listItem.count) {

var tempArr:Array = _root.listItem.words.text.split('');
for (var s = 0; s<=tempArr.length-1; s++) {
var depthNo = _root.Letters.getNextHighestDepth();
_root.Letters.createEmptyMovieClip('splitMovie_'+depthNo,depthNo);
_root.Letters['splitMovie_'+depthNo].createEmptyMovieClip('bg',0);
createRect(_root.Letters['splitMovie_'+depthNo].bg);
_root.Letters['splitMovie_'+depthNo].createTextField('fields',1,0,0,100,20);
_root.Letters['splitMovie_'+depthNo].fields.autoSize = true;
_root.Letters['splitMovie_'+depthNo].fields.selectable = false;
_root.Letters['splitMovie_'+depthNo]._x = Math.random()*Stage.width;
_root.Letters['splitMovie_'+depthNo]._y = Math.random()*Stage.height;
_root.Letters['splitMovie_'+depthNo].fields.text = tempArr[s];


//var temp_array:Array = this.split(_root.listArray[0]);
_root.Letters['splitMovie_'+depthNo].onPress = function() {
this.startDrag();
};


_root.Letters['splitMovie_'+depthNo].onRelease = function() {
this.stopDrag();
//trace(_root.box+' Square box ');
if (this.hitTest(_root.box)) {

this._visible = false;
draggedClip.push(this);
if (_root.checker.text == 'check Here') {
_root.checker.text = '';
}
_root.checker.text += this.fields.text;


}

};


}
_root.listItem.words.text = _root.listArray[_root.listItem.count];

var checkerCount = 0;
_root.btn.onPress = function() {


if (_root.checker.text == _root.listArray[checkerCount].toString()) {

_root.subtxt.text = _root.listArray[checkerCount]+" is correct";
checkerCount++;
} else {
_root.subtxt.text = _root.checker.text+" is Incorrect";
_root.checker.text = '';
for (var j = 0; j<=draggedClip.length-1; j++) {
trace(draggedClip[j]);
draggedClip[j]._visible = true;
draggedClip[j]._x = Math.random()*Stage.width;
draggedClip[j]._y = Math.random()*Stage.height;
}
}
};
if (_root.listItem.count == 5) {
_root.box._visible = true;
_root.btn._visible = true;
_root.txt._visible = true;
_root.removeEvent();
//_root.listItem.words.removeMovieClip()
_root.subtxt._visible = true;
_root.checker._visible = true;
}
}
if (_root.listArray[_root.listItem.count] == undefined) {
_root.listItem.words.text = '';
return;
}
}



function Boxes() {
this.createTextField('txt',-2,330,15,120,20);
this.txt.text = 'Enter ur Text Here:';
this.createTextField('subtxt',-4,445,34,120,20);
this.createTextField('checker',-5,440,15,90,20);
this.subtxt.text = 'validate';
this.checker.text = 'check Here';
this.subtxt.autoSize = true;
this.txt.autoSize = true;
this.createEmptyMovieClip("box",-1);
box.lineStyle(0,0x9999999,50);
box.beginFill(0xE8E8E8,50);
box.moveTo(100,100);
box.lineTo(200,100);
box.lineTo(200,120);
box.lineTo(100,120);
box.lineTo(100,100);
box._x = 330;
box._y = -87;
box.endFill();

}
function createRect(_mov) {
_mov.lineStyle(0,0xFF0000,1);
_mov.beginFill(0xFF0000,1);
_mov.moveTo(0,0);
_mov.lineTo(20,0);
_mov.lineTo(20,20);
_mov.lineTo(0,20);
}
function btns() {
this.createEmptyMovieClip("btn",-9);
btn.lineStyle(1,0x000000,50);
btn.beginFill(0xFFE8E8,50);
btn.moveTo(-6,-6);
btn.lineTo(6,-6);
btn.lineTo(6,6);
btn.lineTo(-6,6);
btn.endFill();
btn._x = 540;
btn._y = 62;
}

this.box._visible = false;
_root.btn._visible = false;
_root.txt._visible = false;
_root.subtxt._visible = false;
_root.checker._visible = false;

trace(_root.btn+' : btn ');


0 comments: