Checkbox add elements to array - actionscript-3

I'm seem having problem with inserting an element to an array.
What I'm trying to do is if the CheckBox is tick it would insert an element in the array and if the checkbox is unticked remove the element from the array
package src
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
var positionY:Number = 80;
var positionX:Number = 0;
var motion:MovieClip;
var fCombo:Array = new Array();
var n:Number;
var combo:Array = new Array();
public function Main()
{
Basic.selected = true;
Basic.addEventListener(Event.CHANGE, change);
generate.addEventListener(MouseEvent.MOUSE_UP, loop);
generate.addEventListener(MouseEvent.MOUSE_DOWN, remove);
n = Number(inputText.text);
var combo:Array = [];
}
function loop(me:MouseEvent):void
{
var combo:Array = [Punch, Kick, Knee, Elbow];
n = Number(inputText.text);
for(var i:Number = 0;i < n;i++ )
{
motion = new combo[randomNumber(combo.length)]();
fCombo.push(motion);
motion.y = positionY;
motion.x = positionX;
positionX += 100;
addChild(motion);
if (i == 4 || i == 9 || i == 14 || i == 19)
{
positionY += 40;
positionX = 0;
}
}
}
function remove(me:MouseEvent):void
{
var k:Number = n
while(fCombo.length)
{
removeChild(fCombo.pop());
}
positionY = 80;
positionX = 0;
}
function randomNumber(max:Number):Number
{
return(Math.floor(Math.random() * max ));
}
function change(e:Event):void
{
if (Basic == true)
{
combo.push(UpperCut); //this movieclip won't insert inside the array
}
}
}
}

I guess Basic is a checkBox, So
if (Basic == true)
{
combo.push(UpperCut); //this movieclip won't insert inside the array
}
Should be
if (Basic.selected == true)
{
combo.push(UpperCut); //this movieclip won't insert inside the array
}

Related

how to use .visible properties in as3?

I just want to make some objects visible="false". But I can't. I can make some objects invisible, however it is not working for the objects in the array. Here is my codes. When score=3, objects should be invisible. It is a catching game. I use Adobe Flash CC.
Can u help me?
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
import flash.utils.getDefinitionByName;
public class CatchingGame extends MovieClip {
var catcher:Catcher;
var nextObject:Timer;
var objects:Array = new Array();
var score:int = 0;
const speed:Number = 7.0;
public function CatchingGame() {
catcher = new Catcher();
catcher.y = 350;
addChild(catcher);
setNextObject();
addEventListener(Event.ENTER_FRAME, moveObjects);
}
public function setNextObject() {
nextObject = new Timer(1000+Math.random()*1000,1);
nextObject.addEventListener(TimerEvent.TIMER_COMPLETE,newObject);
nextObject.start();
}
public function newObject(e:Event) {
var goodObjects:Array = ["Circle1","Circle1","Circle1"];
var badObjects:Array = ["Square1","Square2", "Circle2"];
if (Math.random() < .5) {
var r:int = Math.floor(Math.random()*goodObjects.length);
var classRef:Class = getDefinitionByName(goodObjects[r]) as Class;
var newObject:MovieClip = new classRef();
newObject.typestr = "good";
} else {
r = Math.floor(Math.random()*badObjects.length);
classRef = getDefinitionByName(badObjects[r]) as Class;
newObject = new classRef();
newObject.typestr = "bad";
}
newObject.x = Math.random()*500;
addChild(newObject);
objects.push(newObject);
setNextObject();
}
public function moveObjects(e:Event) {
for(var i:int=objects.length-1;i>=0;i--) {
objects[i].y += speed;
if (objects[i].y > 400) {
removeChild(objects[i]);
objects.splice(i,1);
}
if (objects[i].hitTestObject(catcher)) {
if (objects[i].typestr == "good") {
score += 1;
}
if (score < 0) score = 0;
scoreDisplay.text = "Score:" +score;
removeChild(objects[i]);
objects.splice(i,1);
}
}
for(var k:int=objects.length-1;k>=0;k--){
if (score == 3){finished.text="Well Done!";
catcher.visible=false;
scoreDisplay.visible=false;
objects[k].visible=false; }
}
catcher.x = mouseX;
}
}
}
Bildiğim kadarıyla şu sekilde olması lazım
this[diziismi(i)].visible = false;
bu şekilde daha önceki projelerimin birinde kullandığımı ve çalıştığını hatırlıyorum

