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

How to center game on fla.file stage?

Community Beginner ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

Hi. I have a problem to center the import game swf in fla. file. As you can see below the grey box not at the center of the stage which is at transparent box (464px X 610px)

this is the coding I use in game (grey box), this game is in class:

package

{

import flash.display.Sprite;

import flash.events.MouseEvent;

import flash.events.TimerEvent;

import flash.utils.Timer;

public class color_match extends Sprite

{

private var first_tile:colors;

private var second_tile:colors;

private var pause_timer:Timer;

var colordeck:Array = new Array(1,1,2,2,3,3,4,4,5,5,6,6);

public function color_match()

{

for (x=1; x<=3; x++)

{

for (y=1; y<=4; y++)

{

var random_card = Math.floor(Math.random() * colordeck.length);

var tile:colors = new colors();

tile.col = colordeck[random_card];

colordeck.splice(random_card,1);

tile.gotoAndStop(7);

tile.x = (x - 1) * 100;

tile.y = (y - 1) * 100;

tile.addEventListener(MouseEvent.CLICK,tile_clicked);

addChild(tile);

}

}

}

public function tile_clicked(event:MouseEvent)

{

var clicked:colors = (event.currentTarget as colors);

if (first_tile == null)

{

first_tile = clicked;

first_tile.gotoAndStop(clicked.col);

}

else if (second_tile == null && first_tile != clicked)

{

second_tile = clicked;

second_tile.gotoAndStop(clicked.col);

if (first_tile.col == second_tile.col)

{

pause_timer = new Timer(1000,1);

pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);

pause_timer.start();

}

else

{

pause_timer = new Timer(1000,1);

pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);

pause_timer.start();

}

}

}

public function reset_tiles(event:TimerEvent)

{

first_tile.gotoAndStop(7);

second_tile.gotoAndStop(7);

first_tile = null;

second_tile = null;

pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);

}

public function remove_tiles(event:TimerEvent)

{

removeChild(first_tile);

removeChild(second_tile);

first_tile = null;

second_tile = null;

pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);

}

}

}

Anyone can help me to solve this problem?

Thank you in advance.

TOPICS
ActionScript

Views

521

Translate

Translate

Report

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
Community Expert ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

add your tiles to a parent and then center the parent:

private var p:MovieClip=new MovieClip();

public function color_match()

{

for (x=1; x<=3; x++)

{

for (y=1; y<=4; y++)

{

var random_card = Math.floor(Math.random() * colordeck.length);

var tile:colors = new colors();

tile.col = colordeck[random_card];

colordeck.splice(random_card,1);

tile.gotoAndStop(7);

tile.x = (x - 1) * 100;

tile.y = (y - 1) * 100;

tile.addEventListener(MouseEvent.CLICK,tile_clicked);

p.addChild(tile);

}

}

p.x=(stage.stageWidth-p.width)/2;

p.y=(stage.stageHeight-p.height)/2;

addChild(p);

}

[moved from Adobe Creative Cloud to ActionScript 3]

Votes

Translate

Translate

Report

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
Community Beginner ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

not working

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

is there an error message?

if not what do trace() statements show?

Votes

Translate

Translate

Report

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
Community Beginner ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

when I test the scene in fla.file its show like above..

but when I test movie in class its show below:

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

look at those error messages!

(you need to import flash.display.MovieClip)

Votes

Translate

Translate

Report

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
Community Beginner ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

sorry.. where to import that code?

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

at the top of your class. eg, line 1 insert:

import flash.display.MovieClip;

Votes

Translate

Translate

Report

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
Community Beginner ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

already did what you said sir but this happen when i play in class not the fla.file (main fla)

below is the main platform which is the fla file:

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

what's the problem?

Votes

Translate

Translate

Report

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
Community Beginner ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

the load class game not at the center of the fla.file (the main product) on the transparent box

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

no actionscript will ever change/affect any fla.

actionscript will change/affect the publish file(s).  in your case, you're publishing a swf (where the grid appears centered to me) and you expect your swf to show the effects of your actionscript.

if you want to change the fla you would use jsfl or (more commonly) edit your fla in the ide.

Votes

Translate

Translate

Report

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
Community Beginner ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

ok sir..

one more question: after i import flash.display.MovieClip;

and I test it become below? the pics stuck and I cant click other frames

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

LATEST

you have an error somewhere in your code where you use removeChild().

if that error was not present prior to using the code i suggested, then you probably have something like the following somewhere in your code:

removeChild(tile) or this.removeChild(tile)

and that should probably be changed to:

p.removeChild(tile); or this.p.removeChild(tile);

or just:

removeChild(p);

Votes

Translate

Translate

Report

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