Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-10-2011, 01:16 PM   #1
pttdt
Registered User
 
Join Date: Feb 2011
Posts: 24
Default How do I SIMPLIFY this CODE?

HOW DO I SIMPLIFY THE CODE IN BETWEEN THE ARROWS? THANKS!

ActionScript Code:
var origX:Number; var origY:Number; origX = choice_1.x; origY = choice_1.y; choice_1.buttonMode = true; choice_1.mouseChildren = false; choice_1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag); function fl_ClickToDrag(event:MouseEvent):void {     choice_1.startDrag(); } stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); function fl_ReleaseToDrop(event:MouseEvent):void {     choice_1.stopDrag(); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>      if(choice_1.hitTestObject(box_1))     {     box_1.text = choice_1.text;     }         if(choice_1.hitTestObject(box_2))     {     box_2.text = choice_1.text;     }         if(choice_1.hitTestObject(box_3))     {     box_3.text = choice_1.text;     }         if(choice_1.hitTestObject(box_4))     {     box_4.text = choice_1.text;     }         if(choice_1.hitTestObject(box_5))     {     box_5.text = choice_1.text;     } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  choice_1.x = origX; choice_1.y = origY; }
pttdt is offline   Reply With Quote
Old 03-10-2011, 01:35 PM   #2
Syllogism
capt. Obvious
 
Syllogism's Avatar
 
Join Date: Aug 2006
Location: South Africa
Posts: 826
Default

much of a muchness
ActionScript Code:
switch ( true )     {         case ( choice_1.hitTestObject(box_1) ):         {             box_1.text = choice_1.text;             break;         }         case ( choice_1.hitTestObject(box_2) ):         {             box_2.text = choice_1.text;             break;         }         case ( choice_1.hitTestObject(box_3) ):         {             box_3.text = choice_1.text;             break;         }         case ( choice_1.hitTestObject(box_4) ):         {             box_4.text = choice_1.text;             break;         }         case ( choice_1.hitTestObject(box_5) ):         {             box_5.text = choice_1.text;             break;         }         default:         {             trace("no hit");             break;         }     }
__________________
S y l l o g i s m, Cptn Obvious

"I think you'll find my argument is flawless [Citation][Citation][Citation]"
Syllogism is offline   Reply With Quote
Old 03-10-2011, 02:16 PM   #3
5TonsOfFlax
.as-hole
 
Join Date: Jan 2010
Posts: 781
Default

ActionScript Code:
var origX:Number = choice_1.x; var origY:Number = choice_1.y; var boxes:Array = [box_1, box_2, box_3, box_4, box_5]; choice_1.buttonMode = true; choice_1.mouseChildren = false; choice_1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag); function fl_ClickToDrag(event:MouseEvent):void {      choice_1.startDrag(); } stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); function fl_ReleaseToDrop(event:MouseEvent):void {   choice_1.stopDrag();   for (var i:int = 0; i < boxes.length; i++){     var box:MovieClip = boxes[i]; //might be some other class, you didn't tell us     if(choice_1.hitTestObject(box)){       box.text = choice_1.text;     }   }   choice_1.x = origX;   choice_1.y = origY; }
5TonsOfFlax is offline   Reply With Quote
Old 03-10-2011, 02:40 PM   #4
pttdt
Registered User
 
Join Date: Feb 2011
Posts: 24
Default Thank you!

5tonsofflax.

This is exactly what I was having trouble creating! Thank you. The boxes are text fields .... I'll see if the movieclip class works.

THANKS SO MUCH AGAIN!!!
pttdt is offline   Reply With Quote
Old 03-10-2011, 02:42 PM   #5
5TonsOfFlax
.as-hole
 
Join Date: Jan 2010
Posts: 781
Default

Change ":MovieClip" to ":TextField".
5TonsOfFlax is offline   Reply With Quote
Old 03-10-2011, 02:47 PM   #6
pttdt
Registered User
 
Join Date: Feb 2011
Posts: 24
Default

OK ... I will change! Thanks again!!!
pttdt is offline   Reply With Quote
Old 03-10-2011, 02:51 PM   #7
pttdt
Registered User
 
Join Date: Feb 2011
Posts: 24
Default

Seems not to work.

Getting this error?

TypeError: Error #1034: Type Coercion failed: cannot convert fl.text::TLFTextField@29ac47c1 to flash.text.TextField.
at draganddropthatsends1_fla::MainTimeline/fl_ReleaseToDrop()


The boxes are TLF text - editable?

ANY IDEAS?
pttdt is offline   Reply With Quote
Old 03-10-2011, 02:52 PM   #8
5TonsOfFlax
.as-hole
 
Join Date: Jan 2010
Posts: 781
Default

Then your text fields are not TextFields, they are TLFTextFields. So change the type to that.
5TonsOfFlax is offline   Reply With Quote
Old 03-10-2011, 02:58 PM   #9
pttdt
Registered User
 
Join Date: Feb 2011
Posts: 24
Default

Now there an no errors BUT it is not working either.

HERE IS THE CODE AS IS:

Code:
var origX:Number = choice_1.x;
var origY:Number = choice_1.y;

var boxes:Array = [box_1, box_2, box_3, box_4, box_5];

choice_1.buttonMode = true;
choice_1.mouseChildren = false; choice_1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag); 

function fl_ClickToDrag(event:MouseEvent):void {
     choice_1.startDrag();
}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); 

function fl_ReleaseToDrop(event:MouseEvent):void {
  choice_1.stopDrag(); 
  for (var i:int = 0; i < boxes.length; i++){
    var box:TLFTextField = boxes[i]; //might be some other class, you didn't tell us
    if(choice_1.hitTestObject(box)){
      box.text = choice_1.text;
    }
  }
  choice_1.x = origX;
  choice_1.y = origY;
}
pttdt is offline   Reply With Quote
Old 03-10-2011, 02:59 PM   #10
pttdt
Registered User
 
Join Date: Feb 2011
Posts: 24
Default

Its not displaying the text when hitTargetObject.
pttdt is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:59 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.