ActionScript 3 - Error #1010: A term is undefined and has no properties

When testing my project, I got this error :
TypeError: Error #1010: A term is undefined and has no properties. firegame.as:115]
at firegame/checkhitammo()[..\Desktop\Flash\firegame.as:115
at firegame/mainloop()[..Desktop\Flash\firegame.as:77
I don't understand why and if I change the if statement to something simple it's all work fine.
This is my code :
package {
import flash.display.*;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
public class firegame extends MovieClip {
var tiger:Tiger = new Tiger();
var enemys:Array = new Array();
var scorea:Number = 0;
var ammoleft:Number = 0;
var ammo:Array = new Array();
var setint:Timer = new Timer(110);
var setenemy:Timer = new Timer(980);
var newenemy:Number;
var hitcheck:Array = new Array();
var totallength:Number;
public function firegame() {
startgame();
}
public function startgame() {
addplayer();
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveplayer);
stage.addEventListener(MouseEvent.MOUSE_DOWN, shotfire);
stage.addEventListener(MouseEvent.MOUSE_UP, shotfirestop);
setint.addEventListener(TimerEvent.TIMER, shotfirestart);
setenemy.addEventListener(TimerEvent.TIMER, addenemy);
stage.addEventListener(Event.ENTER_FRAME, mainloop);
setenemy.start();
}
public function addplayer():void {
tiger.y = 200;
tiger.x = 507;
addChild(tiger);
}
public function moveplayer(e:MouseEvent):void {
tiger.y = mouseY;
tiger.x = 507;
}
public function shotfire(e:MouseEvent):void {
setint.start();
}
public function shotfirestop(e:MouseEvent):void {
setint.stop();
}
public function shotfirestart(e:TimerEvent):void {
var fire:Fire = new Fire();
fire.x = 460;
fire.y = mouseY;
addChild(fire);
ammoleft -= 1;
ammo.push(fire);
}
public function addenemy(e:TimerEvent):void {
var enemy:Enemy = new Enemy();
enemy.x = 0;
enemy.y = Math.floor(Math.random() * (370 - 30) + 30);
addChild(enemy);
enemys.push(enemy);
}
public function mainloop(e:Event):void {
setscoreandammo();
moveammo();
moveenemy();
checkhitammo();
}
public function moveammo():void {
for (var i:int = 0; i < ammo.length; i++) {
ammo[i].x -= 15;
if (ammo[i].x < -30) {
removeChild(ammo[i]);
ammo[i] = null;
ammo.splice(i, 1);
}
}
}
public function moveenemy():void {
for (var b:int = 0; b < enemys.length; b++) {
enemys[b].x += 5;
if (enemys[b].x > 590) {
removeChild(enemys[b]);
enemys[b] = null;
enemys.splice(b, 1);
}
}
}
public function setscoreandammo():void {
score.text = String(scorea);
leftammo.text = String(ammoleft);
}
public function checkhitammo():void {
for (var i:int = ammo.length; i >= 0; i--) {
for (var b:int = enemys.length; b >= 0; b--) {
if (ammo[i].hitTestObject(enemys[b])) { // <--- this is the line where the error is fired
removeChild(ammo[i]);
ammo[i] = null;
ammo.splice(i, 1);
removeChild(enemys[b]);
enemys[b] = null;
enemys.splice(b, 1);
scorea += 50;
break;
}
}
}
}
}
}
Your specific problem is right here...
public function checkhitammo():void {
for (var i:int = ammo.length; i >= 0; i--) {
for (var b:int = enemys.length; b >= 0; b--) {
...you are starting the counters i and b with the length of the array, instead of the position of the last index. It should read...
public function checkhitammo():void {
for (var i:int = ammo.length - 1; i >= 0; i--) {
for (var b:int = enemys.length - 1; b >= 0; b--) {
That is, the length is 1-based, and positions are 0-based
first of all, all your for loops only has increment by 1 you may want to use like this
for (var i in ammo) {
for (var b in enemys) {
you just have to loop through array until something happens and break out of loop to make sure it doesn't check twice.
in this line
if (ammo[i].hitTestObject(enemys[b])) {
the error says program cannot find object in the array list, since it's just array it does not throw error like null pointer exception
if you swap ammo with enemys you will see that hitTestObject is trying to access a null object
and you don't really need to call this
ammo[i] = null;
since its already being removed

Action Script 3.0: how can I type other languages in the array or how can I use the other languages in grids

Here is my code. This is my word search game ...In word list array ...these are my questions to find in grid in the game...my questions how can I type other languages in the array or how can I use the other languages in grids
import flash.display.*;
import flash.text.*;
import flash.geom.Point;
import flash.events.*;
import flash.net.FileFilter;
import flash.filters.GlowFilter;
const puzzleSize:uint = 20;
const spacing:Number = 24;
const outlineSize:Number = 20;
const offsetoint = new Point(162.9,179.7);
const offsettoint = new Point(300,265);
const spacingg:Number = 36;
const letterFormat:TextFormat = new TextFormat("Bamini",18,0x000000,true,false,false,null,null,TextFormatAlign.CENTER);
// words and grid
var wordList:Array;
var usedWords:Array;
var grid:Array;
// game state
var dragModetring;
var startPoint,endPointoint;
var numFound:int;
// sprites
var gameSpriteprite;
var outlineSpriteprite;
var oldOutlineSpriteprite;
var letterSpritesprite;
var wordsSpriteprite;
startWordSearch();
function startWordSearch() {
**// word list**
wordList = ("Lion,Tiger,Cheetah,Panther".split(",";
// set up the sprites
gameSprite = new Sprite();
addChild(gameSprite);
oldOutlineSprite = new Sprite();
gameSprite.addChild(oldOutlineSprite);
outlineSprite = new Sprite();
gameSprite.addChild(outlineSprite);
letterSprites = new Sprite();
gameSprite.addChild(letterSprites);
wordsSprite = new Sprite();
gameSprite.addChild(wordsSprite);
// array of letters
var letters:Array = placeLetters();
// array of sprites
grid = new Array();
for(var x:int=0;x<puzzleSize;x++) {
grid[x] = new Array();
for(var y:int=0;y<puzzleSize;y++) {
// create new letter field and sprite
var newLetter:TextField = new TextField();
newLetter.defaultTextFormat = letterFormat;
newLetter.x = x*spacing + offset.x;
newLetter.y = y*spacing + offset.y;
newLetter.width = spacing;
newLetter.height = spacing;
newLetter.text = letters[x][y];
newLetter.selectable = false;
var newLetterSpriteprite = new Sprite();
newLetterSprite.addChild(newLetter);
letterSprites.addChild(newLetterSprite);
grid[x][y] = newLetterSprite;
// add event listeners
newLetterSprite.addEventListener(MouseEvent.MOUSE_DOWN, clickLetter);
newLetterSprite.addEventListener(MouseEvent.MOUSE_OVER, overLetter);
}
}
// stage listener
stage.addEventListener(MouseEvent.MOUSE_UP, mouseRelease);
// create word list fields and sprites
for(var i:int=0;i<usedWords.length;i++) {
//var myglow:GlowFilter=new GlowFilter();
//myglow.color = 0x0000FF;
//myglow.blurX=5;
//myglow.blurY=5;
//myglow.strength=200;
var newWord:TextField = new TextField();
newWord.defaultTextFormat = letterFormat;
newWord.x = 700;
newWord.y = i*spacingg+offsett.y;
newWord.width =140;
newWord.height =spacing;
newWord.text = usedWords[i];
//newWord.filters=[myglow];
newWord.selectable = false;
wordsSprite.addChild(newWord);
}
// set game state
dragMode = "none";
numFound = 0;
}
// place the words in a grid of letters
function placeLetters():Array {
// create empty grid
var letters:Array = new Array();
for(var x:int=0;x<puzzleSize;x++) {
letters[x] = new Array();
for(var y:int=0;y<puzzleSize;y++) {
letters[x][y] = "*";
}
}
// make copy of word list
var wordListCopy:Array = wordList.concat();
usedWords = new Array();
// make 1000 attempts to add words
var repeatTimes:int = 1000;
repeatLoop:while (wordListCopy.length > 0) {
if (repeatTimes-- <= 0) break;
// pick a random word, location and direction
var wordNum:int = Math.floor(Math.random()*wordListCopy.length);
var wordtring = wordListCopy[wordNum].toUpperCase();
x = Math.floor(Math.random()*puzzleSize);
y = Math.floor(Math.random()*puzzleSize);
var dx:int = Math.floor(Math.random()*3)-1;
var dy:int = Math.floor(Math.random()*3)-1;
if ((dx == 0) && (dy == 0)) continue repeatLoop;
// check each spot in grid to see if word fits
letterLoop:for (var j:int=0;j<word.length;j++) {
if ((x+dx*j < 0) || (y+dy*j < 0) || (x+dx*j >= puzzleSize) || (y+dy*j >= puzzleSize)) continue repeatLoop;
var thisLettertring = letters[x+dx*j][y+dy*j];
if ((thisLetter != "*" && (thisLetter != word.charAt(j))) continue repeatLoop;
}
// insert word into grid
insertLoop:for (j=0;j<word.length;j++) {
letters[x+dx*j][y+dy*j] = word.charAt(j);
}
// remove word from list
wordListCopy.splice(wordNum,1);
usedWords.push(word);
}
// fill rest of grid with random letters
for(x=0;x<puzzleSize;x++) {
for(y=0;y<puzzleSize;y++) {
if (letters[x][y] == "*" {
letters[x][y] = String.fromCharCode(65+Math.floor(Math.random()*26));
}
}
}
return letters;
}
// player clicks down on a letter to start
function clickLetter(event:MouseEvent) {
var lettertring = event.currentTarget.getChildAt(0).text;
startPoint = findGridPoint(event.currentTarget);
dragMode = "drag";
}
// player dragging over letters
function overLetter(event:MouseEvent) {
if (dragMode == "drag" {
endPoint = findGridPoint(event.currentTarget);
// if valid range, show outline
outlineSprite.graphics.clear();
if (isValidRange(startPoint,endPoint)) {
drawOutline(outlineSprite,startPoint,endPoint,0x66CCFF);
}
}
}
// mouse released
function mouseRelease(event:MouseEvent) {
if (dragMode == "drag" {
dragMode = "none";
outlineSprite.graphics.clear();
// get word and check it
if (isValidRange(startPoint,endPoint)) {
var word = getSelectedWord();
checkWord(word);
}
}
}
// when a letter is clicked, find and return the x and y location
function findGridPoint(letterSpritebject)oint {
// loop through all sprites and find this one
for(var x:int=0;x<puzzleSize;x++) {
for(var y:int=0;y<puzzleSize;y++) {
if (grid[x][y] == letterSprite) {
return new Point(x,y);
}
}
}
return null;
}
// determine if range is in the same row, column, or a 45 degree diagonal
function isValidRange(p1,p2oint):Boolean {
if (p1.x == p2.x) return true;
if (p1.y == p2.y) return true;
if (Math.abs(p2.x-p1.x) == Math.abs(p2.y-p1.y)) return true;
return false;
}
// draw a thick line from one location to another
function drawOutline(sprite,p1,p2oint,c:Number) {
var offoint = new Point(offset.x+spacing/2, offset.y+spacing/2);
s.graphics.lineStyle(outlineSize,c);
s.graphics.moveTo(p1.x*spacing+off.x ,p1.y*spacing+off.y);
s.graphics.lineTo(p2.x*spacing+off.x ,p2.y*spacing+off.y);
}
// find selected letters based on start and end points
function getSelectedWord()tring {
// determine dx and dy of selection, and word length
var dx = endPoint.x-startPoint.x;
var dy = endPoint.y-startPoint.y;
var wordLength:Number = Math.max(Math.abs(dx),Math.abs(dy))+1;
// get each character of selection
var wordtring = "";
for(var i:int=0;i<wordLength;i++) {
var x = startPoint.x;
if (dx < 0) x -= i;
if (dx > 0) x += i;
var y = startPoint.y;
if (dy < 0) y -= i;
if (dy > 0) y += i;
word += grid[x][y].getChildAt(0).text;
}
return word;
}
// check word against word list
function checkWord(wordtring) {
// loop through words
for(var i:int=0;i<usedWords.length;i++) {
// compare word
if (word == usedWords[i].toUpperCase()) {
foundWord(word);
}
// compare word reversed
var reverseWordtring = word.split("".reverse().join("";
if (reverseWord == usedWords[i].toUpperCase()) {
foundWord(reverseWord);
}
}
}
// word found, remove from list, make outline permanent
function foundWord(wordtring) {
// draw outline in permanent sprite
drawOutline(oldOutlineSprite,startPoint,endPoint,0xE01212);
// find text field and set it to gray
for(var i:int=0;i<wordsSprite.numChildren;i++) {
if (TextField(wordsSprite.getChildAt).text.toUpperCase() == word) {
TextField(wordsSprite.getChildAt).textColor = 0xFF0000;
}
}
// see if all have been found
numFound++;
if (numFound ==usedWords.length) {
endGame();
}
}
function endGame() {
gotoAndStop("gameover";
cleanUp();
Timee.stop();
}
function cleanUp() {
removeChild(gameSprite);
gameSprite = null;
grid = null;
vv=null;
}

Remove all Instance on stage as3

Im having trouble on removing instances on the stage.
The error I keep getting after I click the button 2 times is
"The supplied DisplayObject must be a child of the caller"
Can somebody help me with this?
package src
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
var positionY:Number = 80;
var positionX:Number = 0;
var motion:MovieClip;
var fCombo:Array = new Array();
var n:Number;
public function Main()
{
generate.addEventListener(MouseEvent.MOUSE_UP, loop);
generate.addEventListener(MouseEvent.MOUSE_DOWN, remove);
n = Number(inputText.text);
}
function loop(me:MouseEvent):void
{
var combo:Array = [Punch, Kick, Knee, Elbow];
n = Number(inputText.text);
for(var i:Number = 0;i < n;i++ )
{
motion = new combo[randomNumber(4)]();
fCombo.push(motion);
motion.y = positionY;
motion.x = positionX;
positionX += 100;
addChild(motion);
if (i == 4 || i == 9 || i == 14)
{
positionY += 40;
positionX = 0;
}
}
}
function remove(me:MouseEvent):void
{
for (var j:Number = 0; j < n; j++ )
{
removeChild(fCombo[j]);//error
}
positionY = 80;
positionX = 0;
}
function randomNumber(max:Number):Number
{
return(Math.floor(Math.random() * max ));
}
}
}
You're adding the new objects you create to the array, and then using that to remove them. But you're forgetting to either create a new list or remove the objects from the old list. So, when time comes to loop over the list you're trying to remove objects that have already been removed.
You can fix this in several ways, one is to remove objects from the stage AND array in your loop:
function remove(me:MouseEvent):void
{
while(fCombo.length)
{
removeChild(fCombo.pop());
}
positionY = 80;
positionX = 0;
}
targetDisplayObject.parent.removeChild( targetDisplayObject ); does the trick assuming the parent is not null.

Class in first frame.

Ok now I am more prepared. I have perfectly fine site. But when compress every thing to one frame. It stop working. Only thing I change is that I remove tween in IDE.
Code in Frame
stop();
import flash.events.MouseEvent;
import fl.transitions.Tween;
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.Strong;
import flash.events.Event;
var vektor:Array = new Array(I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII);
var menu:Wyjazd = new Wyjazd(vektor,firmaBTN,kontaktBTN,ofertaBTN,naglowek,tekst,dane);
ofertaBTN.addEventListener(MouseEvent.CLICK, test);
function test(e:MouseEvent):void
{
trace(String("click"));
}
Code in class Wyjazd
package
{
import fl.transitions.Tween;
import fl.motion.easing.*;
import flash.filters.*;
import flash.events.MouseEvent;
import flash.display.Stage;
import flash.display.MovieClip;
import flash.ui.Mouse;
import flash.display.*;
import flash.events.Event;
public class Wyjazd extends MovieClip
{
public function Wyjazd(ar:Array=null,firma:Object=null,kontakt:Object=null,oferta:Object=null,naglowek:Object=null,tekst:Object=null,dane:Object=null)
{
/*
if (ar!=null)
{
init(ar,firma,kontakt,oferta,naglowek,tekst,dane);
}
*/
if (stage)
{
init(ar,firma,kontakt,oferta,naglowek,tekst,dane);
}
else
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
}
public function init(ar:Array,firma:Object=null,kontakt=null,oferta:Object=null,naglowek:Object=null,tekst:Object=null,dane:Object=null):void
{
//Zmienne "globalne" dla funkcji
var time:Number;
var wciecie:Number;
var wciecie2:Number;
var offset:Number = 15.65;
var offset2:Number = 20;
var posX:Array = new Array(12);
var posY:Array = new Array(12);
var spr:Array = new Array(12);
var targetLabel:String;
var wybranyOb:Object = ar[0];
var names:Array = new Array('Szkolenie wstępne BHP','Szkolenie okresowe BHP','Szkolenie P.Poż','Kompleksowa obsługa P.Poż','Pomiar środowiska pracy','Szkolenie z udzielania pierwszej pomocy','Ocena ryzyka zawodowego','Przeprowadzanie postępowań po wypadkowych','Przeprowadzanie audytów wewnętrznych ISO','Hałas w środowisku komunalnym','Medycyna pracy','Szkolenia dla kierowców');
//Pobieranie pozycji
for (var i:Number = 0; i<ar.length; i++)
{
posX[i] = ar[i].x;
posY[i] = ar[i].y;
trace(String("klasa"));
}
//Filtry
function increaseBlur(e:MouseEvent,docPos:Number):void
{
var myBlur:BlurFilter =new BlurFilter();
myBlur.quality = 3;
myBlur.blurX = 10;
myBlur.blurY = 0;
}
//Funkcje
function startPos():void
{
time = 0.2;
for (var i:Number = 0; i<ar.length; i++)
{
//if (wybranyOb.name == ar[i].name)
//{
//var wybranyPos:Tween = new Tween(ar[i],"x",Linear.easeOut,ar[i].x,posX[i],0.01,true);
//wybranyPos = new Tween(ar[i],"y",Linear.easeOut,-30,posY[i],time,true);
//}
//else
//{
var position:Tween = new Tween(ar[i],"x",Linear.easeOut,ar[i].x,posX[i],time,true);
position = new Tween(ar[i],"y",Linear.easeOut,ar[i].y,posY[i],time,true);
//}
//time = 0.2;
}
position = new Tween(naglowek,"x",Linear.easeOut,naglowek.x,2000,time,true);
position = new Tween(tekst,"x",Linear.easeOut,tekst.x,2000,time,true);
position = new Tween(dane,"x",Linear.easeOut,dane.x,2000,0.25,true);
}
//Nasłuchy
oferta.addEventListener(MouseEvent.CLICK, wyskokOferta);
oferta.addEventListener(MouseEvent.MOUSE_OVER,glowOferta);
oferta.addEventListener(MouseEvent.MOUSE_OUT,unglowOferta);
kontakt.addEventListener(MouseEvent.CLICK,wyskokKontakt);
kontakt.addEventListener(MouseEvent.MOUSE_OVER,glowKontakt);
kontakt.addEventListener(MouseEvent.MOUSE_OUT,unglowKontakt);
firma.addEventListener(MouseEvent.CLICK,wyskokFirma);
firma.addEventListener(MouseEvent.MOUSE_OVER,glowFirma);
firma.addEventListener(MouseEvent.MOUSE_OUT,unglowFirma);
function glowFirma(e:MouseEvent):void
{
var myGlow:GlowFilter=new GlowFilter();
myGlow.color = 0xe6da13;
myGlow.inner = true;
firma.filters = [myGlow];
}
function unglowFirma(e:MouseEvent):void
{
firma.filters = [];
}
function glowKontakt(e:MouseEvent):void
{
var myGlow:GlowFilter=new GlowFilter();
myGlow.color = 0xe6da13;
myGlow.inner = true;
kontakt.filters = [myGlow];
}
function unglowKontakt(e:MouseEvent):void
{
kontakt.filters = [];
}
function glowOferta(e:MouseEvent):void
{
var myGlow:GlowFilter=new GlowFilter();
myGlow.color = 0xe6da13;
myGlow.inner = true;
oferta.filters = [myGlow];
}
function unglowOferta(e:MouseEvent):void
{
oferta.filters = [];
}
function wyskokKontakt(e:MouseEvent):void
{
startPos();
var tweenKontakt = new Tween(dane,"x",Linear.easeOut,2000,350,0.25,true);
}
function wyskokFirma(e:MouseEvent):void
{
startPos();
trace("Firma");
}
function wyskokOferta(e:MouseEvent):void
{
time = 0.2;
wciecie = 52.5;
wciecie2 = 67.45;
for (var i:Number = 0; i < ar.length; i++)
{
var tween:Tween = new Tween(ar[i],"x",Sine.easeOut,ar[i].x,oferta.x + wciecie,time,true);
tween = new Tween(ar[i],"y",Sine.easeOut,ar[i].y,oferta.y + wciecie2,time,true);
ar[i].addEventListener(MouseEvent.CLICK,onClick);
spr[i] = i;
time += 0.02;
wciecie += offset;
wciecie2 += offset2;
}
}
function onClick(e:MouseEvent)
{
startPos();
time = 0.2;
var k:Number = 0;
targetLabel = e.currentTarget.name;
for (var i:Number = 0; i < ar.length; i++)
{
if (targetLabel==ar[i].name)
{
//wybranyOb = ar[i];
var tween:Tween = new Tween(ar[i],"x",Linear.easeOut,ar[i].x,posX[i],time,true);
tween = new Tween(ar[i],"y",Linear.easeOut,ar[i].y,posY[i],time,true);
tween = new Tween(naglowek,"x",Linear.easeOut,2000,60,0.2,true);
tween = new Tween(tekst,"x",Linear.easeOut,2000,500,0.25,true);
naglowek.text = names[i];
}
else
{
var tween1:Tween = new Tween(ar[i],"x",Linear.easeOut,ar[i].x,posX[i],time,true);
tween1 = new Tween(ar[i],"y",Linear.easeOut,ar[i].y,posY[i],time,true);
}
//time += 0.02;
}
}
}
}
}
How it's looks like frame.
http://www.dropmocks.com/mbe3j
You should take all the (nested) functions out of init.
So it is more like this:
package
{
import fl.transitions.Tween;
import fl.motion.easing.*;
import flash.filters.*;
import flash.events.MouseEvent;
import flash.display.Stage;
import flash.display.MovieClip;
import flash.ui.Mouse;
import flash.display.*;
import flash.events.Event;
public class Wyjazd extends MovieClip
{
public function Wyjazd(ar:Array=null,firma:Object=null,kontakt:Object=null,oferta:Object=null,naglowek:Object=null,tekst:Object=null,dane:Object=null)
{
/*
if (ar!=null)
{
init(ar,firma,kontakt,oferta,naglowek,tekst,dane);
}
*/
if (stage)
{
init(ar,firma,kontakt,oferta,naglowek,tekst,dane);
}
else
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
}
public function init(ar:Array,firma:Object=null,kontakt=null,oferta:Object=null,naglowek:Object=null,tekst:Object=null,dane:Object=null):void
{
//Zmienne "globalne" dla funkcji
var time:Number;
var wciecie:Number;
var wciecie2:Number;
var offset:Number = 15.65;
var offset2:Number = 20;
var posX:Array = new Array(12);
var posY:Array = new Array(12);
var spr:Array = new Array(12);
var targetLabel:String;
var wybranyOb:Object = ar[0];
var names:Array = new Array('Szkolenie wstępne BHP','Szkolenie okresowe BHP','Szkolenie P.Poż','Kompleksowa obsługa P.Poż','Pomiar środowiska pracy','Szkolenie z udzielania pierwszej pomocy','Ocena ryzyka zawodowego','Przeprowadzanie postępowań po wypadkowych','Przeprowadzanie audytów wewnętrznych ISO','Hałas w środowisku komunalnym','Medycyna pracy','Szkolenia dla kierowców');
//Pobieranie pozycji
for (var i:Number = 0; i<ar.length; i++)
{
posX[i] = ar[i].x;
posY[i] = ar[i].y;
trace(String("klasa"));
}
//Nasłuchy
oferta.addEventListener(MouseEvent.CLICK, wyskokOferta);
oferta.addEventListener(MouseEvent.MOUSE_OVER,glowOferta);
oferta.addEventListener(MouseEvent.MOUSE_OUT,unglowOferta);
kontakt.addEventListener(MouseEvent.CLICK,wyskokKontakt);
kontakt.addEventListener(MouseEvent.MOUSE_OVER,glowKontakt);
kontakt.addEventListener(MouseEvent.MOUSE_OUT,unglowKontakt);
firma.addEventListener(MouseEvent.CLICK,wyskokFirma);
firma.addEventListener(MouseEvent.MOUSE_OVER,glowFirma);
firma.addEventListener(MouseEvent.MOUSE_OUT,unglowFirma);
}
public function glowFirma(e:MouseEvent):void
{
var myGlow:GlowFilter=new GlowFilter();
myGlow.color = 0xe6da13;
myGlow.inner = true;
firma.filters = [myGlow];
}
public function unglowFirma(e:MouseEvent):void
{
firma.filters = [];
}
public function glowKontakt(e:MouseEvent):void
{
var myGlow:GlowFilter=new GlowFilter();
myGlow.color = 0xe6da13;
myGlow.inner = true;
kontakt.filters = [myGlow];
}
public function unglowKontakt(e:MouseEvent):void
{
kontakt.filters = [];
}
public function glowOferta(e:MouseEvent):void
{
var myGlow:GlowFilter=new GlowFilter();
myGlow.color = 0xe6da13;
myGlow.inner = true;
oferta.filters = [myGlow];
}
public function unglowOferta(e:MouseEvent):void
{
oferta.filters = [];
}
public function wyskokKontakt(e:MouseEvent):void
{
startPos();
var tweenKontakt = new Tween(dane,"x",Linear.easeOut,2000,350,0.25,true);
}
public function wyskokFirma(e:MouseEvent):void
{
startPos();
trace("Firma");
}
public function wyskokOferta(e:MouseEvent):void
{
time = 0.2;
wciecie = 52.5;
wciecie2 = 67.45;
for (var i:Number = 0; i < ar.length; i++)
{
var tween:Tween = new Tween(ar[i],"x",Sine.easeOut,ar[i].x,oferta.x + wciecie,time,true);
tween = new Tween(ar[i], "y", Sine.easeOut, ar[i].y, oferta.y + wciecie2, time, true);
ar[i].addEventListener(MouseEvent.CLICK,onClick);
spr[i] = i;
time += 0.02;
wciecie += offset;
wciecie2 += offset2;
}
}
//Filtry
public function increaseBlur(e:MouseEvent,docPos:Number):void
{
var myBlur:BlurFilter =new BlurFilter();
myBlur.quality = 3;
myBlur.blurX = 10;
myBlur.blurY = 0;
}
//Funkcje
public function startPos():void
{
time = 0.2;
for (var i:Number = 0; i<ar.length; i++)
{
//if (wybranyOb.name == ar[i].name)
//{
//var wybranyPos:Tween = new Tween(ar[i],"x",Linear.easeOut,ar[i].x,posX[i],0.01,true);
//wybranyPos = new Tween(ar[i],"y",Linear.easeOut,-30,posY[i],time,true);
//}
//else
//{
var position:Tween = new Tween(ar[i],"x",Linear.easeOut,ar[i].x,posX[i],time,true);
position = new Tween(ar[i],"y",Linear.easeOut,ar[i].y,posY[i],time,true);
//}
//time = 0.2;
}
position = new Tween(naglowek,"x",Linear.easeOut,naglowek.x,2000,time,true);
position = new Tween(tekst,"x",Linear.easeOut,tekst.x,2000,time,true);
position = new Tween(dane,"x",Linear.easeOut,dane.x,2000,0.25,true);
}
public function onClick(e:MouseEvent)
{
startPos();
time = 0.2;
var k:Number = 0;
targetLabel = e.currentTarget.name;
for (var i:Number = 0; i < ar.length; i++)
{
if (targetLabel==ar[i].name)
{
//wybranyOb = ar[i];
var tween:Tween = new Tween(ar[i],"x",Linear.easeOut,ar[i].x,posX[i],time,true);
tween = new Tween(ar[i],"y",Linear.easeOut,ar[i].y,posY[i],time,true);
tween = new Tween(naglowek,"x",Linear.easeOut,2000,60,0.2,true);
tween = new Tween(tekst,"x",Linear.easeOut,2000,500,0.25,true);
naglowek.text = names[i];
}
else
{
var tween1:Tween = new Tween(ar[i],"x",Linear.easeOut,ar[i].x,posX[i],time,true);
tween1 = new Tween(ar[i],"y",Linear.easeOut,ar[i].y,posY[i],time,true);
}
//time += 0.02;
}
}
}
}
If this doesn't help, you should post more details. I don't know how you 'compressed everything' into a single frame, but I suggest you read more about Object Oriented Programming.
A quick Google search resulted in this article, which might help you out with Object Oriented programming in Action Script 3.