Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

loaded swf not work correctly

New Here ,
Jun 15, 2015 Jun 15, 2015

i've created a maze game ( the idea is drawing a line to connect between 2 movie clips within the maze wall )

this is the code of the game :

stop();

  import flash.display.Sprite;

  import flash.events.MouseEvent;

  //Are we drawing or not?

  var drawing:Boolean;

  var isStart = false;

  

  var drawingSprite:Sprite = new Sprite();

addChild(drawingSprite);

  drawingSprite.graphics.lineStyle(3,0x000000);

  drawing = false;//to start with

  stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);

  stage.addEventListener(MouseEvent.MOUSE_MOVE, draw);

  stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);

  function startDrawing(event:MouseEvent):void{

  drawingSprite.graphics.moveTo( mouseX, mouseY);

  drawing = true;

  }

  function draw(event:MouseEvent){

  if(drawing){

  drawingSprite.graphics.lineTo(mouseX,mouseY);

  }

  }

  function stopDrawing(event:MouseEvent){

  drawing = false;

  }

//Adds an event listener onto the stage with the mouse move event.

stage.addEventListener(MouseEvent.MOUSE_MOVE, detectHits);

function detectHits(event:MouseEvent) {

//If the mouse touches the edges of the maze, return back to the

//first scene, and remove the mouse move event listener from the

//stage.

if (wall_mc.hitTestPoint(mouseX,mouseY,true)) {

  if (isStart == true) {

  drawingSprite.graphics.clear();

gotoAndPlay(3);

  isStart = false ;

stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);

  }

}

//If the mouse touches the brush point, go to the third scene and

//remove the mouse move event listener from the stage.

else if (hit_mc.hitTestPoint(mouseX,mouseY,true)) {

  if (isStart == true) {

  drawingSprite.graphics.clear();

  gotoAndPlay(2);

  isStart = false ;

stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);

  }

}

}

mc_start.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void

{

isStart = true ;

}

works fine and published as swf

when i try to load this game to another fla

its never work correctly yes the swf loaded and the game start fine

but when i start to draw the line into the maze and without touch any wall  it moves to the ( u lost ) frame

TOPICS
ActionScript
402
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 15, 2015 Jun 15, 2015

The error still lies in using mouseX and mouseY.  If you had not offset the placement of the loaded swf then you wouldn't need to compensate for it because mouseX/Y for one would be the same value as mouseX/Y for the loaded one.

Either you need to deal with global to local conversion or you need to build in the compensation.  Since it is a fixed value (35) you could adjust the code in the loaded swf to use a compensator variable that is set to zero by default in the swf (for when it plays on its

...
Translate
LEGEND ,
Jun 15, 2015 Jun 15, 2015

If the function that detects hits is the one that goes to whatever the u lost frame is, then I suspect that the mouseX and mouseY values are what it likely causing the error.  You likely need to keep them relative to the swf though I suspect they become relative to the one that loads it.  Use the trace function to see what the numbers are like when it is run solo versus loaded.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 15, 2015 Jun 15, 2015

i think that u r right

but

is there a code to make mouseX and mouseY related only to swf ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2015 Jun 15, 2015

You could try using "this." to preclude the targeting and see if that helps though it might not... as in this.mouseX, etc...

You might have to use globalToLocal coding (try https://www.google.com/search?q=as3+global+to+local+coordinates)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 15, 2015 Jun 15, 2015

i fount the error

its in the load swf code

i use a loader and set the x and y property

fl_Loader_16.x = 35;
fl_Loader_16.y = 35;

without this it works fine

but i need to set the place for the loaded swf ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2015 Jun 15, 2015
LATEST

The error still lies in using mouseX and mouseY.  If you had not offset the placement of the loaded swf then you wouldn't need to compensate for it because mouseX/Y for one would be the same value as mouseX/Y for the loaded one.

Either you need to deal with global to local conversion or you need to build in the compensation.  Since it is a fixed value (35) you could adjust the code in the loaded swf to use a compensator variable that is set to zero by default in the swf (for when it plays on its own).  When you load it into another file then you will have to wait until after is has fully loaded and have the loading file reassign a different value to that compensator... in this case it would be -35

One other way to solve this would be to shift all of the content in the swf 35 pixels to the right and down (within itself).  Then you would not need to adjust the placement of it and the mouseX/Y values would be the same for both the main movie and the loaded one.  The only problem then might be in using the swf by itself.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines