Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Consolidation Of ActionScript [F8]&[F9]



have been running into the same problem multiple times and I know there is an easier way to do this.. any ideas out there?

here would be an example of some code:


PHP Code:



btn1.onPress = function(){
    do the same thing;
    }
btn2.onPress = function(){
    do the same thing;
    }
btn3.onPress = function(){
    do the same thing;
    }
btn4.onPress = function(){
    do the same thing;
    }



FlashKit > Flash Help > Flash ActionScript
Posted on: 05-05-2008, 02:35 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Function Consolidation Help
Okay,

I know there has to be an easier way to write this.
Can someone please point me in the right direction?

There has got to be a way to use 1 function and some type of variable to make to add the new sprites from an array with a for statement. I just don't know how. Any help would be greatly appreciated.

Thanks,

Wayne


Code:
//Add the button onto the stage
var homebutton:Sprite = new Sprite();
var aboutbutton:Sprite = new Sprite();
var servicesbutton:Sprite = new Sprite();
var specialsbutton:Sprite = new Sprite();
var contactbutton:Sprite = new Sprite();

homebutton.buttonMode = true;
aboutbutton.buttonMode = true;
servicesbutton.buttonMode = true;
specialsbutton.buttonMode = true;
contactbutton.buttonMode = true;

homebutton.addChild(home);
aboutbutton.addChild(about);
servicesbutton.addChild(services);
specialsbutton.addChild(specials);
contactbutton.addChild(contact);

// AddEvent for Home Button
this.home.addEventListener("mouseOver",homedoOver);
this.home.addEventListener("mouseOut",homedoOut);
this.home.addEventListener("mouseDown",homedoDown);
this.home.addEventListener("mouseUp",homedoUp);

// AddEvent for about Button
this.about.addEventListener("mouseOver",aboutdoOver);
this.about.addEventListener("mouseOut",aboutdoOut);
this.about.addEventListener("mouseDown",aboutdoDown);
this.about.addEventListener("mouseUp",aboutdoUp);

// AddEvent for services Button
this.services.addEventListener("mouseOver",servicesdoOver);
this.services.addEventListener("mouseOut",servicesdoOut);
this.services.addEventListener("mouseDown",servicesdoDown);
this.services.addEventListener("mouseUp",servicesdoUp);
// AddEvent for specials Button
this.specials.addEventListener("mouseOver",specialsdoOver);
this.specials.addEventListener("mouseOut",specialsdoOut);
this.specials.addEventListener("mouseDown",specialsdoDown);
this.specials.addEventListener("mouseUp",specialsdoUp);
// AddEvent for contact Button
this.contact.addEventListener("mouseOver",contactdoOver);
this.contact.addEventListener("mouseOut",contactdoOut);
this.contact.addEventListener("mouseDown",contactdoDown);
this.contact.addEventListener("mouseUp",contactdoUp);

addChild(homebutton);
addChild(aboutbutton);
addChild(servicesbutton);
addChild(specialsbutton);
addChild(contactbutton);

//Home Button Function
function homedoOver(evt:MouseEvent)
{
home.gotoAndPlay(2);
}
function homedoOut(evt:MouseEvent)
{
home.gotoAndPlay(11);
}
function homedoDown(evt:MouseEvent)
{
home.gotoAndPlay(21);
}
function homedoUp(evt:MouseEvent)
{
home.gotoAndStop(10);
}


//About Button Function
function aboutdoOver(evt:MouseEvent)
{
about.gotoAndPlay(2);
}
function aboutdoOut(evt:MouseEvent)
{
about.gotoAndPlay(11);
}
function aboutdoDown(evt:MouseEvent)
{
about.gotoAndPlay(21);
}
function aboutdoUp(evt:MouseEvent)
{
about.gotoAndStop(10);
}


//Services Button Function
function servicesdoOver(evt:MouseEvent)
{
services.gotoAndPlay(2);
}
function servicesdoOut(evt:MouseEvent)
{
services.gotoAndPlay(11);
}
function servicesdoDown(evt:MouseEvent)
{
services.gotoAndPlay(21);
}
function servicesdoUp(evt:MouseEvent)
{
services.gotoAndStop(10);
}


//Specials Button Function
function specialsdoOver(evt:MouseEvent)
{
specials.gotoAndPlay(2);
}
function specialsdoOut(evt:MouseEvent)
{
specials.gotoAndPlay(11);
}
function specialsdoDown(evt:MouseEvent)
{
specials.gotoAndPlay(21);
}
function specialsdoUp(evt:MouseEvent)
{
specials.gotoAndStop(10);
}


//Contact Button Function
function contactdoOver(evt:MouseEvent)
{
contact.gotoAndPlay(2);
}
function contactdoOut(evt:MouseEvent)
{
contact.gotoAndPlay(11);
}
function contactdoDown(evt:MouseEvent)
{
contact.gotoAndPlay(21);
}
function contactdoUp(evt:MouseEvent)
{
contact.gotoAndStop(10);
}

Function Consolidation Help
Okay,

I know there has to be an easier way to write this.
Can someone please point me in the right direction?

There has got to be a way to use 1 function and some type of variable to make to add the new sprites from an array with a for statement. I just don't know how. Any help would be greatly appreciated.

Thanks,

Wayne


Code:
//Add the button onto the stage
var homebutton:Sprite = new Sprite();
var aboutbutton:Sprite = new Sprite();
var servicesbutton:Sprite = new Sprite();
var specialsbutton:Sprite = new Sprite();
var contactbutton:Sprite = new Sprite();

homebutton.buttonMode = true;
aboutbutton.buttonMode = true;
servicesbutton.buttonMode = true;
specialsbutton.buttonMode = true;
contactbutton.buttonMode = true;

homebutton.addChild(home);
aboutbutton.addChild(about);
servicesbutton.addChild(services);
specialsbutton.addChild(specials);
contactbutton.addChild(contact);

// AddEvent for Home Button
this.home.addEventListener("mouseOver",homedoOver);
this.home.addEventListener("mouseOut",homedoOut);
this.home.addEventListener("mouseDown",homedoDown);
this.home.addEventListener("mouseUp",homedoUp);

// AddEvent for about Button
this.about.addEventListener("mouseOver",aboutdoOver);
this.about.addEventListener("mouseOut",aboutdoOut);
this.about.addEventListener("mouseDown",aboutdoDown);
this.about.addEventListener("mouseUp",aboutdoUp);

// AddEvent for services Button
this.services.addEventListener("mouseOver",servicesdoOver);
this.services.addEventListener("mouseOut",servicesdoOut);
this.services.addEventListener("mouseDown",servicesdoDown);
this.services.addEventListener("mouseUp",servicesdoUp);
// AddEvent for specials Button
this.specials.addEventListener("mouseOver",specialsdoOver);
this.specials.addEventListener("mouseOut",specialsdoOut);
this.specials.addEventListener("mouseDown",specialsdoDown);
this.specials.addEventListener("mouseUp",specialsdoUp);
// AddEvent for contact Button
this.contact.addEventListener("mouseOver",contactdoOver);
this.contact.addEventListener("mouseOut",contactdoOut);
this.contact.addEventListener("mouseDown",contactdoDown);
this.contact.addEventListener("mouseUp",contactdoUp);

addChild(homebutton);
addChild(aboutbutton);
addChild(servicesbutton);
addChild(specialsbutton);
addChild(contactbutton);

//Home Button Function
function homedoOver(evt:MouseEvent)
{
home.gotoAndPlay(2);
}
function homedoOut(evt:MouseEvent)
{
home.gotoAndPlay(11);
}
function homedoDown(evt:MouseEvent)
{
home.gotoAndPlay(21);
}
function homedoUp(evt:MouseEvent)
{
home.gotoAndStop(10);
}


//About Button Function
function aboutdoOver(evt:MouseEvent)
{
about.gotoAndPlay(2);
}
function aboutdoOut(evt:MouseEvent)
{
about.gotoAndPlay(11);
}
function aboutdoDown(evt:MouseEvent)
{
about.gotoAndPlay(21);
}
function aboutdoUp(evt:MouseEvent)
{
about.gotoAndStop(10);
}


//Services Button Function
function servicesdoOver(evt:MouseEvent)
{
services.gotoAndPlay(2);
}
function servicesdoOut(evt:MouseEvent)
{
services.gotoAndPlay(11);
}
function servicesdoDown(evt:MouseEvent)
{
services.gotoAndPlay(21);
}
function servicesdoUp(evt:MouseEvent)
{
services.gotoAndStop(10);
}


//Specials Button Function
function specialsdoOver(evt:MouseEvent)
{
specials.gotoAndPlay(2);
}
function specialsdoOut(evt:MouseEvent)
{
specials.gotoAndPlay(11);
}
function specialsdoDown(evt:MouseEvent)
{
specials.gotoAndPlay(21);
}
function specialsdoUp(evt:MouseEvent)
{
specials.gotoAndStop(10);
}


//Contact Button Function
function contactdoOver(evt:MouseEvent)
{
contact.gotoAndPlay(2);
}
function contactdoOut(evt:MouseEvent)
{
contact.gotoAndPlay(11);
}
function contactdoDown(evt:MouseEvent)
{
contact.gotoAndPlay(21);
}
function contactdoUp(evt:MouseEvent)
{
contact.gotoAndStop(10);
}

Function Consolidation Help
Okay,

I know there has to be an easier way to write this.
Can someone please point me in the right direction?

There has got to be a way to use 1 function and some type of variable to make to add the new sprites from an array with a for statement. I just don't know how. Any help would be greatly appreciated.

Thanks,

Wayne









Attach Code

//Add the button onto the stage
var homebutton:Sprite = new Sprite();
var aboutbutton:Sprite = new Sprite();
var servicesbutton:Sprite = new Sprite();
var specialsbutton:Sprite = new Sprite();
var contactbutton:Sprite = new Sprite();

homebutton.buttonMode = true;
aboutbutton.buttonMode = true;
servicesbutton.buttonMode = true;
specialsbutton.buttonMode = true;
contactbutton.buttonMode = true;

homebutton.addChild(home);
aboutbutton.addChild(about);
servicesbutton.addChild(services);
specialsbutton.addChild(specials);
contactbutton.addChild(contact);

// AddEvent for Home Button
this.home.addEventListener("mouseOver",homedoOver);
this.home.addEventListener("mouseOut",homedoOut);
this.home.addEventListener("mouseDown",homedoDown);
this.home.addEventListener("mouseUp",homedoUp);

// AddEvent for about Button
this.about.addEventListener("mouseOver",aboutdoOver);
this.about.addEventListener("mouseOut",aboutdoOut);
this.about.addEventListener("mouseDown",aboutdoDown);
this.about.addEventListener("mouseUp",aboutdoUp);

// AddEvent for services Button
this.services.addEventListener("mouseOver",servicesdoOver);
this.services.addEventListener("mouseOut",servicesdoOut);
this.services.addEventListener("mouseDown",servicesdoDown);
this.services.addEventListener("mouseUp",servicesdoUp);
// AddEvent for specials Button
this.specials.addEventListener("mouseOver",specialsdoOver);
this.specials.addEventListener("mouseOut",specialsdoOut);
this.specials.addEventListener("mouseDown",specialsdoDown);
this.specials.addEventListener("mouseUp",specialsdoUp);
// AddEvent for contact Button
this.contact.addEventListener("mouseOver",contactdoOver);
this.contact.addEventListener("mouseOut",contactdoOut);
this.contact.addEventListener("mouseDown",contactdoDown);
this.contact.addEventListener("mouseUp",contactdoUp);

addChild(homebutton);
addChild(aboutbutton);
addChild(servicesbutton);
addChild(specialsbutton);
addChild(contactbutton);

//Home Button Function
function homedoOver(evt:MouseEvent)
{
home.gotoAndPlay(2);
}
function homedoOut(evt:MouseEvent)
{
home.gotoAndPlay(11);
}
function homedoDown(evt:MouseEvent)
{
home.gotoAndPlay(21);
}
function homedoUp(evt:MouseEvent)
{
home.gotoAndStop(10);
}


//About Button Function
function aboutdoOver(evt:MouseEvent)
{
about.gotoAndPlay(2);
}
function aboutdoOut(evt:MouseEvent)
{
about.gotoAndPlay(11);
}
function aboutdoDown(evt:MouseEvent)
{
about.gotoAndPlay(21);
}
function aboutdoUp(evt:MouseEvent)
{
about.gotoAndStop(10);
}


//Services Button Function
function servicesdoOver(evt:MouseEvent)
{
services.gotoAndPlay(2);
}
function servicesdoOut(evt:MouseEvent)
{
services.gotoAndPlay(11);
}
function servicesdoDown(evt:MouseEvent)
{
services.gotoAndPlay(21);
}
function servicesdoUp(evt:MouseEvent)
{
services.gotoAndStop(10);
}


//Specials Button Function
function specialsdoOver(evt:MouseEvent)
{
specials.gotoAndPlay(2);
}
function specialsdoOut(evt:MouseEvent)
{
specials.gotoAndPlay(11);
}
function specialsdoDown(evt:MouseEvent)
{
specials.gotoAndPlay(21);
}
function specialsdoUp(evt:MouseEvent)
{
specials.gotoAndStop(10);
}


//Contact Button Function
function contactdoOver(evt:MouseEvent)
{
contact.gotoAndPlay(2);
}
function contactdoOut(evt:MouseEvent)
{
contact.gotoAndPlay(11);
}
function contactdoDown(evt:MouseEvent)
{
contact.gotoAndPlay(21);
}
function contactdoUp(evt:MouseEvent)
{
contact.gotoAndStop(10);
}

Flash MX Code Consolidation
I am trying to recreate a site with as much actionscript as I can to make it easy to update. I am using movie clips for buttons and want all the code to be compact. With the big help of a coder named Sorcerer, the following code has been put together. I know it's very close but with my skills (or lack thereof) I am unable to see my error in executing it.

If anyone out there has the time or inclination to explain my errors, I'd appreciate it. Thanks.


PHP Code:



//all button code
Button_Names = new Array();
Button_Names[0] = "about"
Button_Names[1] = "portfolio"
Button_Names[2] = "extras"
Button_Names[3] = "audio"
Button_Names[4] = "client"
Button_Names[5] = "email"
Button_Names[6] = "phone"
Button_Names[7] = "privacy"
Button_Names[8] = "credits"
Button_Names[9] = "as"

for (i=0; i<=9; i++){
    item = Button_Names[i];
    this[item+"_btn"].onRelease=function(){
    if (item == "about" || item == "portfolio" || item == "extras" ||
        item == "audio" || item == "client" || item == "email" ||
        item == "phone" || item == "privacy" || item == "credits" ||
        item == "as")
        loadMovieNum(item+".swf", 2);
        this.gotoAndStop("_disabled");
        this.enabled = false;
        }
}
    this[item+"_btn"].onRollover=function(){
            this[item+"_btn"].gotoAndPlay("_over");
        }
    this[item+"_btn"].onRollout=function(){
            this[item+"_btn"].gotoAndPlay("_up");
        }
    this[item+"_btn"].onPress=function(){
            this[item+"_btn"].gotoAndPlay("_down");
       }
    function Enable_Button(selected){
        for (i=0; i<=9; i++){
            if(Button_Name[i] !== selected){
            _root[Button_Name[i]].gotoAndStop("_up");
        }
    }
};
//end button code

I Repeat Myself[Code Consolidation Question]
Hi,

In the code below, I've called to several xml objects and functions with repetitive behavior, it functions fine. However would someone offer a solution for pruning this bramble?

Code:
//Create a new style sheet object
var flaCSS = new TextField.StyleSheet();
//Specify the location of the CSS file.
var cssURL = "c/core.css";
//Load CSS file
flaCSS.load(cssURL);
//define onLoad handler
flaCSS.onLoad = function(success) {
if (!success) {
trace("Document Failed To Load");
}
};
/*
//Create the text format object.
var formatText:TextFormat = new TextFormat();
formatText.font = "Verdana";
formatText.color = 0xFEFEFE;
formatText.size = 9;
//
*/
//Create and populate the about xml object
var aboutXML:XML = new XML();
aboutXML.onLoad = handleAboutData;
aboutXML.load("x/about.xml");
function handlAboutData(success) {
if (!success) {
trace("Document Failed To Load");
}
}
//
//Create and populate the services xml object
var servicesXML:XML = new XML();
servicesXML.onLoad = handleServicesData;
servicesXML.load("x/services.xml");
function handleServicesData(success) {
if (!success) {
trace("Document Failed To Load");
}
}
//
//Create and populate the meditation xml object
var meditationXML:XML = new XML();
meditationXML.onLoad = handleMeditationData;
meditationXML.load("x/meditation.xml");
function handleMeditationData(success) {
if (!success) {
trace("Document Failed To Load");
}
}
//
//Create and populate the portfolio xml object
var portfolioXML:XML = new XML();
portfolioXML.onLoad = handlePorfolioData;
portfolioXML.load("x/portfolio.xml");
function handlePortfolioData(success) {
if (!success) {
trace("Document Failed To Load");
}
}
//
function loadServices() {
this.main_mc.main_txt.styleSheet = flaCSS;
this.main_mc.main_txt.htmlText = servicesXML;
this.main_mc.main_txt.html = true;

//this.main_mc.main_txt.setTextFormat(formatText);
}
function loadAbout() {
this.main_mc.main_txt.styleSheet = flaCSS;
this.main_mc.main_txt.htmlText = aboutXML;
this.main_mc.main_txt.html = true;

//this.main_mc.main_txt.setTextFormat(formatText);
}
function loadMeditation() {
this.main_mc.main_txt.styleSheet = flaCSS;
this.main_mc.main_txt.htmlText = meditationXML;
this.main_mc.main_txt.html = true;

//this.main_mc.main_txt.setTextFormat(formatText);
}
function loadPortfolio() {
this.main_mc.main_txt.styleSheet = flaCSS;
this.main_mc.main_txt.htmlText = portfolioXML;
this.main_mc.main_txt.html = true;

//this.main_mc.main_txt.setTextFormat(formatText);
}

Basic Moving Clip W/actionscript + Random Motion W/actionscript
ive tried this many times w/logical scripts but i dont know how

how do you create motion w/actionscript?

also, how do you randomize the motion?

any help would be appreciated

Adding Actionscript To An Empty Movie Clip Created By Actionscript
Ok, I'm trying to figure out if I can add actionscript to an empty movie clip that I created using actionscript. Is it possible and if so, how?

Thanks,
Doug

[FCS3] Adding Actionscript To A Movieclip Through Actionscript?
Yo, is there a way to add actionscript to a movieclip created in actionscript? Such as a onClipEvent(load) and onClipEvent(enterframe)? I have a onEnterFrame already for the movie clip as its created though. I have taken code thats from a gravity tutorial where it uses the two methods above. I've tried adding them into the onEnterFrame that I had already to add gravity to the movieclips created though that did'nt work =(

Jigsaw Puzzle - Changing From Actionscript 2.0 To Actionscript 3.0
Hello Everyone,

I was hoping someone could help me convert the following actionscript from actionscript 2.0 to actionscript 3.0. I'm trying to complete a jigsaw puzzple but I'm having problems converting it into actionscript 3.0.

Below is my actionscript:

//Puzzle Pieces
scramble_btn.onRelease = function(){
piece1._x = random(250);
piece1._y= random(250);
piece2._x = random(250);
piece2._y= random(250);
piece3._x = random(250);
piece3._y= random(250);
piece4._x = random(250);
piece4._y= random(250);
startGame();
messageOn.text = "";
counter.text = "00:00";
clearInterval(timeStarted);
timeStarted = setInterval(countdown, 1000);
time_start = 0;
}

//Puzzle Move
function startGame(){
piece1.onPress = function(){
this.startDrag();
piece1.swapDepths(1)
}
piece1.onRelease = function() {
this.stopDrag();
hit1();
checker();
};
piece2.onPress = function(){
this.startDrag();
piece2.swapDepths(1)
}
piece2.onRelease = function() {
this.stopDrag();
hit2();
checker();
};
piece3.onPress = function(){
this.startDrag();
piece3.swapDepths(1)
}
piece3.onRelease = function() {
this.stopDrag();
hit3();
checker();
};
piece4.onPress = function(){
this.startDrag();
piece4.swapDepths(1)
}
piece4.onRelease = function() {
this.stopDrag();
hit4();
checker();
}
};

//HitTest Script
function hit1(){
if(piece1.hitTest(container1)){
piece1._x = container1._x;
piece1._y = container1._y;
}else{
piece1._x = random(250);
piece1._y = random(250);
}
}
function hit2(){
if(piece2.hitTest(container2)){
piece2._x = container2._x;
piece2._y = container2._y;
}else{
piece2._x = random(250);
piece2._y = random(250);
}
}
function hit3(){
if(piece3.hitTest(container3)){
piece3._x = container3._x;
piece3._y = container3._y;
}else{
piece3._x = random(250);
piece3._y = random(250);
}
}
function hit4(){
if(piece4.hitTest(container4)){
piece4._x = container4._x;
piece4._y = container4._y;
}else{
piece4._x = random(250);
piece4._y = random(250);
}
}

//Timer
counter.text = "00:00";

function countdown() {
started();
time_start = time_start+1;
if (time_start>10) {
messageOn.text = "GAME OVER!!!";
clearInterval(timeStarted);
}
}

function started(){
sec = Math.floor(time_start+1/1000);
sec = (sec<10)?"0"+sec:sec;
min = Math.floor(sec/60);
min = (min<10)?"0"+min:min;
counter.text = min+":"+sec;
};

//This will check if all puzzle pieces are complete...and display game finish messsage.
function checker(){
if((piece1.hitTest(container1)) && (piece2.hitTest(container2)) && (piece3.hitTest(container3)) && (piece4.hitTest(container4))){
messageOn.text = "CONGRATULATIONS!!!";
clearInterval(timeStarted);
}
}

Giving Actionscript To An Actionscript-loaded Movie
How can I (if possible) set actionscript (say, an on-mouse event) to a movie that I load via attachMovie()? I poked around and I couldn't seem to find an answer...

I want the movie that I load via attachMovie() to have an on(RollOver) event...any thoughts?

Warning: An ActionScript 1.0/2.0 SWF File Has Loaded An ActionScript 3.0 SWF;
Hi all,

I'm trying to clone an swf (produced in CS3) that has been loaded into my app (built using Actionscript/mxmlc) but keep getting the following message appear in my logs:


Code:
Warning: An ActionScript 1.0/2.0 SWF file has loaded an ActionScript 3.0 SWF; code in the ActionScript 3.0 SWF will not run.
I know the CS3 swf has been produced using Actionscript 3 as it's settings and published for FP9. It does nothing more than a motion tween of a graphic.

Here is a really simple example of how to emulate the problem:

ActionScript Code:
package{

    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLRequest;
   
    [SWF(backgroundColor=0x000000)]

    public class Test extends Sprite{
       
        private var _mc:MovieClip;
   
        public function Test():void{
       
            var mc:String = "rain.swf";
            var ldr:Loader = new Loader();
           
            ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,loadedSWF);
            ldr.load(new URLRequest(mc));
        }
       
        private function loadedSWF(e:Event):void{
           
            var mc:MovieClip = MovieClip(e.target.content);
           
            this._mc = MovieClip(new (mc.constructor)());
            this.addChild(this._mc);
        }
   
    }
}

I'm using the following version of mxmlc: Version 3.0.0 build 1844

I've also tried a slightly more convoluted way:

ActionScript Code:
package{

    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.utils.getQualifiedClassName;
    import flash.net.URLRequest;
   
    [SWF(backgroundColor=0x000000)]

    public class Test extends Sprite{
       
        private var _mc:MovieClip;
   
        public function Test():void{
       
            var mc:String = "rain.swf";
            var ldr:Loader = new Loader();
           
            ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,loadedSWF);
            ldr.load(new URLRequest(mc));
        }
       
        private function loadedSWF(e:Event):void{
           
            var c:Class = Class(e.target.applicationDomain.getDefinition(getQualifiedClassName(e.target.content)));
            this._mc = new c();
           
            this.addChild(this._mc);
        }
   
    }
}

I would like to know what's causing the warning message, am I doing something wrong?

Migrate ActionScript 1.0 To ActionScript 2.0 , Part 1: The Basics
This is an article discussion thread for discussing the SitePoint article, "Migrate ActionScript 1.0 to ActionScript 2.0 , Part 1: The Basics"

Actionscript - User Input Actionscript
I am trying to develop a way where by a users input can determine the number of fields in a form e.g. the user inputs the number 3 then the form would have 3 fields

can you show me or point me in the direction of an example i can look at and manipulate?

[F8] Flash6 Actionscript 2, Flash 8 Actionscript 2...help
Ok loosing it a bit now, have gone back to a very old project from a Flash 6 file, managed to convert the script language to ActionScript2, works fine as flash6 actionscript2, but once I change the project to be flash 8 I get One error......and I know where it's coming from (see below), Have come to a dead - end here, so hope that one of you guys may be able to help me....

Feel free to use this if you can get it working, just credit the designer (Me).

On the main stage MC named "site", go inside and double click on any of the MC's (named "str0, or str1 etc....all instances). Once inside an "str" MC move to frame 2 and the MC on the stage should be called "seg0 or seg1 etc...(again all instances"), go inside the MC and click on frame 1 of the actions layer. Scroll down and look for the variable named "var nummer = _parent.plus+Number(this._name.substr(3, 1));"....this always returns NaN in flash player 8, but works in flash player 6?.................help me.....I'm drowning.

link to files:
http://www.solidvision.co.uk/dev/help.zip

Moving A Game From Actionscript 1.0 To Actionscript 2.0...
Hi there.

I hope someone can help me out here. I have been asked to create a simple Flash memory game, and I have been given a template to use as a basis. However, this template has been created in Actionscript 1.0 for Flash player 5. I now need to transfer it over to Actionscript 2.0 Flash player 8, and Ive noticed lots of odd behaviour once it has been changed.

Here is the code....


Code:
initGame();
stop();
function initGame() {
// make sorted list of cards
cardsListOrdered = [];
for (i=1; i<=18; i++) {
cardsListOrdered.push(i, i);
}
// shuffle list
cardsListSorted = [];
while (cardsListOrdered.length>0) {
r = int(Math.random()*cardsListOrdered.length);
cardsListSorted.push(cardsListOrdered[r]);
cardsListOrdered.splice(r, 1);
}
// create card clips and assign their location and picture
x = 0;
y = 0;
for (i=0; i<36; i++) {
attachMovie("Card", "Card"+i, i);
_root["Card"+i].picture = cardsListSorted[i];
_root["Card"+i]._x = x*60+200;
_root["Card"+i]._y = y*60+50;
// move to next card spot
x++;
if (x>5) {
x = 0;
y++;
}
}
firstclip = 0;
}
function clickCard(clip) {
// see if two card are showing
if (secondclip != 0) {
// turn those two cards back over
firstclip.enabled = true;
secondclip.enabled = true;
firstclip.gotoAndStop(1);
secondclip.gotoAndStop(1);
firstclip = 0;
secondclip = 0;
}
// see if same card was clicked
if (firstclip == clip) {
// turn card back over
firstclip.gotoAndStop(1);
firstclip = 0;
// see if no cards are showing
} else if (firstclip == 0) {
// turn first card over
clip.gotoAndStop(clip.picture+1);
firstclip = clip;
firstclip.enabled = false;
// must be one card showing
} else {
// turn second card over
clip.gotoAndStop(clip.picture+1);
secondclip = clip;
secondclip.enabled = false;
// see if two cards match
if (firstclip.picture == secondclip.picture) {
// Disable both cards
firstclip.enabled = false;
secondclip.enabled = false;
firstclip = 0;
secondclip = 0;
}
}
}
When set to FlashPlayer5, all works well. If a player tries clicking the same tile twice, it stops them. Also, when a pair of tiles are uncovered, again, the user is no-longer able to press them. This was done using the "enabled = false".

However, when I change it to Flash Player 8, none of these seems to work. Ill include the .fla so someone could possibly play around with it and see where the problem is, or whether there is another way to do it....

Hope someone can help.
Many thanks

Convert Actionscript Flash 5 To Actionscript 2.0
any one can tell me how to convert actionscript flash 5 to actionscript 2.0??? anythings i need to take note? i reallynew in actionscript 2.0...please help me.. thanks a lot

Swf Actionscript 3, Load A Actionscript 2 File.
Hey dudes.

I need some help over here:
i have one banner player, and load some external swf files in actionscript 2, but the player is actionscript 3.

The files is loaded like a movie, when load a as2 files into as3. I just need a trigger when the swf file ends, when is in the last frame of movie.

Someone have a ideia in how do that?

thanks!

Flash ActionScript == Flex ActionScript?
Is ActionScript basically programmed the same way for Flash as it is for Flex? I know some folks who develop in AS for Flex. I didn't know if it was exactly the same for Flash, so I could tap them as a resource when I have an AS question.

Thanks,
Loren

Urgent :Getting Actionscript To 'pause' - Actionscript 2.0
Hi guys,

I need the actionscript to carry out a piece of code, then pause for 0.5 seconds, then carry out the next piece of code, then pause, then next code e.t.c

There will be twenty pieces of code that build up an animation with tweens that need to start at different times.

I guess its something to do with setInterval, but I'm not sure on the syntax, as there 20 pieces of code I don't want lots of nested code (though if thats the only way to do it then so be it!)

I'd really appreciate your help guys

cheers

Obtaining An ActionScript 2 Variable From ActionScript 3
Probably one of the most subjects on this forum has to be ActionScript 3 and ActionScript 2 communication. I found several threads on how to communicate between the two using a LocalConnection class, but there is one problem with this approach - I can't transport any values with it. Because LocationConnection.send doesn't have a return type, there is no way to transport a value from AS2 to AS3. This is very unfortunate, as I need to have access to a value that is set somewhere in the AS2 code.

I could use JavaScript as a middle layer to communicate the data between the two, but this will be a very ineffective way to achieve it. Are there any better ways for doing this?

ActionScript 3.0 Is 5~7 Times Slower Then ActionScript 2.0
I have a code that will translate this XML
quote:
<?xml version='1.0'?>
<Member>
<M>
<Username>Test 1</Username>
<Password>Test 1 Password</Password>
</M>
<M>
<Username>Test 2</Username>
<Password>Test 2 Password</Password>
</M>
<M>
<Username>Test 3</Username>
<Password>Test 3 Password</Password>
</M>
</Member>
Into this array
quote:
Array[0].Username = "Test 1"
Array[0].Password = "Test 1 Password"
Array[1].Username = "Test 2"
Array[1].Password = "Test 2 Password"
Array[2].Username = "Test 3"
Array[2].Password = "Test 3 Password"


Here is my variable declaration
quote:
var StartTime:Number = getTimer();
var EndTime:Number = getTimer();
var j:Number = 0;//This Variables used for ActionScript 3.0 Loop
var k:Number = 0;//This Variables used for ActionScript 3.0 Loop


Here is the XML String
quote:
var MyXMLString:String = "<?xml version='1.0'?><member><O><member_id>1</member_id><currency_id>0</currency_id><name>Administrator</name><description>Account Administrator</description><contact>-</contact><billing_info>-</billing_info><opening_payable>0.0000000000</opening_payable><opening_receivable>0.0000000000</opening_receivable><type>STAFF</type><asset_chart_of_account_id>0</asset_chart_of_account_id><liability_chart_of_account_id>0</liability_chart_of_account_id><staff_username>administrator</staff_username><staff_password>21232f297a57a5a743894a0e4a801fc3</staff_password><staff_privileges>ADMIN</staff_privileges></O><O><member_id>1</member_id><currency_id>0</currency_id><name>Administrator</name><description>Account Administrator</description><contact>-</contact><billing_info>-</billing_info><opening_payable>0.0000000000</opening_payable><opening_receivable>0.0000000000</opening_receivable><type>STAFF</type><asset_chart_of_account_id>0</asset_chart_of_account_id><liability_chart_of_account_id>0</liability_chart_of_account_id><staff_username>administrator</staff_username><staff_password>21232f297a57a5a743894a0e4a801fc3</staff_password><staff_privileges>ADMIN</staff_privileges></O><O><member_id>1</member_id><currency_id>0</currency_id><name>Administrator</name><description>Account Administrator</description><contact>-</contact><billing_info>-</billing_info><opening_payable>0.0000000000</opening_payable><opening_receivable>0.0000000000</opening_receivable><type>STAFF</type><asset_chart_of_account_id>0</asset_chart_of_account_id><liability_chart_of_account_id>0</liability_chart_of_account_id><staff_username>administrator</staff_username><staff_password>21232f297a57a5a743894a0e4a801fc3</staff_password><staff_privileges>ADMIN</staff_privileges></O></member>";
var MyXML:XML = new XML(MyXMLString);//Parse the XML ONCE


I have a function called ConvertXML , and to check the performance i made it loop every frame by calling the following RunXML function
quote:
function RunXML(Events:Event){
StartTime = getTimer();
for(var i:Number=0;i<100;i++){
var MyXMLArr:Array = ConvertXML(MyXML, false, false);
}
EndTime = getTimer();
trace(EndTime - StartTime + " ms");
}


and here is my code for parsing the variable MyXML in ActionScript 3.0 (ConvertXML function)
quote:
//Action Script 3.0 ConvertXML
import flash.xml.*;
function ConvertXML(RecvXML:XML, ChildBranch:Boolean, IsTable:Boolean):Array {
var RowArr:Array = new Array();
for (j=0; j<RecvXML.child("*").length(); j++) {
var TempObject = new Object();
for (k=0; k<RecvXML.child("*")[j].elements("*").length(); k++) {
TempObject[RecvXML.child("*")[j].elements("*")[k].name()] = RecvXML.child("*")[j].elements("*")[k];
}
RowArr.push(TempObject);
}
return RowArr;
}
addEventListener(Event.ENTER_FRAME, RunXML);


The code above run 5~7 times slower then the following actionscript 2.0 code
quote:
//Action Script 2.0 ConvertXML
function ConvertXML(RecvXML:XML, ChildBranch:Boolean, IsTable:Boolean):Array {
var RowArr:Array = new Array();
for (var aNode:XMLNode = RecvXML.firstChild.firstChild; aNode != null; aNode=aNode.nextSibling) {
var TempRecord:Object = new Object();
for (var bNode:XMLNode = aNode.firstChild; bNode != null; bNode=bNode.nextSibling) {
TempRecord[bNode.nodeName] = bNode.firstChild.toString();
}
RowArr.push(TempRecord);
}
return RowArr;
}
this.onEnterFrame = RunXML;


they both does exactly the same thing.. and yet the actionscript 3.0 code run 5~7 TIMES SLOWER . why?
i have tried other benchmark, and it seems that actionscript 3.0 perform 10 to 100 TIMES FASTER then actionscript 2.0 , only for this one it run slower... why?

I also attach all the code for actionscript 3.0
should you want to try the actionscript 2.0 , just uncomment the ConvertXML and this.onEnterFrame for actionscript 2.0 and comment the one for actionscript 3.0


Why? have i done something wrong?


Cheers and God Bless,

Chowi








Attach Code

var StartTime:Number = getTimer();
var EndTime:Number = getTimer();
var MyXMLString:String = "<?xml version='1.0'?><member><O><member_id>1</member_id><currency_id>0</currency_id><name>Administrator</name><description>Account Administrator</description><contact>-</contact><billing_info>-</billing_info><opening_payable>0.0000000000</opening_payable><opening_receivable>0.0000000000</opening_receivable><type>STAFF</type><asset_chart_of_account_id>0</asset_chart_of_account_id><liability_chart_of_account_id>0</liability_chart_of_account_id><staff_username>administrator</staff_username><staff_password>21232f297a57a5a743894a0e4a801fc3</staff_password><staff_privileges>ADMIN</staff_privileges></O><O><member_id>1</member_id><currency_id>0</currency_id><name>Administrator</name><description>Account Administrator</description><contact>-</contact><billing_info>-</billing_info><opening_payable>0.0000000000</opening_payable><opening_receivable>0.0000000000</opening_receivable><type>STAFF</type><asset_chart_of_account_id>0</asset_chart_of_account_id><liability_chart_of_account_id>0</liability_chart_of_account_id><staff_username>administrator</staff_username><staff_password>21232f297a57a5a743894a0e4a801fc3</staff_password><staff_privileges>ADMIN</staff_privileges></O><O><member_id>1</member_id><currency_id>0</currency_id><name>Administrator</name><description>Account Administrator</description><contact>-</contact><billing_info>-</billing_info><opening_payable>0.0000000000</opening_payable><opening_receivable>0.0000000000</opening_receivable><type>STAFF</type><asset_chart_of_account_id>0</asset_chart_of_account_id><liability_chart_of_account_id>0</liability_chart_of_account_id><staff_username>administrator</staff_username><staff_password>21232f297a57a5a743894a0e4a801fc3</staff_password><staff_privileges>ADMIN</staff_privileges></O></member>";
var MyXML:XML = new XML(MyXMLString);//Parse the XML ONCE
var j:Number = 0;//This Variables used for ActionScript 3.0 Loop
var k:Number = 0;//This Variables used for ActionScript 3.0 Loop
/*
//Action Script 2.0 ConvertXML
function ConvertXML(RecvXML:XML, ChildBranch:Boolean, IsTable:Boolean):Array {
var RowArr:Array = new Array();
for (var aNode:XMLNode = RecvXML.firstChild.firstChild; aNode != null; aNode=aNode.nextSibling) {
var TempRecord:Object = new Object();
for (var bNode:XMLNode = aNode.firstChild; bNode != null; bNode=bNode.nextSibling) {
TempRecord[bNode.nodeName] = bNode.firstChild.toString();
}
RowArr.push(TempRecord);
}
return RowArr;
}
this.onEnterFrame = RunXML;
*/

//Action Script 3.0 ConvertXML
import flash.xml.*;
function ConvertXML(RecvXML:XML, ChildBranch:Boolean, IsTable:Boolean):Array {
var RowArr:Array = new Array();
for (j=0; j<RecvXML.child("*").length(); j++) {
var TempObject = new Object();
for (k=0; k<RecvXML.child("*")[j].elements("*").length(); k++) {
TempObject[RecvXML.child("*")[j].elements("*")[k].name()] = RecvXML.child("*")[j].elements("*")[k];
}
RowArr.push(TempObject);
}
return RowArr;
}
addEventListener(Event.ENTER_FRAME, RunXML);


function RunXML(Events:Event){
StartTime = getTimer();
for(var i:Number=0;i<100;i++){
var MyXMLArr:Array = ConvertXML(MyXML, false, false);
}
EndTime = getTimer();
trace(EndTime - StartTime + " ms");
}

























Edited: 10/09/2008 at 12:17:57 AM by M4G1C14N

URGENT How Do I Get Actionscript To Pause Actionscript 2.0
Hi guys,

sorry to repost, I know its an annoying thing to do, but this is pretty urgent on a project I'm doing.

I need the actionscript to carry out a piece of code, then pause for 0.5 seconds, then carry out the next piece of code, then pause, then next code e.t.c

There will be twenty pieces of code that build up an animation with tweens that need to start at different times.

I guess its something to do with setInterval, but I'm not sure on the syntax, as there 20 pieces of code I don't want lots of nested code (though if thats the only way to do it then so be it!)

I'd really appreciate your help guys

cheers

Help: This Works In Actionscript 1 But I Need It To Work In Actionscript 2
I have some scrolling navigation that works when published using actionscript 1 but not actionscript 2. I need to use actionscript 2 because it supports the streaming video that I'm trying to navigate. Can someone help me rewrite my button logic to get the scroll bar to work as it did in actionscript 1? Please see my fla if necessary, but here is the area I need help with.

if (Number((getProperty("../scrollhandle", _y)))>Number((Number(../:top)+Number((../:speed/(../:height/../:scrolllength)))))) {
setProperty("../scrollhandle", _y, (getProperty("../scrollhandle", _y)-(../:speed/(../:height/../:scrolllength))));
} else {
setProperty("../scrollhandle", _y, ../:top);
}
tellTarget ("../scrollhandle") {
gotoAndPlay(3);
}

the error that I get is:

**Error** Symbol=buttonlogic, layer=Layer 1, frame=2:Line 1: Operator '>' must be followed by an operand
if (Number((getProperty("../scrollhandle", _y)))>Number((Number(../:top)+Number((../:speed/(../:height/../:scrolllength)))))) {

**Error** Symbol=buttonlogic, layer=Layer 1, frame=2:Line 2: Operator '-' must be followed by an operand
setProperty("../scrollhandle", _y, (getProperty("../scrollhandle", _y)-(../:speed/(../:height/../:scrolllength))));

**Error** Symbol=buttonlogic, layer=Layer 1, frame=2:Line 4: Unexpected '.' encountered
setProperty("../scrollhandle", _y, ../:top);

Please help if you can.

Actionscript 3 Tutorials For Actionscript Beginners
hey all, looking for some tutorials on actionscript 3 for people who are relatively new to actionscript altogether? Finding loads of tutorials but they seem to expect u to already have a grasp of actionscript 2!!

cheers in advance!

Actionscript 1.0 Include Files In Actionscript 2.0
Am I able to include files that were written in actionscript 1.0 in a application that is written in actionscript 2.0?



Works In Actionscript 1.0, Not Actionscript 2.0, Help?
Any idea why this would work fine in Flash MX but not MX 2004 Pro? I'm new to the upgrade but I can't imagine why this doesn't work.

_root.mission.gotoAndStop("mission");

I'm publishing in Actionscript 1.0 so I don't see what the difference would be.

Thank you much!

Converting ActionScript 1 To ActionScript 2
Flash keeps giving me a "type mismatch" error for this particular line of code:
myItemArray[x] = parseInt(Math.random()*9) + myItemArray[x];
Based on my research it's because it's old script and I'm not sure how to go about converting it so I don't get the error. I've pasted the entire block of code for your understanding. Thanks in advance for you help.

Code:
//Build array
myItemArray = new Array("a1","a2","a3","a4","a5","a6","b1","b2","b3" ,"b4","b5","b6");
for(var x = 0; x < 12; x++){
myItemArray[x] = parseInt(Math.random()*9) + myItemArray[x];
}
//Sort array
myItemArray.sort();
//Strip off random num at beginning
for (var x = 0; x < 12; x++){
myItemArray[x] = myItemArray[x].substr(1,myItemArray[x].length);
}

Works On ActionScript 1.0 But Not On ActionScript 2.0
The following code works if you have your flash file set to:
Flash Player 6
Action Script 1

I need it to work for
Flash Player 7
Action Script 2

What it does is that basically if i have
1 2 3 4 5
and i click on the 5 it will arrange the movie clips so they will be
5 1 2 3 4

mc is the name for action script of the movie clip i'm using

I think
the function that doesn't work correctly is the move function

HOW CAN I FIX THIS Sad

Code:
var acceleration = 12;
var friction = 0.7;
clipArray = [];
posArray = [];
for (var k = 0; k<5; k++) {
myclip = attachMovie("mc", "mc"+k, k);
myclip._y = 100;
myclip._x = 170+myclip._width*k;
//myclip.myText.text = "Button "+k;
clipArray.push(myclip);
//countArray.push(k);
posArray.push(myclip._x);
myclip.onPress = dostuff;
}
function move() {
var xdif = posArray[this.jvar]-this._x;
this.xspeed += xdif/this._parent.acceleration;
this.xspeed *= this._parent.friction;
this._x += this.xspeed;
this.checkDistance();

}
checkDistance = function () {
if (Math.abs(posArray[this.jvar]-this._x)<1) {
this._x = posArray[this.jvar];
delete this.onEnterFrame;
}
};
function dostuff() {
for (var i = 0; i<clipArray.length; i++) {
// setting indexes
clipArray[i].ivar = i;;
}
// deleting the mc the user clicked
k = clipArray.splice(this.ivar, 1);

// the mc you click is on the front
clipArray = k.concat(clipArray);

for (var j = 0; j<posArray.length; j++) {
// re setting the indexes
clipArray[j].jvar = j;
trace(clipArray[j]+" "+clipArray[j].jvar);
// calls move
clipArray[j].onEnterFrame = move;
}
}

The Difference Between Actionscript 1 And Actionscript 2?
What's the difference between Actionscript 1 and Actionscript 2? was actionscript 1 used in earlier versions of flash like flash 5?

ActionScript 1.0 To ActionScript 2.0 Converter
Guys i need an extansion or anything that converts my actionscript 1.0 script to actionscript 2.0 . anything ? software application anything ? plz reply . thanks

Actionscript 2.0 Convert To Actionscript 3.0
Hello Everyone,

I have the code below which was created for Actionscript 2.0... I was hoping someone could help me convert to Actionscript 3.0.

If there is anyone that could help me out I would greatly appreciate it.

Thanks,
Alan


var mouse_control:Boolean = true;

var speed:Number = 0;

var mouse_force:Number = 100;

map_color_mc.gotoAndStop("1");
var stop_motion:Boolean = false;
var front_map_position:Number = front_map_mc._x=0;
var reverse_map_postion:Number = reverse_map_mc._x=0;
var centerX:Number = Stage.width/2;
point_mc.duplicateMovieClip("point_mc2", -16367);
point_mc2._x = point_mc._width;
point_mc2._y = point_mc._y;
this.onEnterFrame = function() {
if (stop_motion == false) {
if (mouse_control) {
speed = ((_xmouse-centerX)/mouse_force);
}
front_map_position += speed;
reverse_map_postion -= speed;
if (front_map_position>0) {
front_map_position = -(front_map_mc._width/2);
}
if (front_map_position<(front_map_mc._width/2)*-1) {
front_map_position = 0;
}
if (reverse_map_postion>0) {
reverse_map_postion = -(reverse_map_mc._width/2);
}
if (reverse_map_postion<(reverse_map_mc._width/2)*-1) {
reverse_map_postion = 0;
}
point_mc._x = front_map_mc._x=front_map_position;
point_mc2._x = point_mc._x+point_mc._width;
reverse_map_mc._x = reverse_map_postion;
}
};
globe_hit_mc.onRollOver = function() {
if (mouse_control == false) {
stop_motion = true;
}
};
globe_hit_mc.onRollOut = function() {
if (mouse_control == false) {
stop_motion = false;
}
};

Importing Actionscript Into Actionscript
I've got a game and I've got too much actionscript.
So I'm wondering if it's posible to import an external actionscript file into the code on the maibn SWF file.
This would also give the user a chance to edit basic vaiables, eg. speed, jumpHeight etc.

Any ideas?

Set Movieclips's Actionscript Using Actionscript
Right now, I have a button that attaches a movie clip. However, I need to attach some code to the movie clip, once it's been added. How would I do that?
Edit: Otherwise, would there be any way to automaticly attach it to any movie clip sharing the same instance name?

Actionscript 2.0 &#8594; Actionscript 3.0
Hi,

Since I'm no expert in it, it took me time to get used to some Actionscript 2.0 codes. Now I'm trying to work on Actionscript 3.0, but I don't know that much about it. I have a script that I want to convert from 2.0 to 3.0. Here it is:


ActionScript Code:
g_list.addItem({label:"Wikipedia", data:"Wikipedia"});
g_list.addItem({label:"Yahoo", data:"Yahoo"});
var listHandler:Object = new Object();
listHandler.change = function(ntt:Object) {
    switch (ntt.target.selectedItem.data) {
    case "Wikipedia" :
        getURL ("http://www.wikipedia.org");
        break;
    case "Yahoo" :
        getURL ("http://www.yahoo.com");
        break;
    default :
        trace("unhandled event: "+ntt.target.selectedItem.data);
        break;
    }
};
g_list.addEventListener("change", listHandler);

Can anyone help me, please?

Migrate Actionscript 3 To Actionscript 2
Hello,

I have a problem migrating from AS3 to AS2.

I have the following code:

class Main extends MovieClip {
var g1:Graph;
function Main() {
g1 = new Graph(); // I create a new instance on Graph
addChild(g1); //add it to this movieclip
g1.startup(); //in startup I add several instances on Elem to g1
}
function updateElems()
{
for(var i:Number = 0; i < g1.numChildren; i++)//I iterate through childrens to update them
{
var elem:Elem = g1.getChildAt(i) as Elem;
elem.update();
}
}
}

I create an AS3 project and associate the stage to the Main class that adds a child - g1 - of type Graph using addChild(), then I add several Elem instances to Graph using addChild().

While running I need to update the Elem instances so I iterate through g1's children of type Elem, using getChildAt(i=0, numChildren).

I need to port this to AS2

In AS2
- there's no fl.core.UIComponent (I've used mx.core.UIComponent)
- mx.core.UIComponent doesn't have getChildAt and addChild methods

The questions are:
a) how can I add Main class to stage as I cannot link it from the user interface as this feature is only supported with as3?
b) how can I add g1 to Main?
c) how can I add instances of Elem to g1
c) how can I iterate through the children of g1, the Elem instances and update them?

Thanks!

Can You Have One Actionscript 3.0 Work With Actionscript 2.0?
Hi
I am creating a scrollbar with dynamic text in actionscript 3.00 for my website but all my other swf's are actionscript 2.0 is there anyway I can make them work together?
thanks
matt

Actionscript 3 Support Actionscript 2?
Hi
I would want to ask whether if currently, all the object, functions, classes in actionscript 2 can be rewritten in actionscript 3?
E.g (its just an example), actionscript 2 have Math class, and actionscript 3 also has Math class??

Hope everyone here can understand what I mean. Thanks.

Works On ActionScript 1.0 But Not On ActionScript 2.0
The following code works if you have your flash file set to:
Flash Player 6
Action Script 1

I need it to work for
Flash Player 7
Action Script 2

What it does is that basically if i have
1 2 3 4 5
and i click on the 5 it will arrange the movie clips so they will be
5 1 2 3 4

mc is the name for action script of the movie clip i'm using

I think
the function that doesn't work correctly is the move function

var acceleration = 12;
var friction = 0.7;
clipArray = [];
posArray = [];
for (var k = 0; k<5; k++) {
myclip = attachMovie("mc", "mc"+k, k);
myclip._y = 100;
myclip._x = 170+myclip._width*k;
//myclip.myText.text = "Button "+k;
clipArray.push(myclip);
//countArray.push(k);
posArray.push(myclip._x);
myclip.onPress = dostuff;
}
function move() {
var xdif = posArray[this.jvar]-this._x;
this.xspeed += xdif/this._parent.acceleration;
this.xspeed *= this._parent.friction;
this._x += this.xspeed;
this.checkDistance();

}
checkDistance = function () {
if (Math.abs(posArray[this.jvar]-this._x)<1) {
this._x = posArray[this.jvar];
delete this.onEnterFrame;
}
};
function dostuff() {
for (var i = 0; i<clipArray.length; i++) {
// setting indexes
clipArray[i].ivar = i;;
}
// deleting the mc the user clicked
k = clipArray.splice(this.ivar, 1);

// the mc you click is on the front
clipArray = k.concat(clipArray);

for (var j = 0; j<posArray.length; j++) {
// re setting the indexes
clipArray[j].jvar = j;
trace(clipArray[j]+" "+clipArray[j].jvar);
// calls move
clipArray[j].onEnterFrame = move;
}
}

ActionScript 2.0 To ActionScript 1.0 Using Flash 8
Hi there, I've a contact form with input fields, but, in some area of this form I've placed a combobox drop down menu, wich is a component, I'm using flash 8, so everything was working fine untill my client saids he needs that working in Actionscript 1.0 and the movie published for the flash player version 6, in my button I've this code

on (release) {
Enquiry = (comboBox1.getSelectedItem().label);
_root.test.text = este;
gotoAndPlay("gracias");
this.loadVariables("contacts.php", "POST");
}

thing here is because of the player version update now my dropdown menu is not working, just wondering if somebody can help me with this?

Thanks a lot!!


Arturo

Actionscript 1.0 To Actionscript 2.0 Conversion, Help
Hi guys,
Straight to the point. I found this skewing prototype in laco tweener web. And it was in actionscript 1.0 can u convert this code so its compatible with flash8 & actionscript 2.0 please? I can't seem to know what's wrong in here that I cant play it in as2.
------------------------------------------------------------------------------
var mp = MovieClip.prototype;
mp.setXskew = function(value) {
var _xskew = value;
//this._xskew = value;
//
var _yskew = this._yskew;
// add properties to movieclip
if (!this.inner_mc) {
// defines inner_mc clip needed to skew
for (var clips in this) {
if (typeof (this[clips]) == "movieclip") {
this.inner_mc = this[clips];
// finds first movieclip and uses it to skew
break;
}
}
if (!this.inner_mc) {
return trace("No interior clip for skewing found in "+this._name+".");
// error if inner not found
} else {
this.inner_mc._rotation = -45;
}
// assure clip is rotated -45 degrees
}
var toRads = Math.PI/180;
// converts degrees to radians
var xr = _xskew*toRads;
// skew in radians
var yr = _yskew*toRads;
var cosxr = Math.cos(xr);
// cosine of skew
var cosyr = Math.cos(yr);
this._rotation = 45+(_xskew+_yskew)/2;
// rotate this clip accordingly
var div = Math.sin(this._rotation*toRads)*.707106781186547;
//div: divisor - sin rotation *sin 45 degrees;
if (!div) {
div = .0000001;
}
// prevents dividing by 0 which you just... cant... do
this._xscale = 100*(Math.sin(yr)+cosxr)/div;
// scaling for skew
this._yscale = 100*(Math.sin(xr)+cosyr)/div;
this.inner_mc._yscale = this.inner_mc._xscale=50/cosyr;
// scaling inner to maintain width/height
// = base_yscale*.5/cosxr;
};
ASSetPropFlags(mp, "setXskew", 1, 0);
//
mp.getXskew = function() {
return this._xskew;
};
ASSetPropFlags(mp, "getXskew", 1, 0);
//
mp.setYskew = function(value) {
var _xskew = this._xskew;
//
var _yskew = value;
//this._yskew = value;
// add properties to movieclip
if (!this.inner_mc) {
// defines inner_mc clip needed to skew
for (var clips in this) {
if (typeof (this[clips]) == "movieclip") {
this.inner_mc = this[clips];
// finds first movieclip and uses it to skew
break;
}
}
if (!this.inner_mc) {
return trace("No interior clip for skewing found in "+this._name+".");
// error if inner not found
} else {
this.inner_mc._rotation = -45;
}
// assure clip is rotated -45 degrees
}
var toRads = Math.PI/180;
// converts degrees to radians
var xr = _xskew*toRads;
// skew in radians
var yr = _yskew*toRads;
var cosxr = Math.cos(xr);
// cosine of skew
var cosyr = Math.cos(yr);
this._rotation = 45+(_xskew+_yskew)/2;
// rotate this clip accordingly
var div = Math.sin(this._rotation*toRads)*.707106781186547;
//div: divisor - sin rotation *sin 45 degrees;
if (!div) {
div = .0000001;
}
// prevents dividing by 0 which you just... cant... do
this._xscale = 100*(Math.sin(yr)+cosxr)/div;
// scaling for skew
this._yscale = 100*(Math.sin(xr)+cosyr)/div;
this.inner_mc._yscale = this.inner_mc._xscale=50/cosxr;
// scaling inner to maintain width/height
//
};
ASSetPropFlags(mp, "setYskew", 1, 0);
//
mp.getYskew = function() {
return this._yskew;
};
ASSetPropFlags(mp, "getYskew", 1, 0);
//
mp.addProperty("_xskew", mp.getXskew, mp.setXskew);
ASSetPropFlags(mp, "_xskew", 1, 0);
mp.addProperty("_yskew", mp.getYskew, mp.setYskew);
ASSetPropFlags(mp, "_yskew", 1, 0);
delete mp;

------------------------------------------------------------------------------

