Hey guys,
I’ve created a drag and drop application (well the beginnings of one), it’s 200 lines of code and I’ve only got one element on the canvas.
I know I should be using arrays, and even seperate class files, but my knowledge level isn’t too good when it comes to either of these.
I aim to be replicating whats on the canvas at least a couple of more times and don’t want to be getting 100’s of lines of coding.
The Code:
import caurina.transitions.*;
import fl.controls.CheckBox;
import fl.controls.Button;
import fl.controls.TextInput;
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
var container_mc:MovieClip = new MovieClip();
container_mc.graphics.lineStyle(2,0xcccccc,1);
container_mc.graphics.drawRect(300, 110, 362, 362);
container_mc.graphics.endFill();
addChild(container_mc);
var textHolder:Sprite = new Sprite();
//draw a rectangular header dealy so they can click on something that isn't text
textHolder.graphics.beginFill(0xffffff, 0);
textHolder.graphics.drawRect(70, 110, 150, 40);
textHolder.graphics.endFill();
addChild(textHolder);
var textHolder2=new Sprite();
textHolder2.graphics.lineStyle(2,0xcccccc,1);
textHolder2.graphics.drawRect(70, 110, 190, 40);
textHolder2.graphics.endFill();
addChild(textHolder2);
setChildIndex(textHolder2, 2);
textHolder.addEventListener(MouseEvent.MOUSE_DOWN,startdragging);
textHolder.addEventListener(MouseEvent.MOUSE_UP, stopdragging);
function startdragging(e:MouseEvent):void {
textHolder.startDrag();
}
function stopdragging(e:MouseEvent):void {
textHolder.stopDrag();
if (textHolder.hitTestObject(container_mc)) {
(textHolder,{x:0, y:0,
time:1,
transition:"easeIn"});
} else {
Tweener.addTween(textHolder,{x:0, y:0,
time:1,
transition:"easeIn"});
}
}
// Title Label //
var titleName:TextField = new TextField();
titleName.x =2;
titleName.y = 110;
titleName.width = 80;
titleName.height = 50;
titleName.wordWrap = true;
titleName.multiline = true;
titleName.text = "Company Name:";
addChild(titleName);
var textOne:TextInput = new TextInput();
var textOneFormat:TextFormat = new TextFormat();
var aCp:ColorPicker = new ColorPicker();
addChild(aCp);
aCp.move(230, 80);
addChild(textOne);
textHolder.addChild(textOne);
textOne.setStyle("upSkin", textOneFormat); // Makes the Background transparent
textOne.maxChars = 25;
textOne.text = "";
textOne.restrict = "A-Z .a-z .0-9";
textOne.editable=true;
textOne.setSize(160, 40);
textOne.move(70,110);
function changeHandler(event:ColorPickerEvent):void {
if (TextFormat(textOne.getStyle("textFormat"))) {
textOneFormat = TextFormat(textOne.getStyle("textFormat"));
}
textOneFormat.color = event.target.selectedColor;
textOne.setStyle("textFormat", textOneFormat);
}
aCp.addEventListener(ColorPickerEvent.CHANGE, changeHandler);
///////////////////////////////Put Buttons into an Array? /////////////////////////////////
//Small Title Text
var text1:Button = new Button();
addChild(text1);
text1.move(5, 80);
text1.label="Small";
text1.setSize(50, 20);
text1.addEventListener(MouseEvent.CLICK, smallTxt);
function smallTxt(event:MouseEvent):void {
if (TextFormat(textOne.getStyle("textFormat"))) {
textOneFormat = TextFormat(textOne.getStyle("textFormat"));
}
textOneFormat.size = 9;
textOne.setStyle("textFormat", textOneFormat);
textOne.maxChars = 30;
textOne.setSize(160, 40);
textOne.editable = false;
textHolder.graphics.lineStyle(0,0x000000,0);
}
// Medium Title Text
var text2:Button = new Button();
addChild(text2);
text2.move(60, 80);
text2.label="Medium";
text2.setSize(50, 20);
text2.addEventListener(MouseEvent.CLICK, mediumTxt);
function mediumTxt(event:MouseEvent):void {
if (TextFormat(textOne.getStyle("textFormat"))) {
textOneFormat = TextFormat(textOne.getStyle("textFormat"));
}
var i:int=13;
textOneFormat.size = i;
textOne.maxChars = 26;
textOne.setSize(180, 40);
textOne.setStyle("textFormat", textOneFormat);
textOne.editable = false;
}
// large Title Text
var text3:Button = new Button();
addChild(text3);
text3.move(115, 80);
text3.label="Large";
text3.setSize(50, 20);
text3.addEventListener(MouseEvent.CLICK, largeTxt);
function largeTxt(event:MouseEvent):void {
if (TextFormat(textOne.getStyle("textFormat"))) {
textOneFormat = TextFormat(textOne.getStyle("textFormat"));
}
textOneFormat.size = 24;
textOne.maxChars = 20;
textOne.setSize(205, 40);
textOne.setStyle("textFormat", textOneFormat);
textOne.editable = false;
}
// large Title Text
var text4:Button = new Button();
addChild(text4);
text4.move(175, 80);
text4.label="HUGE";
text4.setSize(50, 20);
text4.addEventListener(MouseEvent.CLICK, hugeTxt);
function hugeTxt(event:MouseEvent):void {
if (TextFormat(textOne.getStyle("textFormat"))) {
textOneFormat = TextFormat(textOne.getStyle("textFormat"));
}
textOne.maxChars = 18;
textOneFormat.size = 32;
textOne.setSize(270, 40);
textOne.setStyle("textFormat", textOneFormat);
textOne.editable = false;
}
var resetTitle:Button = new Button();
addChild(resetTitle);
resetTitle.move(5, 160);
resetTitle.label="Reset";
resetTitle.setSize(42, 20);
resetTitle.addEventListener(MouseEvent.CLICK, resetTitleFunc);
function resetTitleFunc(event:MouseEvent):void {
textOne.maxChars = 25;
textOne.alwaysShowSelection = true;
textOne.text = "";
textOne.restrict = "A-Z .a-z .0-9";
textOne.editable=true;
textOne.setSize(160, 40);
textOne.move(70,30);
textOneFormat.size = 12;
textOneFormat.color = 0x000000;
textHolder.x=0;
textHolder.y=0;
}
This pasted into Flash CS3 will work straight away (Edit: I tell a lie, the caurina class files are needed. I’ve attached the file incase you don’t have it), so if theres anybody out there who could take the time to show me a couple of methods of cutting the code down consideribally I’d be very thankful.
I think the main help would be putting the text size buttons into a class file, and perhaps maybe the same for the input text field.
Thanks for any help. :hugegrin: