Copy link to clipboard
Copied
Hi,
I have a situation where I am modifying a working FLA file to work in just one Scene of a project I am working on.
The FLA file is linked to two external .as files.
I would like to take that code and call it from Fram 1 of the Scene as it will only but used for that scene and I do not want it affecting the other scenes.
I removed the package wrapper and changed any private function/public function just to function etc.
part of the issue is calling on Movieclips in the library.
I am trying to use drag and drop to drag Movieclips to Target transparent Movieclips.
The .as files uses:
import THE;
In a function I use:
the = new THE();
addChild(the);
the._targetPiece = tTHE_mc;
the.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
the.x = 103.50;
the.y = 72.60;
I get an error for the "import THE;" as error 1046: Type was not found orwas not a compile-time constant: THE
I get the error for the function reference as: error 1180 call to a possibly undefined method THE
Any advise would be grateful.
Copy link to clipboard
Copied
where's the THE class?
Copy link to clipboard
Copied
Hi,
thanks for the response. I have tried several variations to fix the issue.
The "THE" class is the class assigned to the MovieClip "THE" in the library where it was exported for Actionscript 3 using linkage.
This was the working situation when the code was being called from the external .as files.
By you asking this question suddenly made me realise that instead of the class linking to the external .as file, which I had stupidly left as linkage is still required when calling movieclips from the library, I simply changed the properties to the base class of: flash.display.MovieClip
The errors have all gone, the SWF file publishes, but none of the movieclips are displayed on the screen.
If I comment out the "import THE:" or leave it in, the same thing happens. No errors but the movieclips do not populate the screen.
I have 5 movieclips in the Library. All are words.
The idea is that the five words display mixed up.
The user then drags the words into the correct order, once in the correct order the user goes to another frame displaying a "Well done" message and a button to go to the next scene to continue. This works fine when using the external .as files.
I can provide the full script text if required?
Copy link to clipboard
Copied
you have a THE() class movieclip in your library, correct? when you click that library movieclip, you see something in the library panel's preview window, correct?
if yes and yes, with
the = new THE();
addChild(the);
the._targetPiece = tTHE_mc;
the.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
the.x = 103.50;
the.y = 72.60;
your THE instance will be on-stage and visible unless something is occuring elsewhere to cause it to not be visible.
Copy link to clipboard
Copied
Hi,
Yes,
The movieclip THE is in the Library.
I click on it and it displays in the preview window.
It has the Class name of THE and the base class of: flash.display.MovieClip
This why I am flustered by this, it should work.
Here is the complete code: There are actually five Movieclips, each one is a word:
==========================================================
stop();
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import THE;
import BOY;
import KICKED;
import HIS;
import BALL;
var _targetPiece:*;
var _origX:Number;
var _origY:Number;
var _totalPieces:Number;
var _currentPieces:Number;
var the:THE;
var boy:BOY;
var kicked:KICKED;
var his:HIS;
var ball:BALL;
function DragGame()
{
_totalPieces = 5;
_currentPieces = 0;
createPieces();
}
function createPieces():void
{
the = new THE();
addChild(the);
the._targetPiece = tTHE_mc;
the.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
the.x = 103.50;
the.y = 72.60;
boy = new BOY();
addChild(boy);
boy._targetPiece = tBOY_mc;
boy.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
boy.x = 165.25;
boy.y = 72.30;
kicked = new KICKED();
addChild(kicked);
kicked._targetPiece = tKICKED_mc;
kicked.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
kicked.x = 247.05;
kicked.y = 72.30;
his = new HIS();
addChild(his);
his._targetPiece = tHIS_mc;
his.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
his.x = 323.85;
his.y = 72.30;
ball = new BALL();
addChild(ball);
ball._targetPiece = tBALL_mc;
ball.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
ball.x = 379.60;
ball.y = 72.75;
}
function DragDrop()
{
_origX = this.x;
_origY = this.y;
this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
this.addEventListener(MouseEvent.MOUSE_UP, dropMovie);
this.buttonMode = true;
}
function dragMovie(event:MouseEvent):void
{
this.startDrag();
this.filters = [new DropShadowFilter()];
this.parent.addChild(this);
}
function dropMovie(event:MouseEvent):void
{
this.stopDrag();
this.filters = [];
}
function disable():void
{
this.buttonMode = false;
this.removeEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
this.removeEventListener(MouseEvent.MOUSE_UP, dropMovie);
}
function checkTarget(event:MouseEvent):void
{
if(event.currentTarget.hitTestObject(event.currentTarget._targetPiece))
{
event.currentTarget.x = event.currentTarget._targetPiece.x;
event.currentTarget.y = event.currentTarget._targetPiece.y;
event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
event.currentTarget.disable();
_currentPieces ++;
if(_currentPieces >= _totalPieces)
{
gotoAndStop (5);
}
}
else
{
event.currentTarget.x = event.currentTarget._origX;
event.currentTarget.y = event.currentTarget._origY;
//gotoAndStop (7);
}
}
Copy link to clipboard
Copied
i'm not sure what you mean by "..the complete code" but that code you just showed should be irrelevant (from your description) because none of it executes except the import and variable declarations.
because you're having problems, i suspect you're not doing exactly as you stated.
Copy link to clipboard
Copied
Hi,
I'm not sureI understand what you mean?
The code I have provided is all of the code in Frame 1 on its own script layer.
The code is identical to the code in the .as file, which does work. Other than that, I don't know what else to provide.
The only other chnages are in the MovieClip Class settings:
Thats it, its all I have.......
Copy link to clipboard
Copied
you're #4 post does not include this code:
the = new THE();
addChild(the);
the._targetPiece = tTHE_mc;
the.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
the.x = 103.50;
the.y = 72.60;
that's the only code needed. the rest of the code you showed does nothing because none of those methods are called. however, if you have a THE class file in your current scope, code there will execute.
Copy link to clipboard
Copied
em,
maybe I misanderstand you, but the 4th post does show that code?
The rest of the code checks to see if the movieClip that is dragged hits the required target MovieClip.
If it does, it locks into place and you no longer can drag it.
If you do not drop it into the correct target place the movieClip snaps back into the original place.
Copy link to clipboard
Copied
you're correct. that code is there.
i should have said your #4 post shows that code is not executing. you need to call the function that contains that code.
Copy link to clipboard
Copied
Hi,
It is being called in the function:
function DragGame()
{
_totalPieces = 5;
_currentPieces = 0;
createPieces();
}
I'll take another look at the code, there must be something else. When I publish there are not errors, which is the strange thing.
I'll keep chipping away to see what is the missing link.
Copy link to clipboard
Copied
what makes you think DragGame() is being called?