Referencing movieclip within another movie in Flash AS3
I was creating a drap and drop simple game, dragging and dropping an item from within a movie clip. All was working fine, but then I had to add more items so I created a ScrollPane and referenced the movie clip through that, now I need to rework how I pull reference that movieclip again.
The movieclip is exported so the scrollpane can bring it in...
before:
package {
import flash.display.*;
import flash.geom.Point;
import flash.events.*;
public class shopping extends Sprite {
public function shopping() {
shoppinglist.Ketch.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
shoppinglist.Ketch.addEventListener(MouseEvent.MOUSE_UP, dropIt);
Any help welcome... And hope this makes sense...
**Edit
Still really struggling on this, here is my code:
package {
import flash.display.*;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.events.KeyboardEvent;
import flash.events.*;
public class shopping exten开发者_开发百科ds MovieClip {
public function shopping() {
var counter:Number = 0;
var startX:Number;
var startY:Number;
var budget:Number = 25
scoreText.text = 'You have £'+budget+' for your weekly shop';
priceText.text = '£'+budget;
ScrollList.Ketch.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
ScrollList.Ketch.addEventListener(MouseEvent.MOUSE_UP, dropIt);
public function pickUp(e:MouseEvent):void {
e.target.startDrag(true);
reply_txt.text = "";
e.target.parent.addChild(e.target);
startX = e.target.x;
startY = e.target.y;
}
public function dropIt(e:MouseEvent):void {
e.target.stopDrag();
if (e.target.dropTarget != null && e.target.dropTarget.parent == trolley){
//reply_txt.text = "Good Job!";
e.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
e.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
e.target.buttonMode = false;
//e.target.x = trolley.x;
//e.target.y = trolley.y;
if(e.currentTarget.name == 'Ketch'){
budget -= 1.25;
scoreText.text = 'You have £'+budget+' for your weekly shop';
}
counter++;
} else {
//reply_txt.text = "Try Again!";
e.target.x = startX;
e.target.y = startY;
}
if(counter == 4){
reply_txt.text = "Congrats, you're finished!";
}
}
ScrollList.Ketch.buttonMode = true;
}
}
}
Well here is the little code that might help
var Gotparent;
var myobj ;
public function pickUp(e:Event):void {
myobj = (evt.currentTarget)
Gotparent = myobj.parent;
addChild(myobj);
myobj.startDrag(true);
}
public function dropIt(e:Event):void { myobj.stop(); Gotparent.addChild(myobj); }
精彩评论