and here's the code for the press button.
#include "lmc_tween.as"
//
skew_btn.onPress = function() {
squares_mc_xskew = random(180);
squares_mc.tween("_xskew", squares_mc_xskew, 1, 'easeInOut');
//
squares_mc_yskew = 180;
squares_mc.tween("_yskew", squares_mc_yskew, 1);
};

------------------------------------------------------------------------------

Thanks in advance!

Works On ActionScript 1.0 But Not On ActionScript 2.0
The following code works if you have your flash file set to:
Flash Player 6
Action Script 1

I need it to work for
Flash Player 7
Action Script 2

What it does is that basically if i have
1 2 3 4 5
and i click on the 5 it will arrange the movie clips so they will be
5 1 2 3 4

mc is the name for action script of the movie clip i'm using

I think
the function that doesn't work correctly is the move function

var acceleration = 12;
var friction = 0.7;
clipArray = [];
posArray = [];
for (var k = 0; k<5; k++) {
myclip = attachMovie("mc", "mc"+k, k);
myclip._y = 100;
myclip._x = 170+myclip._width*k;
//myclip.myText.text = "Button "+k;
clipArray.push(myclip);
//countArray.push(k);
posArray.push(myclip._x);
myclip.onPress = dostuff;
}
function move() {
var xdif = posArray[this.jvar]-this._x;
this.xspeed += xdif/this._parent.acceleration;
this.xspeed *= this._parent.friction;
this._x += this.xspeed;
this.checkDistance();

}
checkDistance = function () {
if (Math.abs(posArray[this.jvar]-this._x)<1) {
this._x = posArray[this.jvar];
delete this.onEnterFrame;
}
};
function dostuff() {
for (var i = 0; i<clipArray.length; i++) {
// setting indexes
clipArray[i].ivar = i;;
}
// deleting the mc the user clicked
k = clipArray.splice(this.ivar, 1);

// the mc you click is on the front
clipArray = k.concat(clipArray);

for (var j = 0; j<posArray.length; j++) {
// re setting the indexes
clipArray[j].jvar = j;
trace(clipArray[j]+" "+clipArray[j].jvar);
// calls move
clipArray[j].onEnterFrame = move;
}
}

Works On ActionScript 1.0 But Not On ActionScript 2.0
The following code works if you have your flash file set to:
Flash Player 6
Action Script 1

I need it to work for
Flash Player 7
Action Script 2

What it does is that basically if i have
1 2 3 4 5
and i click on the 5 it will arrange the movie clips so they will be
5 1 2 3 4

mc is the name for action script of the movie clip i'm using

I think
the function that doesn't work correctly is the move function

var acceleration = 12;
var friction = 0.7;
clipArray = [];
posArray = [];
for (var k = 0; k<5; k++) {
myclip = attachMovie("mc", "mc"+k, k);
myclip._y = 100;
myclip._x = 170+myclip._width*k;
//myclip.myText.text = "Button "+k;
clipArray.push(myclip);
//countArray.push(k);
posArray.push(myclip._x);
myclip.onPress = dostuff;
}
function move() {
var xdif = posArray[this.jvar]-this._x;
this.xspeed += xdif/this._parent.acceleration;
this.xspeed *= this._parent.friction;
this._x += this.xspeed;
this.checkDistance();

}
checkDistance = function () {
if (Math.abs(posArray[this.jvar]-this._x)<1) {
this._x = posArray[this.jvar];
delete this.onEnterFrame;
}
};
function dostuff() {
for (var i = 0; i<clipArray.length; i++) {
// setting indexes
clipArray[i].ivar = i;;
}
// deleting the mc the user clicked
k = clipArray.splice(this.ivar, 1);

// the mc you click is on the front
clipArray = k.concat(clipArray);

for (var j = 0; j<posArray.length; j++) {
// re setting the indexes
clipArray[j].jvar = j;
trace(clipArray[j]+" "+clipArray[j].jvar);
// calls move
clipArray[j].onEnterFrame = move;
}
}

Converting Actionscript 1.0 To Actionscript 2.0
Last edited by funkyflash : 2006-01-18 at 11:06.
























This code goes in Frame 1:

ActionScript Code:
//          script by Jae Young, Choi
//            on Designers Forum (corea)
 
Movieclip.prototype.elasticScale = function(target, accel, convert) {
    xScale = xScale * accel + (target - this._xscale) * convert
    yScale = yScale * accel + (target - this._yscale) * convert
    this._xscale += xScale
    this._yscale += yScale
}


This code goes on the movieClip:


ActionScript Code:
onClipEvent (enterFrame) {
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
        elasticScale(150, .75, 0.1)
        trace ("x=" + xscale)
        trace ("x2=" + (target - this._xscale))
    } else {
        elasticScale(100, .75, 0.1)
        trace ("x=" + xscale)      
        trace ("x2=" + (target - this._xscale))
    }
}

ActionScript 2.0 To ActionScript 3.0 Migration
Here's a Livedoc published by MM giving an overview of the differences between 2.0 and 3.0. This is geared as a reference for Flex 2.0, but I would assume that this would apply as well to anyone who's going to be jumping into 3.0 with Flash.

Big and exciting changes. ActionScript is really shaping up to be a serious platform language. Long live Flash!

http://livedocs.macromedia.com/labs/...migration.html

Actionscript 1.0 To Actionscript 2.0 Problem
ok my problem may or may no be something you guys can help me with... i downloaded a preloader tutorial from actionscript.org and i love the preloader but the problem is it doesn't work with actionscript 2.0 or at least that's what i think is the case. as it is right now i can't figure out any other reason other then the fact that it was created on flash mx and i use mx 2004. the reason i think it's a difference between AS 1.0 and 2.0 is that when i just transfer my documents and everything directly into the tutorial page, format it to the same size and everything, the preloader works but the easing code i use doesn't, and if i'm not mistaken that's something for AS 2.0. is there a way i can convert the script over? i'm not sure how to do it really if anyone knows can you help? here it is:

ActionScript Code:
onClipEvent (enterFrame) {
    loading = _parent.getBytesLoaded();
    total = _parent.getBytesTotal();
    percent -= (percent-((loading/total)*100))*.25;
    per = int(percent);
    percentage = per+"%";
    loadBar._width = per;
    if (percent>99) {
        _parent.gotoAndPlay(2);
    }
}

[CS3] Needs Help Converting Simple Flash 5 Actionscript 1.0 To Flash 8 Actionscript 2
Hi, can anyone help me convert this code to actionscript 2.0
I will separate it into the frames its on.

Frame 1
i = 1;
max = 60;
x = getProperty("fire", _x);

Frame 2
if (Number(i)<=Number(max)) {
duplicateMovieClip("fire", "fire" add i, i);
i = Number(i)+1;
}

Frame 3
if (Number(i)<=Number(max)) {
duplicateMovieClip("fire", "fire" add i, i);
i = Number(i)+1;
}
gotoAndPlay(2);

Thanks i appreciate any help

Actionscript To Javascript ..any Actionscript Hero Or Javascript Guru?
Hi..everybody..

i just like to know..if anyone could tell me is it possible to pass a variable from actionscript to javascript ?
eg.
password = inputName
login = login
boolean gate == fales;

if (password == "temp" && login =="login"){
answer = "Access granted!" ;
getURL("temp.html",_self);

} else {
answer = "Access denied!" ;
}

because my login page was made in flash..however, after i found out that user could type in url direct access to the web, i made a redirect meta tag ,redirect that web to login page..however, its does work out..because those 2 pages are not passing login success to another...>__<
thanks you..

anythingokay

Flash 8 V. Flash MX 2004, ActionScript, Actionscript 3
I have a question:

Could someone explain the material differences between Flash 8 and Flash MX 2004, ActionScript and ActionScript 3?

Can Flash 8 ($699 retail version) do everything that the other three can do?

Thank you very much for your time and response.

Actionscript 2 Localconnection Talking To Actionscript 3 Localconnection
We have a whole site written using LocalConnection in AS 3, however, one of our managers wants us to use a component that was written in AS 2 for a menu bar. Is it possible to have the AS2 menu utilize LocalConnection to trigger functions in our AS 3 LC listener?

Copyright © 2005-08 www.BigResource.com, All rights reserved