jeudi 31 décembre 2015

Starling for IOS - Can't load files packaged in ipa when packaging for app store

I have an app for iphone created that I created using Starling.

At runtime, from my main SWF, I'm loading external SWFs which were packaged in the ipa.

Whenever I package the app for testing / debuging, it works great, the SWFs are loaded with no problems.

However, whenever I package it for App Store, suddenly trying to load external SWFs results in an error.

I compared the contents of the testing / debugging and app store ipas (opened as zips), both contain the external SWFs I'm trying to load in the exact same path.

Any idea what's going on?

Is it not possible to get the arguments array from a static method?

I'm trying to get the reserved keyword arguments array from inside a static method and I'm getting this error:

1042: The this keyword can not be used in static methods. It can only be used in instance methods, function closures, and global code.

Here is my code:

public static function doSomething(message:String, ...Arguments):void {
    var object:Object = this.arguments.caller;
}

If I take the this keyword out then I get the following error:

1120: Access of undefined property arguments.

Is it possible to get the class or class name from inside a function?

I'm trying to write debugging tools and I would like to be able to get the class name of the caller. Basically, caller ID.

So if I have a method like so, I want to get the class name:

public function doSomething():void {
   var object:String = argument.caller.this;
   trace(object); // [Class MyClass]
}

public class MyClass {

   public function method1 {
       doSomething();
   }
}

Is there anything like this in JavaScript or ActionScript3? FYI AS3 is based on and in most cases interchangeable with JS.

Play different animation on every other rollover?

I have a couple of buttons which have corresponding movieclips. Every movieclip has two different animations (first starts at frame 1, second on frame 20). I want the animations to play alternating on MOUSE.OVER

Now I am wondering how to do this with one function. Buttons are always named e.g thing and movieclips thing_mc.

I was thinking something like this:

var thing_bo:Boolean = false;

function over(e:MouseEvent)
{
    var mcName = e.currentTarget.name + "_mc";
    var yourContainer:DisplayObjectContainer = e.currentTarget.parent as DisplayObjectContainer;
    var mc = yourContainer.getChildByName( mcName );

    var boName = e.currentTarget.name + "_bo";

    if (!boName) {
        mc.gotoAndPlay(1);
        boName = true; 
    } else {
        mc.gotoAndPlay(20);
        boName = false; 
    }
}

How to I get this to work? Is there a simpler way?

AS3 - How to properly stop player with hitTestObject and restrict player's movement based on colliding area?

I've got a player that has to stop moving on when colliding, but only based on the x/y area of the object. While it touches the left/right sides of the bounding box, it should still be able to move up and down. While it touches the top/bottom sides of the bounding box, it should be able to move side to side.

However I have two issues, the player can glitch through the object when pressing the keys multiple times and both the player's x and y movement would stop once touching any side of the object.

My movement code inside player's class enterframe:

private function onEnterFrame(event: Event): void
{
    _vx = 0;
    _vy = 0;

    if (isRight)
    {
        _vx = 5;
    }
    if (isLeft)
    {
        _vx = -5;
    }
    if (!isJumping && isUp)
    {
        _vy = -5;
    }
    if (!isJumping && isDown)
    {
        _vy = 5;
    }

    x += _vx;
    y += _vy;
}

My hitTestObject code in base class enterframe

private function onEnterFrame(event: Event): void
{
    if (MovieClip(parent).player.collisionArea.hitTestObject(this))
    {
        if (MovieClip(parent).player.isLeft)
        {
            MovieClip(parent).player.x -= MovieClip(parent).player._vx;
        }
        if (MovieClip(parent).player.isRight)
        {
            MovieClip(parent).player.x -= MovieClip(parent).player._vx;
        }
        if (MovieClip(parent).player.isUp)
        {
            MovieClip(parent).player.y -= MovieClip(parent).player._vy;
        }
        if (MovieClip(parent).player.isDown)
        {
            MovieClip(parent).player.y -= MovieClip(parent).player._vy;
        }
    }
}

However, I think my tactic of movement and collision may be incorrect.

FLA file: http://ift.tt/1YR6T7K

The FLA file includes a player and a bed for it to collide with.

AS3 method return vs getter return

I understand how both work, and the idea that using getters is the standard or "correct" way of returning objects - but what exactly is the difference? As far as I'm aware, both of the following methods do the exact same thing with an extra word - "get" - added to one of them:

public function object():Object
{
    return _object;
}

public function get object():Object
{
    return _object;
}

Is there any memory/processing differences or anything that would impact the speed or performance of Flash and, if so, can anybody provide benchmarks? Alternatively, is there anything else I should know about this?

Apologies if this has been posted before, I literally can't find anything on the matter and, although both work, I'd like to know if there is any differences I should be aware of.

mercredi 30 décembre 2015

Flash cs6 AS3 1119 error, undefined property READY through a reference with static type Class. What should I do?

I need help. How to I fix the problem? I use Flash CS6 and AS3. Please Help me to fix it, and thanks a lot! God bless you. Happy New Year!

Output: Symbol 'cinematography_mc', Layer 'AS3', Frame 1, Line 31 1119: Access of possibly undefined property READY through a reference with static type Class.

import fl.video.*;
import flash.events.MouseEvent;
import flash.sampler.pauseSampling;

var flvPlayer:FLVPlayback = new FLVPlayback();
addChild(flvPlayer);
flash.events.Event.MOUSE_LEAVE;
if(!stage.hasEventListener("Leave"))
{
stage.addEventListener("Leave", __onLeaveThis);
}

function __onLeaveThis(e : Event) : void
{
myVideo.stop();
 }
 //The next line assumes you have copied the skin file to the directory
 //that contains the published SWF file. If you are testing the 
 //application in Flash Professional, this is the same directory as the
 //FLA file, too.


function readyHandler(event:VideoEvent):void
{
// Pause until the video can play till the end
myVideo.pause();
myVideo.playWhenEnoughDownloaded();
}

myVideo.addEventListener(VideoEvent.READY, readyHandler);

var mybtn:Array = new      Array(Movie1_btn,Movie2_btn,Movie3_btn,Movie4_btn,Movie5_btn,Movie6_btn,Movie    7_btn,Movie8_btn,Movie9_btn);
for (var i=0; i<mybtn.length; i++)
{
mybtn[i].addEventListener(MouseEvent.CLICK,clickhandler);
function clickhandler(event:MouseEvent):void
{

    if (event.target == Movie1_btn)
    {
        myVideo.source = "1_Bad Water Sequence.mov";
    }
    else if (event.target==Movie2_btn)
    {
        myVideo.source = "2_Nat Geo Clips_Red Wolf Docu.mp4";
    }
    else if (event.target==Movie3_btn)
    {
        myVideo.source = "3_News_Anthrax_Postal Story.mov";
    }
    else if (event.target==Movie4_btn)
    {
        myVideo.source = "4_Energy Ducumentary 2 min Clip.mov";
    }
    else if (event.target==Movie5_btn)
    {
        myVideo.source = "5_Wildlife_Scenic_Reel.mov";
    }
    else if (event.target==Movie6_btn)
    {
        myVideo.source = "6_Intro Title Sequence for Mt.Rushmore    Webcasts.mov";
    }
    else if (event.target==Movie7_btn)
    {
        myVideo.source = "7_PowWow Ancestry Dream Sequence.mov";
    }
    else if (event.target==Movie8_btn)
    {
        myVideo.source = "8_Fence Fixin-Western style-L.mov";
    }
    else if (event.target==Movie9_btn)
    {
        myVideo.source = "9_Docu_3 separate Clips.mov";
        }
        myVideo.stop()
    }
 }
stop();

Flash: Function is triggered more than once

I am trying to make a little blackjack game. I ran in to a problem, ant I cant find my mistake. When you want an extra card the first round, you get one card. (You have to press a button to get it), but in the second round, when you click the button the function triggers twice, in the third round 3 times and so on. Between the rounds I remove everything from screen.

Here is the function that trigger to often:

function extracard() {
                    var cextra: int = drawcard(cardpos, 400, true);
                    trace("drew extra card");
                    if (cextra == 1) {
                        var valchooser3: _1or11 = new _1or11();
                        addChild(valchooser3);
                        valchooser3.one.addEventListener(MouseEvent.CLICK, choose3_1);
                        valchooser3.eleven.addEventListener(MouseEvent.CLICK, choose3_11);
                        valchooser3.x = 280;
                        valchooser3.y = 380;
                        //chipsandcardonscreen.push(valchooser3);
                        function choose3_1() {
                            valchooser3.one.removeEventListener(MouseEvent.CLICK, choose3_1);
                            removeChild(valchooser3);
                        }
                        function choose3_11() {
                            valchooser3.eleven.removeEventListener(MouseEvent.CLICK, choose3_11);
                            playerpoints += 10;
                            trace(playerpoints);
                            removeChild(valchooser3);
                        }
                    }
                    cardpos += 150;
                    playerpoints += cextra;
                }

The drawcard function:

    function drawcard(xpos: int, ypos: int, faceup: Boolean): int {
            var rand: int = Math.floor(Math.random() * shoe.length);
            var newcard: Karte = shoe[rand];
            addChild(newcard);
            trace("aktuelle Karte:" + getChildAt(numChildren - 1).name);
            trace("draw:" + numChildren);
            newcard.x = xpos;
            newcard.y = ypos;
            if (!faceup) {
                toturn.push(newcard);
                newcard.turncard();
            } 
            shoe.splice(rand, 1);
            return newcard.getcardval();
            if (shoe.length <= 0) {
                trace("shoe empty");
                realshoe.gotoAndStop(2);
            }

And the remove everything function

            function realreset() { 

            canBet = true;

            while (numChildren != 0) {
                removeChild(getChildAt(0));
            } 
            startsinglegame();
        }

Does anyone know a solution?

Thanks!

AS3- Trying to flip a MovieClip horizontally, but it's children won't flip properly?

There is a level one MovieClip that contains a player. There are a separate MovieClip that is contained inside the player MovieClip which is the "arms" for the player. The player flips horizontally, but the MovieClip children such as the 'arms" inside the player will not flip horizontally.

In the level one class I put:

if (mouseX > player.x)
{
    player.scaleX = 1;
    crosshair.x = mouseX;
}
else if (mouseX < player.x)
{
    player.scaleX = -1;
    crosshair.x = mouseX;
}

I added a download to my files because it's a bit hard to explain. The code is located in PageOne.as.

http://ift.tt/1PnemDD

addChild() issue: error 2007 on AS3

I have this piece of code that's suppose to add a swf file (homePage.swf) inside my main file (skeleton.fla).

var mcHome:MovieClip;



var newPage: Loader = new Loader();
newPage.load(new URLRequest("homePage.swf"));

newPage.contentLoaderInfo.addEventListener(Event.COMPLETE, homeLoaded);


function homeLoaded(event:Event): void {
    mcHome = MovieClip (newPage.contentLoaderInfo.content);
    newPage.contentLoaderInfo.removeEventListener(Event.COMPLETE, homeLoaded);
    addChild(mcHome);

}

I keep getting this error:

TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/addChild()
    at skeleton_fla::MainTimeline/homeLoaded()

I don't know how to solve it, or what to change!

Help please, I'm a bit desperate.

change movie clip when click to other movie clip, Actionscript 3

I want to change rat_mc MovieClip into a new MovieClip when rat_mc is beaten, for example by another MovieClip. How can I do it?

import flash.events.Event;

hammerMC.startDrag(true);

var allHoles:Array = new Array(hole1_mc, hole2_mc, hole3_mc);
rat_mc.visible = false;

var num_count:Number = 0;
var rat_mc:MovieClip;
addChild(rat_mc);
rat_mc.buttonMode = true;
var txt_score:TextField;

function showRat(e:Event):void {

var rand = Math.floor(Math.random() * 3);
var randomHole = allHoles[rand];

rat_mc.visible = true;
rat_mc.x = randomHole.x;
rat_mc.y = randomHole.y;

}

rat_mc.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(e:MouseEvent):void {
txt_score.text = String (num_count += 10);
} 

enter image description here

Capturing ctrl + click in Flash actionscript3

I would love to know if it is possible to listen for 2 simultaneous events in Flash such a keyboard press and mouse click e.g ctrl click to perform an action?

ERRORS 1009 & 2007 in AS3

I'm doing a website with Flash. The main page is a skeleton, with a top bar (with the links to different sections) and footer (with links to other websites).

I have issues trying to load the other sections (swf files) inside this main skeleton. When I try I get both errors, 1009 and 2007. I cannot see the problem.

This is the code:

var mcHome: MovieClip;

    var load: Loader = new Loader();
    load.contentLoaderInfo.addEventListener(Event.COMPLETE, homeLoaded);
    load.load(new URLRequest("homePage.swf"));


    function homeLoaded(e: Event): void {
        mcHome = MovieClip(load.contentLoaderInfo.content);
        load.contentLoaderInfo.removeEventListener(Event.COMPLETE, homeLoaded);
        addChild(mcHome);
        mcHome.x = 9;
        mcHome.y = 208;
    }

        //DESIGNERS BUTTON

        des_menu.addEventListener(MouseEvent.CLICK, designersLoaded);
        function designersLoaded(event:MouseEvent):void 

{
            mcHome = MovieClip(load.contentLoaderInfo.content);
            load.load(new URLRequest("designersJ.swf"));
            removeChild(mcHome);
            addChild(mcHome);
            mcHome.x = 9;
            mcHome.y = 208;
        }


    (...)

Can someone help?

ActionScript - Load url content - angularjs

I need to load a URL (below) in my panel Flex but angularjs is not loading.

What is the solution?

<s:Panel id="panelHtml" x="0" y="22" width="100%" height="95%" enabled="false">
    <mx:HTML id="content" location="http://ift.tt/1mhtER1"
    width="100%" height="100%"
    visible="true" 
    verticalScrollPolicy="auto" horizontalScrollPolicy="auto"
    complete="content_completeHandler(event)"
    locationChange="content_locationChangeHandler(event)"/>
</s:Panel>

as3 - How to sort display objects that constantly switch depths?

I have a 2.5D game (2D game that acts like a 3D game) where you constantly switch depths, where the player displays on top of an object when it walks in front of it and when it walks behind it, the object displays on top of the player. Like when the player's y is less than the object's y, the player would be going behind the object and vice versa.

I tried to use a code like this:

if (player.y < block.y)
{
    setChildIndex(block, numChildren - 5);
}
else if (player.y > block.y)
{
    setChildIndex(block, numChildren - 10);
}

However, I see if I do it this way with multiple times, I would need tons of codes and the display list would get mixed up and sort the wrong depths in the wrong orders. Would anyone please show an organized depth changer with minimal code?

Error 1119 : Access of possibly undefined property x through a reference with static type model:PlayerModel

I'm usually developping in Java but I need to do something in AIR (AS3), but I'm struggling with something that seems really stupid :

package model {
    import view.PlayerView;

    public class PlayerModel extends BasicModel implements UpdatableModel{

        private var view:PlayerView;

        public function PlayerModel(game:Game, initX:Number, initY:Number) {
            super(game, initX, initY);
            this.view = new PlayerView();
            this.game.addChild(this.view);
            this.view.x = initX;
            this.view.y = initY;
        }

        public function update() {
            if(view != null) {
                this.view.updatePosition(this.body.position.x, this.body.position.y);
            }
        }

    }

}

It doesn't want to compile with the error :

Line 13 1119: Access of possibly undefined property x through a reference with static type model:PlayerModel. Line 14 1119: Access of possibly undefined property y through a reference with static type model:PlayerModel.

I'm using Flash Pro CS5.5 and I auto-generated the Class PlayerView.as through the MovieClip (Export for ActionScript).

package view {

    import flash.display.MovieClip;


    public class PlayerView extends MovieClip {


        public function PlayerView() {
            super();
        }

        public function updatePosition(newX:Number, newY:Number) {
            this.x = newX;
            this.y = newY;
        }

        public function idle(){
            this.gotoAndStop("Idle");
        }

        public function walk(){
            this.gotoAndStop("Walking");
        }

    }

}

It also seems that I could have an error for the updatePosition method too ...

Thanks

mardi 29 décembre 2015

How to fix a program from having to run as administrator to be able to print in adobe air?

I am having a problem with printing in a adobe air application using the as3 printjob package.

The problem is that the example works 100% as expected until I package the application into a .air file or as a native application. When I do this I can no longer print anything until I right click on the application and run it as administrator.

Is there a way to package the application so it doesn't have to be run as administrator in order for it to be able print? Is there something I should be setting in the mxml file?

Thank you!

How to get value of selected index in combo Box when user select the value from it in flex

Hi I have created a comboBox dynamically and Since I'm new to Flex I have no idea how to get the selected value from combo box when user select a value from combobox dropdown

Below is my code

var comboBox:ComboBox = new ComboBox();
comboBox.dataProvider = field.getValues();
comboBox.width = "50";
comboBox.prompt = "Test";
comboBox.selectedIndex = -1;

Could someone help me out in order to identify how I'll be able to get value of a selected index when user will select the value from dropdown of combo box ?

Even a sample example will help me !!

Thanks in Advance.....!!

FLEX - Load anglularJS URL content

I need to load a URL (below) in my panel Flex but angularjs is not loading.

What is the solution?

<s:Panel id="panelHtml" x="0" y="22" width="100%" height="95%" enabled="false">
    <mx:HTML id="content" location="http://ift.tt/1mhtER1"
    width="100%" height="100%"
    visible="true" 
    verticalScrollPolicy="auto" horizontalScrollPolicy="auto"
    complete="content_completeHandler(event)"
    locationChange="content_locationChangeHandler(event)"/>
</s:Panel>

Can not Get an Image URL When Drag and Drop an Image from IE8 Using "NativeDragEvent" into Flash

I have this code:

this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onNativeDragEnter);

private function onNativeDragEnter(vEvent:NativeDragEvent)
{   
    httpUrl = vEvent.clipboard.getData( ClipboardFormats.URL_FORMAT ) as String;
    var arr:Array = (vEvent.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT)) as Array;

    if(arr != null && arr.length >= 1 || httpUrl != null && httpUrl.length > 3)
    {
        NativeDragManager.acceptDragDrop(this); 
        this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onNativeDragDrop);
    }
    else
    {
        if(vEvent.clipboard.hasFormat(ClipboardFormats.TEXT_FORMAT))
        {
            DragManager.acceptDragDrop(this);
            this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onNativeDragDropForText);
        }
    }

    arr = null;
}

private function onNativeDragDrop(vEvent:NativeDragEvent)
{
    var dropFiles:Array = vEvent.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;

    if(httpUrl == null)
    {
        for(var i=0;i<dropFiles.length;i++)
        {
            var dragDropEvent:MediaManagerEvents = new MediaManagerEvents(MediaManagerEvents.DRAG_DROP_MEDIA);
            dragDropEvent.fileURL = (dropFiles[i] as File).nativePath;
            dispatchEvent(dragDropEvent);
        }
    }
    else 
    {
        var extension = getExtension(httpUrl);
        var scopeCount = getMatchCount(":",httpUrl);
        if (scopeCount <= 1 && ( extension == 'gif' || extension == 'jpg' || extension == 'png' || extension == 'JPEG' || extension == 'jpeg' || extension == 'JPG' || extension == 'PNG' || extension == 'bmp' || extension == 'BMP'))
        {
            var dragDropEvent:MediaManagerEvents = new MediaManagerEvents(MediaManagerEvents.DRAG_DROP_MEDIA);
            dragDropEvent.fileURL = httpUrl;
            dispatchEvent(dragDropEvent);
        }
        else if(dropFiles && dropFiles.length > 0)
        {
            var original:File = File(dropFiles[0]);
            var nativeExtension = getExtension(original.nativePath);

            if(nativeExtension == 'bmp' || nativeExtension == 'BMP'){
                var loader:URLLoader = new URLLoader();         
                loader.dataFormat = URLLoaderDataFormat.BINARY;         
                loader.addEventListener( Event.COMPLETE, onCompleteLoad );          
                loader.load( new URLRequest( original.nativePath ) );
            }
            else{
                var dragDropEvent:MediaManagerEvents = new MediaManagerEvents(MediaManagerEvents.DRAG_DROP_MEDIA);
                dragDropEvent.fileURL = original.nativePath;
                dispatchEvent(dragDropEvent);
            }
        }
    }

    this.removeEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onNativeDragDrop);
    vEvent.clipboard.clear();
    dragDropEvent = null;
    httpUrl = null;
}

My Problem is that When i am dragging and dropping an image from IE8, URL showing NULL(i.e httpUrl = NULL) but in case of Chrome an Firefox it is working fine.

I don't know how to solve.

So I want the solution to work on Internet Explorer8.

why flash/AS3 is deadly?

I have been developed (Adobe AIR)/(flash) more than 5 years until 2014. Learn a lot about programming with using ActionScript 3.0. such as animation,web game,mobile game,video+camera,sound+speaker,stage3D + AGAL(open a new door about programming of graphics rendering for me), etc...

I know that it's so many security bugs in Flash Player,but you can use Adobe AIR on mobile.Easy to meet the performance bottleneck on mobile . But it is easier to do so many thing like multi-platform game(web/iOS/Android Adobe AIR game) than other languages.

But I don't get the point to convince me that why it is disappearing so quickly ?


PS: Don't worry about me. I had moved on and learned a lot of new programming language and zone. such as go+thrift , redis , python django , nginx-lua,openWRT , c , java ssh2(outsource). From frontend to backend,I had a bit comfortable with the lacking of UE by other frontend programer.And the problem of MySQL was more puzzled me.

Does JavaScript in the browser support ByteArrays? [duplicate]

This question already has an answer here:

The ByteArray class provides methods and properties to optimize reading, writing, and working with binary data.

How to use byte arrays tutorial.

I'm looking for a very similar API as the one linked.

Is Loader/unload() a must for garbage collection?

I'm using flash.display.Loader to load an external SWF.

When I'm done with the SWF, is it enough to manually remove all references to the loader and the SWF's content in order to free it for garbage collection? or must I also call Loader/unload()?

AS3 tween object not working with .hitTestObject()

I am having a major problem in my new browser app.

Okay so I made game where different cubes (squares) spawn at the top of the screen and I use the Tween class to make them go down the screen and then disappear.

However I want to detect a collision when a cube hits the player (that is also a flying cube).

I tried everything, truly everything but it does not seem to work. The problematic thing is that when I remove the "Tween" function it does detect collision with the hitTestObject method but when I add the "Tween" line collision won't be detected anymore.

It looks like this:

       function enemiesTimer (e:TimerEvent):void
  {
      newEnemy = new Enemy1();
      layer2.addChild(newEnemy);
      newEnemy.x = Math.random() * 700;
      newEnemy.y = 10;

      if (enemiesThere == 0)
      {
          enemiesThere = true;
          player.addEventListener(Event.ENTER_FRAME, collisionDetection)
      }



      var Tween1:Tween = new Tween(newEnemy, "y", null, newEnemy.y, newEnemy.y+distance, movingTime, true);
  }

And the collision detection part:

private function collisionDetection (e:Event):void
  {


      if (player.hitTestObject(newEnemy))
      {
          trace("aaa");
      }






  }

I am desperate for some information/help on the topic, it's been bugging me for days.

Thanks for your time, I would be very happy if someone could help me out^^

missing child bullet to spaceship as3

the thing i don't get is i got a symbol called ray that is the bullet for my spaceship and i don't get the bullet on stage when space is triggerd could someone help me with this? and as you can see i write in 1 class so if you know a possible way to let my spaceship shoot a ray in the y.as that would be great.

package {

import flash.display.MovieClip;
import flash.events.*
import flash.ui.Keyboard;

public class SpaceInvaders extends MovieClip {
    var left: Boolean;
    var right: Boolean;
    var shoot: Boolean;
    var upKey: Boolean;
    var downKey: Boolean;
    var player: Player;
    var ray: Ray;

    public function SpaceInvaders() {
        player = new Player();
        ray = new Ray();
        spawn();
        fireSpawn();
        left = false;
        right = false;
        shoot = false;
        upKey = false;
        downKey = false;

        stage.addEventListener(Event.ENTER_FRAME, update);
        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
        stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
    }

    public function spawn() {
        trace("ree");
        player.x = 95;
        player.y = 200;
        this.stage.addChild(player);



    }
    public function fireSpawn(players) {
        trace("fireshoot");

    }


    public function update(e: Event) {
        if (left) {
            player.x -= 10;
            trace("left");
        }
        if (right) {
            player.x += 10;
            trace("right");
        }
        if (shoot) {
            addChild(ray);
            trace("shoot");
        }
        if (upKey) {
            player.y += 10;
            trace("up");
        }
        if (downKey) {
            player.y -= 10;
            trace("down")
        }
    }
    public function keyDownHandler(event: KeyboardEvent): void {
        switch (event.keyCode) {
            case Keyboard.LEFT:
                left = true;
                break;

            case Keyboard.RIGHT:
                right = true;
                break;

            case Keyboard.SPACE:
                shoot = true;
                break;
            case Keyboard.UP:
                upKey = true;
                 break;
            case Keyboard.DOWN:
                downKey = true;
                break;
            default:
                break;
        }
    }

    public function keyUpHandler(event: KeyboardEvent): void {
        switch (event.keyCode) {
            case Keyboard.LEFT:
                left = false;
                break;

            case Keyboard.RIGHT:
                right = false;
                break;

            case Keyboard.SPACE:
                shoot = false;
                break;

            case Keyboard.UP:
                upKey = false;
                break;

            case Keyboard.DOWN:
                downKey = false;
                break;

            default:
                break;
        }
    }
}

}

AS3: Moving the registration point of a container rotated in 3D space

I have a simple function that takes a container sprite with one child object and moves the registration point to the bottom right corner, with the child seemingly staying in place. But if the container sprite has a rotationX, rotationY, or rotationZ, the child object appears to change position slightly when the function is called. How can I do this while making the child appear to not change position?

function BR(s:Sprite):void {
    var dO:DisplayObject = s.getChildAt(0);
    s.x += dO.x + dO.width;
    s.y += dO.y + dO.height;
    dO.x = -dO.width;
    dO.y = -dO.height;
}

how to display name and score in as3

I have a quiz in flash as3. I want to save the name and score from user when they try my quiz. If user end the quiz, I want to display the name and the score from user before. I think to use mySQL and PHP, but I don't sure it will works in another PC without internet. Can anybody help me?

Toggling Full Screen view on Key press in Flash via Actionscript3

Below is my code aimed at getting my flash content to toggle between full screen view and normal view on press of the spacebar key, so far no compiler errors yet does not work.

import flash.events.KeyboardEvent;

stage.addEventListener (KeyboardEvent.KEY_DOWN, toggleScreenview);
function toggleScreenview(e:KeyboardEvent):void {
    if (e.keyCode == Keyboard.SPACE){
        stage.displayState = StageDisplayState.FULL_SCREEN;
    } else {
    stage.displayState = StageDisplayState.NORMAL;
    }
}

Is a big code embedded into the first frame of root on Flash considered a bad practice?

I am planning to create a game with the help of Flash CS3/AS3. This game will feature too many functions and lots of code. A 30-seconds demo alone I've been making here already has 5,000 lines of code, and will only get bigger and bigger as I make progress.

I'm planning on separating snippets of this code into separate as files, so I can embed them on the timeline using the include function, but before I proceed, I need to know: Is this considered a bad practice?

I mean, there will be a point in development where the code will become so huge, it might threaten the game's stability, or am I just paranoid and this is a perfectly normal way to address this issue. Pasting all the important functionality on the timeline and being done with it?

Copy an Image and Text together to Clipboard, using ActionScipt?

Is there any way to copy an Image and some relevant text (Like a Description to the image, added programatically), so that these can be pasted together (On some application like Excel; outside the Flex Application).

Copy an Image from Flex Application (Web) and paste it outside the application

I have a requirement that we should be able to copy an image displayed in our application, to Clipboard and paste it outside (Like on Excel).

I was trying the below code snippet.

Clipboard.generalClipboard.clear(); var dataLoaded:Boolean = Clipboard.generalClipboard.setData(ClipboardFormats.RICH_TEXT_FORMAT, event.imageSnapshotByteArray, false);

The dataLoaded object is true, however it does not paste anything when tried on Excel or MsPaint.

Do we have any way to achieve this?

Thanks.

lundi 28 décembre 2015

How to Add Multiple Images to Clipboard in as3 using Flex

I have this code:

                mSelectedWidget = getWidgetsByID( mSelectedWidXML.children()[i].@id ) as DisplayObject;
                mSelectedWidgetXML = (mSelectedWidget as IWidget).getWidgitPropXML();
                var bmpData:BitmapData = new BitmapData(mSelectedWidget.width, mSelectedWidget.height);
                bmpData.draw(mSelectedWidget);
                Clipboard.generalClipboard.setData(ClipboardFormats.BITMAP_FORMAT, bmpData,false);

My Problem is that When i am copying multiple images, it is only copying last image (i.e which is added at last) to the clipboard.

I don't know how to add more than one images to clipboard at a time.

So I want the solution to add multiple images to clipboard.

Anyone got Airxzip with password working on Air for ios/android?

I'm building an app in Flashbuilder and using Airxzip AS3 library to unzip files. The 'set password' feature works fine to read/write on Air for Windows. I can unzip files ok in Air for ios, but get error 'password is not match' when file is encrypted with a password. I'm wondering if anyone has managed to get this working before I start to delve into differences between windows/ios in the airxzip/ZipCrypto.as file. (source can be found here: http://ift.tt/1NMLUbD) Many thanks and Merry Christmas all!

Adding and storing a highscore

I'd like to add a highscore to my android game. I'd like to add it and store for when they return. how do I go about this? Here's the code for the frame I want it on!

lblScore.text = String(score);
gameOver.addEventListener(TouchEvent.TOUCH_TAP, End);
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT; 


function End(event:TouchEvent): void {
    gotoAndPlay(1);
}

stage.removeEventListener(TouchEvent.TOUCH_TAP, End);

function refreshScores():void {
    lblScore.text = String(score);
    score++;
}

Tone Generator converted for specified tones

I was hoping that you could help me figure out how to change this code generator from playing specific tones already designated to keys on the keyboard to using a textbox to specify which frequency of tone to play.

Thank you for your help.

var _sound       :Sound         = null;
var _channel     :SoundChannel  = null;
var _pitchRatios :Object        = null;
const BASE_PTICH :Number        = 440;
var _pitch       :Number        = 5;
var _timer       :Timer         = null;



function SoundGeneration()
{

_pitchRatios = {97:1, 115:1.059, 100:1.122, 102:1.189, 103:1.259, 104:1.334, 106:1.414, 107:1.498, 108:1.587};

_timer = new Timer(9000);
_timer.addEventListener(TimerEvent.TIMER, TimerStop,false, 0, true);

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown, false, 0, true);

stage.focus = this;
}

function KeyDown($e:KeyboardEvent):void
{
if(_timer.running == false) _timer.start();
PlaySound(_pitchRatios[$e.charCode])
}

function PlaySound($pitchRatio:Number):void 
{
StopSound();
_pitch = BASE_PTICH * $pitchRatio;
_sound = new Sound();
_sound.addEventListener(SampleDataEvent.SAMPLE_DATA, SoundGenerator, false, 0, true);
_channel = _sound.play();
}

function SoundGenerator($e:SampleDataEvent):void
{
var $lev:Number;

for (var i:uint = 0; i < 8192; i++) 
{
    $lev = 0;
    $lev += Math.sin((i + $e.position) * Math.PI / (44100 / _pitch ));
    $lev /= 2;
    $e.data.writeFloat($lev);
    $e.data.writeFloat($lev);
}
}

function TimerStop($e:TimerEvent):void
{
if(_timer.running) _timer.stop();

}

function StopSound():void 
{
if (_channel) 
{
    _channel.stop();
    _sound.removeEventListener(SampleDataEvent.SAMPLE_DATA,SoundGenerator);
}
}

SoundGeneration();

Getting a button to shuffle through the timeline

How do I get the play head to consecutively go through the timeline containing objects in 4 frames on the click of a button using actionscript 3

Adobe Air Update Framework Number

Dear Stackoverflow readers,

I am trying to use the update frame work for an Adobe Air Application. There are some links on this site and Adobe's but they seem a bit dated, and I am not sure how to proceed.

Background for the problem

I am using Flash CC 2015 to build an a test app. Its version is 1.0 I am trying to implement the update functionality so that when users open the app, the app checks for any updates, then updates if that is the case

What I did

Added the updater swc file to my AS settings

My xml update file has the following information

<?xml version="1.0" encoding="utf-8"?>

<update xmlns="http://ift.tt/1YNxVHC">

<versionNumber>2</versionNumber>

<url>/newSoftware/test.air</url>

<description>This is the latest version of the Sample application.</description>

</update> 

The app current version's XML is below

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!-- 
    Usage:

    To localize the description, use the following format for the description element.
    <description>
    <text xml:lang="en">English App description goes here</text>
    <text xml:lang="fr">French App description goes here</text>
    <text xml:lang="ja">Japanese App description goes here</text>
    </description>

    To localize the name, use the following format for the name element.
    <name>
    <text xml:lang="en">English App name goes here</text>
    <text xml:lang="fr">French App name goes here</text>
    <text xml:lang="ja">Japanese App name goes here</text>
    </name>
-->
<application xmlns="http://ift.tt/1WEFl4n">
  <id>test</id>
  <versionNumber>1.0</versionNumber>
  <filename>test</filename>
  <description/>
  <name>test</name>
  <copyright/>
  <initialWindow>
    <content>test.swf</content>
    <systemChrome>standard</systemChrome>
    <transparent>false</transparent>
    <visible>true</visible>
    <fullScreen>false</fullScreen>
    <aspectRatio>portrait</aspectRatio>
    <renderMode>auto</renderMode>
  </initialWindow>
  <icon/>
  <customUpdateUI>false</customUpdateUI>
  <allowBrowserInvocation>false</allowBrowserInvocation>
</application>

Here is the error I get Error ID: 16827. Version mismatch

Looking at the trace results, here is what I get. The app does find the update, downloads the updated file, and then I get the error

[StatusUpdateEvent (type=updateStatus available=true version=2 details=,This is the latest version of the Sample application. versionLabel=2 )]
65536 792601
131072 792601
196608 792601
262144 792601
327680 792601
393216 792601
458752 792601
524288 792601
589824 792601
655360 792601
720896 792601
786432 792601
792601 792601

Again, Sorry for repeating the question. The links I checked seemed dated, or focused on the migration from old air frameworks to new ones. I am using the latest stuff, so I am not sure how to solve this.

Thank you for your help

Spark Button trapping keydown (spaceBar) event

Update: Apparently this is part of the accessibility scheme of Flex Spark Components

Button control Press the Spacebar to activate the Button control. To cancel activating a button, press the Tab key to move the focus off the Button control before releasing the Spacebar.

I guess it can be turned off through compiler directives: Accessibility best practices


Question: Is there any reason a Spark Button would trap key events, in particular a "spacebar" key event?

Background: I've inherited and am maintaining a large legacy project done in Flex 4.6. I am seeing a weird behavior with a Spark Button. Essentially, once the button has been clicked on (i.e. given focus) a keyEvent (spaceBar) will trigger the click event handler attached to the button.

Weird, right?

The button is defined in MXML (below) within an MX:Module. The module has key event listeners attached to the stage but the event handlers for those do nothing with the button:

this.stage.addEventListener(KeyboardEvent.KEY_DOWN, echoKeyDownHandler);
this.stage.addEventListener(KeyboardEvent.KEY_UP, echoKeyUpHandler);

If I put a trace statement in the button's event handler to check the event type when this weird behavior occurs, the type is reported as a click. I don't see anything in the docs for the Spark Button about capturing key events like this.

   <s:Button id="toggleBtn"
     label="Editor" 
     click="toggleBtn_clickHandler(event)" 
      x="943" y="8"/>

Adobe AIR update 20.0 left Native Extension broken

There is an an AIR app which is being maintained, and for the time being, things were alright. Up until Dec. 08 when AIR update 20.0 came in, leaving an error message

"The required native extension is missing for this application. Try re-installing or contacting the publisher for assistance".

A lot of people have been seeing same, so it must be a common problem - that AIR update broke down all native extensions, like:

http://ift.tt/1YJ8DQs http://ift.tt/1JEIZQx

etc. etc.

Is there any definite fix, or all we have to do is to sit and wait for Adobe to issue a fixed version? People suggests downgrading to version 19.0 but it seems impractical for any massively used app, most users will simply give up on it rather than downgrade.

Clean uninstall of Adobe Air application?

I am doing some work with the EncryptedLocalStore and I have noticed that this data remains after the application is uninstalled. I uninstall the application by running the .air installer for the application and selecting the "uninstall" option.

Is this leftover garbage "normal" for an AIR application?

coordinate function mouse down in action script 3

i will make my hammer(movie clip) following cursor and every time I click the mouse / mouse down, the hammer will come down exposed cursor and return to original position. But i just can make the hammer(movie clip) following cursor. How can I do?

hammer.startDrag(true);

adding and removing from the page in ActionScript 3

I am using flash for the first time, I have a set of videos and image galleries, for users who are viewing it, I have created an Exit button so that the users can come out and go back to the menu. How do I go about doing this?

Thanks

as3 - How to access child's child?

I dispatched an event for a bullet to spawn on the page. However the bullet should be located in the area where the page's child child should be. There is a Page One Movieclip, which has a child named "player" and the player's child is "gun". So I'm trying to keep the location and rotation of the bullet the same as the player's gun. So I need to access Page One's child's child. The player and the turret are using instance names and not variables.

I tried this code, but the bullet spawns in the page but will not spawn itself on the turret's location. This event is located in the PageOne class.

function fire(e: Event)
    {
        var b: Bullet = new Bullet();
        b.rotation = player.turret.rotation;
        b.x = player.turret.x + player.turret.width * Math.cos(player.turret.rotation / 180 * Math.PI);
        b.y = player.turret.y + player.turret.width * Math.sin(player.turret.rotation / 180 * Math.PI);
        addChild(b);
    }

Swfloader scale content to full size

I have load swf file to my flex project.
I have used SWFLoader for that to load the swf file.

var loader:SWFLoader = new SWFLoader();
loader.load("player/VideoPlayer.swf");
loader.width = 320;
loader.height = 280;
parentContainer.addElement(loader);

In which parentContainer is <s:BorderContainer. It's width 320 and height 280.

I have also tried to set like following, but didn't got succeeded:

function onComplete(event:Event):void
{
    loader.width = 320;
    loader.height = 280;
}

Problem: But when i run it swf file load to full width and height.
How can i set it's width and height to it's parent container?

Use of dynamic array in ActionScript?

I would like to have a dynamic array depending on values inputted by the user. How can I go about doing that?

Would array1.push(i++) work?

dimanche 27 décembre 2015

Aptana Studio 3 No local history available for selected resource

This problem is happening under OSX 10.11.2 with Aptana Studio 3.6.1 "AS3" After creating a projectFolder and some subfolders with some html/css/js files and did some coding in a different text editor. Started AS3, right click on projectFolder and did Promote to Project, accepted the default with Project Type = Web, edited my.html file and saved it.

In the Project Explorer on my.html, RightClick > Compare With > Local History...
but a pop up window saying "No local history available for selected resource".

Please help me find what I am doing wrong in order to get this functionality to work.

Thanks

Adding sound to a MovieClip event in Adobe Flash

Basically I have this sound effect that id like to add to my movieclip. What happens is when I touch the ball (movieclip) it moves to a new location, speeds up and the score climbs. At the exact point the ball is touched, id like the sound effect to play. Here is the code for my ball touch

    function fl_TapHandler(event:TouchEvent):void {
_touch = true;
timmyTimer.reset();
score +=1;
mcBall.x = Math.floor(Math.random() *(stage.stageWidth - mcBall.width));
mcBall.y = Math.floor(Math.random() *(stage.stageHeight - mcBall.height));
mcBall.nextFrame();
removeChild(mcBall);
timmyTimer.reset();
timmyTimer.start();
updateScores();

}

as3commons generate function call at runtime

For reasons I am generating a class at runtime which has an existing super class with a protected member and implements an existing interface. Each method (and accessor) of the interface needs to get generated, too. The point where I'm struggeling is to fill the method body with the correct opcodes. Here is an example which i want to generate or translate into opcode:

public function myFunction(arg1:String, arg2:int):Boolean
{
    return member.my_namespace::myFunction(arg1, arg2);
}

All Informations are available, like the name of the function, the arguments, the return type and the namespace. And I am able to create the function itself and return a default value, like seen in the as3commons tests/examples

Maybe I should use another lib than as3commons?

Show layers when mouse hovers

I am new to flash and I am creating a set of HTML tutorials. In one, there is a demonstration of the structure of an HTML page, and I want to create an interactive demonstration for it in flash. Here is my unfinished file. With actionscript 3.0, I would like...

  • I would like the 'text' layer to always show.
  • Firstly, both the layers 'head' and 'body' need to show
  • If the user hovers over the 'head', the 'head_text' should come up. When the user's mouse exits the 'head', the 'head_text' should hide.
  • If the user hovers over the 'body', the 'body_text' should come up. When the user's mouse exits the 'body', the 'body_text' should hide.

I hope these instructions are sufficient so you can help me. Many Thanks

Creating boundaries for scrollRect for platformer game as3

Writing a side-scrolling platformer and figured that scrollRect would be best for memory, since it only renders the rectangle and not the entire stage. I have it centering my hero and scrolling with him. My problem is with creating the outer boundaries for the rectangle. if(view.x < 0) is easy. I have the x and y origins locked, it's the other edges where I have problems.It runs on ENTER_FRAME, btw. Here's my code:

    public function ScrollWithHero()
    {
        var stageW2:Number = stage.stageWidth/2;
        var stageH2:Number = stage.stageHeight/2;
        var view:Rectangle = new Rectangle(0,0,stage.stageWidth,stage.stageHeight);

        if(hero.x - stageW2 > 0){ view.x = hero.x - stageW2; }

        if(hero.x + stageW2 > levelWidth){ // stop scrolling the rect }

        if(hero.y - stageH2 > 0){ view.y = hero.y - stageH2; }

        if(hero.y + stageH2 < levelHeight){ // stop scrolling the rect }

        scrollRect = view;
    }

change movie clip when click, Actionscript 3

I want to change rat_mc (movie clip) into a new movie clip when rat_mc (beaten), for example into another movie clip. then, I want to be when rat_mc (movie clip) has appeared 20 times, it will move to frame 3. how can I do?

stop();
import flash.events.Event;

hammerMC.startDrag(true);

var allHoles:Array = new Array(hole1_mc,hole2_mc, hole3_mc);
rat_mc.visible = false;

var myTimer:Timer = new Timer(1000,20);
myTimer.addEventListener(TimerEvent.TIMER, showRat);
myTimer.start();

function showRat(e:Event):void{
var rand = Math.floor(Math.random()*3);
var randomHole = allHoles[rand];

rat_mc.visible = true;
rat_mc.x = randomHole.x;
rat_mc.y = randomHole.y;
}

var num_count:Number=0;
var rat_mc: MovieClip ;

addChild( rat_mc);
rat_mc. buttonMode = true;
rat_mc. addEventListener (MouseEvent. CLICK, clickHandler);

var txt_score: TextField;

function clickHandler(e: MouseEvent):void{
txt_score. text = String (num_count += 10);

} 

import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;

function TimerExample() {
        var myTimer:Timer = new Timer(1000, 2);
        myTimer.addEventListener("timer", timerHandler);
        myTimer.start();
    }

function timerHandler(event:TimerEvent):void {
        trace("timerHandler: " + event);
    }

var secs:Number = 30;
var waktu:Timer = new Timer(1000);

detik_txt.text=""+secs;

waktu.addEventListener(TimerEvent.TIMER,handTimer);
waktu.start();
function handTimer(e:TimerEvent):void{
     if(secs==0){
              waktu.stop();
               gotoAndStop(3);
          }else{
             secs--;
             detik_txt.text=""+secs;
           }
  }

samedi 26 décembre 2015

Starling for IOS & Android: Very low FPS in a static situation

I created an application with Starling, on the new mobile devices it performs amazingly well, however on the older devices (e.g. iPhone 4) I encounter a very odd lag.

I have as far as I can tell a completely static situation:

There are quite a few display objects added to stage, many of them are buttons in case it matters, their properties are not changed at all after initialization (x, y, rotation, etc...). There are no enterframes / timeouts / intervals / requests of any kind in the background. I'm not allocating / deallocating any memory.

In this situation, there's an average of 10 FPS out of 30, which is very odd.

Since Starling is a well established framework, I imagine it's me who's doing something wrong / not understanding something / not aware of something.

Any idea what might be causing it?

Do I need to perhaps manually set some properties to let starling know not to redraw display objects which properties are not changed?

Has anyone else experienced this sort of problem?

vendredi 25 décembre 2015

Unload SWF File in a Same Button that Load the External File to Minimize Loading Time

I have two SWF files. First one is home.swf and the second one is menu.swf. Each SWF file has a button that load external SWF file.

This is the code inside home.swf file:

stop();
menu_btn.addEventListener(MouseEvent.CLICK, func_menu);
function func_menu(e:MouseEvent):void {
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    loader.load(new URLRequest("menu.swf"));
}

function onComplete(e:Event):void {
    var movie:* = LoaderInfo(e.currentTarget).content;
    stage.addChild(movie);
}

This is the code inside menu.swf file:

stop();
home_btn.addEventListener(MouseEvent.CLICK, func_home);
function func_home(e:MouseEvent):void {
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    loader.load(new URLRequest("home.swf"));
}

function onComplete(e:Event):void {
    var movie:* = LoaderInfo(e.currentTarget).content;
    stage.addChild(movie);
}

If I click the buttons numerous times, the SWF files gets longer time to load. I notice that those code doesn't unload files. What code do I need to unload the previous SWF files? I'm new in actionscript. Please go easy on me.

organization of adventure game with Flash AS3

first of all, Merry Christmas to everyone :-)!

I while ago, I started learning flash with AS3. My goal is to create an adventure game. I have had people here helping me and also watched some youtube videos and read some flash beginner sites. I make this question a new thread, because I think it is not a concrete command line question like before, it is more a general question for the basic organization of my game.

This is what I have in mind for the game: Lets say it contains 4 rooms. R1 kitchen, R2 living room, R3 lobby, R4 Bedroom. Goal is to find the mobile phone in the house. There are buttons connecting the rooms. Say in the living room is an arrow on the left side of the screen, when clicking it you will “be” in the kitchen. Classic point and click adventure room escape.

In the bedroom you find a key and put it in your inventory. In the lobby you can use this key with little box. It opens, revealing mobile phone. Pick up mobile phone, go to livingroom, use mobile phone, finish game. Just an example, hope you can follow me.

Now, when asking ppl and reading other manuals on how to create flash applications (like this good one: http://ift.tt/1MBdRFj) I have the impression I should avoid using different SCENES. My first approach was to have each room R1 R2 R3 R4 in a different SCENE with different layers, like background picture layer (picture of a lobby), object layer (little box) and AS3 layer. This is tempting for me, because the Scene and layer interface is very intuitive, feels like using Photoshop.

Anyways, since ppl say “AVOID SCENES,AS3 hates Scenes”, I avoid them now. Now my whole game is in ONE scene. Instead, I want to have each room attached to its own frame: R1 in frame 1, R2 in frame 2…

Then there is two layers which are extended for all scenes: The AS3 layer containing all the AS for the game. And the inventory layer. It works like this: It contains all the items in invisible form. It only covers the area on the bottom of the screen. Example: How do I pick up key in R4 bedroom? There is a keybedroominventory movie clip in the inventory visible = false, in other words invisible and not clickable. But when you are in the bedroom and click on keybedroom movie clip (a little key next to the bed), it triggers keybedroomvisible = false and keybedroominventory = true.

Keep in mind that I am a total beginner. I am only able to do little stuff: I manage to learn the “Press button” command for AS3 somewhere, design a button in an object layer, give it its instance name. Or find the AS3 commands for visible = true. I would like to stay on “photoshop mode” as much as possible, using frames, having different layers and so on. And learn other commands when needed. (Say maybe later I will have some password (text field) in R1, which is found on a paper sheet in R2. Giving me reason to look into that text-field-String-nerd-thing commands) So far I have been able to walk around rooms and click on items.

I still stuggle often with beginner mistakes like mixing up capital letter commands, mixing up ( ) { } ; ; and so on…Therefore using stuff like seven different .as files like document class.as and so on is way to advanced. MY QUESTION: Does that basic “1 room 1 frame” organization make sense? Or is that just replacing SCENES with FRAMES, but the concern from you more experienced programmers are the same?

Adobe AIR opening EXE

Im working in Flash CC using AIR3 and I prepared two AIR applications. I want to know if it is possible to run the second air app from the first app. Simple as I can when you click in App1 on button it would open new window with App2. Both apps are AIR but they have different stage size.

Is it possible to do?

How do I stop function on as3

Well... I try to stop animation that coded on as3, but can't do it. Here the code!

//this make the ground move
function GroundAndEndingMove(event:Event):void
{   
    ground.x = ground.x - 5;
    if (ground.x <= -846.24)
    {
        ground.x = -846.25;
        ending.x = 503.5;
        stop();

    }
    stopmation.x = stopmation.x - 5;
    if (stopmation.x <= -846.24)    
    {
        ground.x = -846.25;
        ending.x = 503.5;
        stop();
    }
    ending.x = ending.x - 5.1;
    if (ending.x <= 503.5)

    {
        rowl.x = 548.1;
        ending.x = 503.5;
        stop();
    }
    trash.x = trash.x - 5.1;
    if (trash.x <= 503.5)
    {   
        trash.x = 503.5;
        ball.x = ball.x + 5.1;
        stop();
    }

}
stage.addEventListener(Event.ENTER_FRAME, GroundAndEndingMove);

//this function make the ball to faled

function GameOver(event:Event):void
{
    if(ball.hitTestObject(ground))
    {
        //here I should stop the animation wherever it be.
    }
    if (ball.hitTestObject(stopmation))
    {
        //also here
    }

}
stage.addEventListener(Event.ENTER_FRAME, GameOver);

What to do? or that you have any better idea.. Help!

(Sorry about any spelling mistake... I made it long ago and I back to it right now..)

as3 load serialize object from java servlet

First, sorry for my english. I was making a simple streaming program. To a first approximation I use a servlet in a server that recover a image from webcam connect it at this, and send the image to an java applet. That works fine, i recover correctly the image and show it into the applet. But the applets not are compatible with android, then, I build a android application that connect to the same servlet and recover a image like response of this, i show it in the mobile screen. Again, works fine. But now, I'm thinking in build a as3 application for not use separately a android application for mobile and a applet for pc users.

The code of my servlet that send the image is this:

response.setContentType("application/x-java-serialized-object");
ObjectOutputStream salida = new ObjectOutputStream(response.getOutputStream());
salida.writeObject(imageInByte);
salida.flush();

where imageInByte is an java byte[]

the code of my as3 project is:

main class:

public class Main extends Sprite {

    public function Main() {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point
        addChild(new WebCam());
    }

}

webcam class:

public class WebCam extends Sprite
{

    private var request:URLRequest = new URLRequest("http://localhost:8080/WebCamToAndroid/Respuesta?action=actualizar");
    private var loader:URLLoader = new URLLoader();

    public function WebCam()
    {
        request.contentType ="application/x-java-serialized-object";

        loader.addEventListener(Event.COMPLETE, completeHandler);
        try {
            loader.dataFormat = URLLoaderDataFormat.BINARY; 
            loader.load(request);
        } catch (error:Error) {

        }
    }

    private function completeHandler(event:Event):void {
        //HE DE TRANSFORMAR EL BYTEARRAY EN IMAGEN
        var bytes:ByteArray = loader.data;
        addChild(new ShowImage(bytes));
    }

}

}

ShowImage class:

public class ShowImage extends Sprite
{
    private var loader:Loader;

    public function ShowImage(bytes:ByteArray=null) 
    {
        loader =new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);

        if(bytes == null){
            loader.load(new URLRequest("http://ift.tt/1mDE3GF"));
        } else {
            loader.loadBytes(bytes)
        }
    }

    public function onImageLoaded(e:Event):void
    {
        addChild(loader);
    }

}

Here it's the problem, I can't see anything, I think that the problem is in as3 application. I was reading into internet looking for a example that could be help me, but any code that I proved help me. What it's the problem? That I was wrong?

Thanks!!!

as3 - movieclip flickers when flipping it horizontally?

When I move my cursor, the player flips from left to right as expected. However, when I keep my cursor still in the middle of the screen (not moving cursor but, instead the player using "WASD" keys), and make my player move towards the cursor and walk past it. Then the player will change scale to horizontal. However, just before it changes scale, the children (player's arms, turret) inside the player flickers to scaleY before changing horizontal scale.

This is my code located inside the container of the player, it's the "PageOne" class.

if (mouseX > player.x)
        {

            player.playerStand.scaleX = 1;
            player.turret.scaleY = 1;
            player.armBottom.scaleY = 1;
            player.armTop.scaleY = 1;
            crosshair.x = mouseX;

        }
        else if (mouseX < player.x)
        {

            player.playerStand.scaleX = -1;
            player.turret.scaleY = -1;
            player.armBottom.scaleY = -1;
            player.armTop.scaleY = -1;
            crosshair.x = mouseX;
        }

So, I am trying to make it so the player's children do not flicker before flipping horizontally and instead instantly change horizontal shape. The movieclip that has ScaleX does not flicker, but the children that use scaleY has this flickering issue. It may be a bit hard to understand by reading so I added a file below.

Here is the file: http://ift.tt/1PnemDD

as3- Trying to flip horizontal but flips in an odd way instead?

There is a level one class that contains a player and it's arms. The arms are a separate movieclip that is contained inside the player movieclip. The player flips horizontally, but the movieclip children inside the player will not flip horizontally.

In the level one class I put:

if (mouseX > player.x)
        {
            player.scaleX = 1;
            crosshair.x = mouseX;
        }
        else if (mouseX < player.x)
        {
            player.scaleX = -1;
            crosshair.x = mouseX;
        }

I added a download to my files because it's a bit hard to explain. The code is located in "PageOne.as".

http://ift.tt/1PnemDD

jeudi 24 décembre 2015

Flash GotoFrame on Keypress

I am trying to figure out some code where when I press one of the 4 arrow keys, flash goes to a certain frame on the timeline. And when none of these keys are being pressed, it will return to its original start point on the timeline. I have seen some examples on this site, but I am struggling with it, especially returning to the original point on the timeline when there are no keypresses.

So for example.

if no keypress gotoandstop (10)
if keypress=UPARROW gotoandstop (20)
if keypress=DOWNARROW gotoandstop (30)
if keypress=LEFTARROW gotoandstop (40)
if keypress=RIGHTARROW gotoandstop (50)

I know thats not code, but its the clearest way I could explain it.

If anyone can help, I would be grateful. Thanks

Adding Blur Filter to The Stage in Flash

Is it possible to add like a "global blur" filter to the stage via actionscript3? Below is my code attempt but it obviously doesn't make sense to Flash

stage.filters = [myBlur];

AS3: Not getting typeError when calling a function

I'm writing my own language from ActionScript as a personal project (yeah, I guess AS3 is not the best language to build a language from, but never mind that).

At any rate, I have a this:

package NodyCode.Classes 
{
    public class NCString 
    {

        public function rindex(substr:NCString, startIndex:int = 0x7fffffff):uint {
            //code here
        }
    }
}

I would like an error to be thrown whenever the user uses the wrong type of argument. So I would expect this code to cause an error:

strInstance.rindex('foo', [5]);

Instead, though, rindex is called with startIndex = 5.

Why is [5] converted to 5, and is there any way for me to prevent that? If there isn't, I can always work around this problem, but I'd rather not if I can do otherwise.

that message: Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed

my code is perfect but i have that message error (Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed). what is the answer ???

var Xposition:Number=0;
var Yposition:Number=95;
var swf:MovieClip;
var loader:Loader=new Loader();


///// load the home page by default /////
var defaultSWF:URLRequest=new URLRequest("home.swf");
loader.load(defaultSWF);
loader.x= Xposition;
loader.y= Yposition;
addChild(loader);

//// button general function ////
function btnClick(event:MouseEvent):void{
removeChild(loader);
var newSWF:URLRequest=new URLRequest(event.target.name+"swf");
loader.load(newSWF);
loader.x= Xposition;
loader.y= Yposition;
addChild(loader);
}

/////// each btn listener //////
home.addEventListener(MouseEvent.CLICK,btnClick);
aboutus.addEventListener(MouseEvent.CLICK,btnClick);
getinvolved.addEventListener(MouseEvent.CLICK,btnClick);
contact.addEventListener(MouseEvent.CLICK,btnClick);

actionscript Storing a value after a button is clicked

I don't program a lot. Sometimes I program a bit of Actionscript 3. Now I wanted to create an flash enviroment where people can click on buttons and play a video. I think I almost figured it out with the following script:

public class main extends MovieClip 
{
    private var drukknop1:knopje;
    private var drukknop2:knopje;
    private var drukknop3:knopje;
    private var drukknop4:knopje;
    private var drukknop5:knopje;
    private var drukknop6:knopje;
    private var drukknop7:knopje;
    private var drukknop8:knopje;
    private var drukknop9:knopje;
    private var drukknop10:knopje;
    private var videoclip:FLVPlayback = new FLVPlayback();
    private var buttonClicked:Number = 0;

    public function main() 
    {
        // plaatsen van buttons on stage
        drukknop1 = new knopje();
        drukknop1.name = "inst_knop1";
        drukknop1.x = 50;
        drukknop1.y = 70;
        addChild(drukknop1);
        drukknop1.buttonMode = true;
        drukknop1.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop1.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

        drukknop2 = new knopje();
        drukknop2.name = "inst_knop2";
        drukknop2.x = 150;
        drukknop2.y = 70;
        addChild(drukknop2);
        drukknop2.buttonMode = true;
        drukknop2.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop2.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

        drukknop3 = new knopje();
        drukknop3.name = "inst_knop3";
        drukknop3.x = 250;
        drukknop3.y = 70;
        addChild(drukknop3);
        drukknop3.buttonMode = true;
        drukknop3.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop3.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

        drukknop4 = new knopje();
        drukknop4.name = "inst_knop4";
        drukknop4.x = 350;
        drukknop4.y = 70;
        addChild(drukknop4);
        drukknop4.buttonMode = true;
        drukknop4.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop4.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

        drukknop5 = new knopje();
        drukknop5.name = "inst_knop5";
        drukknop5.x = 450;
        drukknop5.y = 70;
        addChild(drukknop5);
        drukknop5.buttonMode = true;
        drukknop5.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop5.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

        drukknop6 = new knopje();
        drukknop6.name = "inst_knop6";
        drukknop6.x = 550;
        drukknop6.y = 70;
        addChild(drukknop6);
        drukknop6.buttonMode = true;
        drukknop6.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop6.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

        drukknop7 = new knopje();
        drukknop7.name = "inst_knop7";
        drukknop7.x = 650;
        drukknop7.y = 70;
        addChild(drukknop7);
        drukknop7.buttonMode = true;
        drukknop7.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop7.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

        drukknop8 = new knopje();
        drukknop8.name = "inst_knop8";
        drukknop8.x = 750;
        drukknop8.y = 70;
        addChild(drukknop8);
        drukknop8.buttonMode = true;
        drukknop8.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop8.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

        drukknop9 = new knopje();
        drukknop9.name = "inst_knop9";
        drukknop9.x = 850;
        drukknop9.y = 70;
        addChild(drukknop9);
        drukknop9.buttonMode = true;
        drukknop9.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop9.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

        drukknop10 = new knopje();
        drukknop10.name = "inst_knop10";
        drukknop10.x = 950;
        drukknop10.y = 70;
        addChild(drukknop10);
        drukknop10.buttonMode = true;
        drukknop10.addEventListener(MouseEvent.MOUSE_UP, _flv_component);
        drukknop10.addEventListener(MouseEvent.MOUSE_DOWN, ButtonClicked);

    }
    private function _flv_component(event:MouseEvent):void
    {
        //plaatsen van de video player door drukken op de knop 
        drukknop1.buttonMode = false;
        drukknop1.removeEventListener(MouseEvent.MOUSE_UP, _flv_component);

        videoclip.x = (stage.stageWidth/2)-(videoclip.width/2);
        videoclip.y = (stage.stageHeight/2)-(videoclip.height/2);
        videoclip.width = 640;
        videoclip.height = 400;
        videoclip.autoPlay = true;
        videoclip.skin = "MinimaSilverPlayBackSeekMute.swf";

        if(buttonClicked ==1)
        {videoclip.load("Functieomschrijvingscene.flv");}
        else if(buttonClicked ==2)
        {videoclip.load("2.flv");}
        else if(buttonClicked ==3)
        {videoclip.load("3.flv");}
        else if(buttonClicked ==4)
        {videoclip.load("4.flv");}
        else if(buttonClicked ==5)
        {videoclip.load("5.flv");}
        else if(buttonClicked ==6)
        {videoclip.load("6.flv");}
        else if(buttonClicked ==7)
        {videoclip.load("7.flv");}
        else if(buttonClicked ==8)
        {videoclip.load("8.flv");}
        else if(buttonClicked ==9)
        {videoclip.load("9.flv");}
        else if(buttonClicked ==10)
        {videoclip.load("10.flv");}

        videoclip.play();
        addChild(videoclip);
        videoclip.addEventListener(Event.COMPLETE,videoComplete);
    }
    function videoComplete(event:Event):void
    {
        //Verwijderen van FLVPlayback component
        trace ("video is klaar");
        removeChild(videoclip);
        buttonClicked = 0;
        trace (buttonClicked);

    }
    function ButtonClicked(Event:MouseEvent):void
    {
        trace ("ButtonClicked functie werkt.");
        trace (buttonClicked);

        // het opslaan van een nummer van een button
        if(event.target.name == drukknop1)
        {buttonClicked = 1;}
        else if(event.target.name == drukknop2)
        {buttonClicked = 2;}
        else if(event.target.name == drukknop3)
        {buttonClicked = 3;}
        else if(event.target.name == drukknop4)
        {buttonClicked = 4;}
        else if(event.target.name == drukknop5)
        {buttonClicked = 5;}
        else if(event.target.name == drukknop6)
        {buttonClicked = 6;}
        else if(event.target.name == drukknop7)
        {buttonClicked = 7;}
        else if(event.target.name == drukknop8)
        {buttonClicked = 8;}
        else if(event.target.name == drukknop9)
        {buttonClicked = 9;}
        else if(event.target.name == "inst_knop10")
        {buttonClicked = 10;}
    }
}

}

In the function "ButtonClicked, I want to check which button is clicked. After that I want to store a value in the private var "Buttonclicked" So that based on this number I know which FLV needs to be loaded. But when I export I get an error "Access of Undefined property event". This probably has got to do with my "If" statement in the functions but I have no clue on how to solve this.

Could someone please help me out? I know programming with classes would be much neater, but I have to little experience in this.

Thanks in advance, Harold

Check VideoDisplay video is not null in flex

I have datagrid which contains number of rows which have video data.

<s:DataGrid id="movieGrid" dataProvider="{movieData}" selectionChange="setSource(event)" />

On selection of row get video url and play in VideoDisplay.

private function setSource(event:GridSelectionEvent):void
{
    if(videoDisplay!=null)
    {

        var movie:String = movieGrid.selectedItem.flvLink;
        videoDisplay.source = movie;
     }
}

And on play select it will play the video.

videoDisplay.play();

VideoDisplay:

<s:VideoDisplay id="videoDisplay"  autoPlay="false" />

Now that moveData values come from server request.

Problem:
Above works well but, Some of flvlink are wrong, which does not have videos.
Now i click on that row which have wrong link and again click on right link row then it have error in videodisplay.

TypeError: Error #1009: Cannot access a property or method of a null object reference.

How, can i skip this error. Is there are anyway i can get that link has video file or not. And if not then not apply source to video display?

how to make a score with function mousedown to movie clip actionscript 3

enter image description hereIn my game, I've three holes (MovieClip) and that every time (of 20 times) the rat (MovieClip) to be over one of those holes. i want to to make a score when rat(movie clip) click with function mousedown in actionscript 3. i already to try but error.

 hammerMC.startDrag(true);
 hammerMC.addEventListener(MouseEvent.MOUSE_DOWN, turunpalu);
 function turunpalu (e:Event):void{
   hammerMC.visible = true;
   hammerMC.x = mouseX;
   hammerMC.y = mouseY; 
 }

// the array has all the hole movieclips
var allHoles:Array = new Array(hole1_mc,hole2_mc, hole3_mc);
rat_mc.visible = false;

// show the rat 20 times
var myTimer:Timer = new Timer(1000,20); 
myTimer.addEventListener(TimerEvent.TIMER, showRat);
myTimer.start();

function showRat(e:Event):void{
// choose a random hole
var rand = Math.floor(Math.random()*3);
var randomHole = allHoles[rand];

rat_mc.visible = true;
rat_mc.x = randomHole.x;
rat_mc.y = randomHole.y;
}

Can not Get an Image URL When Drag and Drop an Image from IE8 Using "NativeDragEvent" into Flash

I have this code:

this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onNativeDragEnter);

private function onNativeDragEnter(vEvent:NativeDragEvent) {
httpUrl = vEvent.clipboard.getData( ClipboardFormats.URL_FORMAT ) as String; var arr:Array = (vEvent.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT)) as Array;

        if(arr != null && arr.length >= 1 || httpUrl != null && httpUrl.length > 3)
        {
            NativeDragManager.acceptDragDrop(this); 
            this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onNativeDragDrop);
        }
        else
        {
            if(vEvent.clipboard.hasFormat(ClipboardFormats.TEXT_FORMAT))
            {
                DragManager.acceptDragDrop(this);
                this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onNativeDragDropForText);
            }
        }

        arr = null;
    }

private function onNativeDragDrop(vEvent:NativeDragEvent) { var dropFiles:Array = vEvent.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;

        if(httpUrl == null)
        {
            for(var i=0;i<dropFiles.length;i++)
            {
                var dragDropEvent:MediaManagerEvents = new MediaManagerEvents(MediaManagerEvents.DRAG_DROP_MEDIA);
                dragDropEvent.fileURL = (dropFiles[i] as File).nativePath;
                dispatchEvent(dragDropEvent);
            }
        }
        else 
        {
            var extension = getExtension(httpUrl);
            var scopeCount = getMatchCount(":",httpUrl);
            if (scopeCount <= 1 && ( extension == 'gif' || extension == 'jpg' || extension == 'png' || extension == 'JPEG' || extension == 'jpeg' || extension == 'JPG' || extension == 'PNG' || extension == 'bmp' || extension == 'BMP'))
            {
                var dragDropEvent:MediaManagerEvents = new MediaManagerEvents(MediaManagerEvents.DRAG_DROP_MEDIA);
                dragDropEvent.fileURL = httpUrl;
                dispatchEvent(dragDropEvent);
            }
            else if(dropFiles && dropFiles.length > 0)
            {
                var original:File = File(dropFiles[0]);
                var nativeExtension = getExtension(original.nativePath);

                if(nativeExtension == 'bmp' || nativeExtension == 'BMP'){
                    var loader:URLLoader = new URLLoader();         
                    loader.dataFormat = URLLoaderDataFormat.BINARY;         
                    loader.addEventListener( Event.COMPLETE, onCompleteLoad );          
                    loader.load( new URLRequest( original.nativePath ) );
                }
                else{
                    var dragDropEvent:MediaManagerEvents = new MediaManagerEvents(MediaManagerEvents.DRAG_DROP_MEDIA);
                    dragDropEvent.fileURL = original.nativePath;
                    dispatchEvent(dragDropEvent);
                }
            }
        }

        this.removeEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onNativeDragDrop);
        vEvent.clipboard.clear();
        dragDropEvent = null;
        httpUrl = null;
    }

My Problem is that When i am dragging and dropping an image from IE8, URL showing NULL(i.e httpUrl = NULL) but in case of Chrome an Firefox it is working fine.

I don't know how to solve.

So I want the solution to work on Internet Explorer8.

mercredi 23 décembre 2015

Is it possible to make a connection to a Flash instance in the browser from an AIR app?

Is it possible and how would I make a connection to a Flash instance in the browser from an AIR app running on the desktop?

I'm opening up a browser window to a specific web page where I can add a Flash player instance. I then want to communicate with the browser instance in a one way communication.

Example from AIR app:

  1. var connection = connectToBrowserFlashInstance()
  2. connection.send("updated");

Example code from Flash instance:

  1. addEventListener("messages", messageHandler);
  2. if (message=="updated") then do something

Why onPress function doesn't Work?

Here is my code :

stop();

btn_start.onPress = function() 
gotoAndStop("gameon")

I have An error and it sounds like: "

Access of possibly undefined property onPress through a Reference with static type 
flash.display:SimpleButton.

I converted the text into a Button, I gave him an id, I don't know what to do, don't judge, I'm begginer.

Thanks!

Anyone got Airxzip with password working on Air for ios/android?

I'm building an app in Flashbuilder and using Airxzip AS3 library to unzip files. The 'set password' feature works fine to read/write on Air for Windows. I can unzip files ok in Air for ios, but get error 'password is not match' when file is encrypted with a password. I'm wondering if anyone has managed to get this working before I start to delve into differences between windows/ios in the airxzip/ZipCrypto.as file. (source can be found here: http://ift.tt/1NMLUbD) Many thanks and Merry Christmas all!

How can I correctly position a loaded image in AS3

I am having heaps of problems trying to reposition an image which is loaded to a movieclip using Actionscript. here is what I am trying to do:

for (var i:int=0; i<roleHeadData[pNum].length; i++) {
        var gap = (sWidth/(roleHeadData[pNum].length+1))*(i+1)-sWidth/2;
        var roleBtn:roleBtn_mc = new roleBtn_mc();
        roleBtn.name = "role"+roleHeadData[pNum][i].shortName+"_mc";
        roleBtn.x = gap;
        roleBtn.buttonMode = true;
        rolePane.addChild(roleBtn);
        var imgPath = roleHeadData[pNum][i].imgRef;
        var roleImg = loadMovie(roleBtn.roleImg, imgPath);
        rolePane.roleBtn =  roleBtn;
        roleBtn.text_txt.text = roleHeadData[pNum][i].title;
        roleImg.x = -(roleImg.width/2);
        roleFunc(roleBtn,i, isHome);
    }

The images don't move as there is no width. I am assuming it is because it hasn't loaded yet. For that reason I tried loaders to re-position the items. This didn't work either, as by the time the image is loaded, the var used is no longer available, so only the last item gets re-positioned:

for (var i:int=0; i<roleHeadData[pNum].length; i++) {
        var gap = (sWidth/(roleHeadData[pNum].length+1))*(i+1)-sWidth/2;
        var roleBtn:roleBtn_mc = new roleBtn_mc();
        roleBtn.name = "role"+roleHeadData[pNum][i].shortName+"_mc";
        roleBtn.x = gap;
        roleBtn.buttonMode = true;
        rolePane.addChild(roleBtn);
        var imgPath = roleHeadData[pNum][i].imgRef;
        var roleLoader:Loader;
        roleLoader = new Loader();
        roleLoader.load(new URLRequest(imgPath));
        var roleImg = roleBtn.roleImg;
        roleBtn.roleImg.addChild(roleLoader);
        roleLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void{roleLoaded(roleImg)});
        function roleLoaded(mc):void {
            // Load Image
            mc.x = -(mc.width/2);
        }
    }

Any help would be greatly appreciated.

Removing MC from array AS3

I am having a problem removing a MovieClip from an array.

I am getting the error "TypeError: Error #1009: Cannot access a property or method of a null object reference. at Spiker/loop()".

The spike (Spiker) is getting removed, but the error still annoys me.. Any idea how to fix this?

Thanks

package  {

import flash.display.MovieClip;
import flash.events.Event;

public class Spiker extends MovieClip {

    public var spikeDirection:int = 1;
    private var removed = false;
    public function Spiker() {
        // constructor code
        trace("Spiker added");

        addEventListener(Event.ENTER_FRAME, loop);
    }
    private function loop (evt){
        this.x += spikeDirection * 10;

        for(var i:int = 0; i < this["parent"].enemyList.length; i++){
            if(removed == false){
                if(this["parent"].enemyList[i].hitTestObject(this)){
                    trace("Spikerhit");
                    removed = true;
                    remove(evt);
                }
            }
        }
    }
    public function remove (evt){
        removeEventListener(Event.ENTER_FRAME, loop);
        this["parent"].removeChild(this);
    }

}

Elegant and efficient way to traverse through edges and resolve intersections

I have an array which represents adjacency matrix of a graph like this.

connections:Array = [0,0,1,1,
                     0,0,1,1,
                     0,0,0,1,
                     0,0,0,0];

Every node of the graph has a 2D point assigned to it which represents its position on a plane. I am trying to write a function which traverses through all the edges and returns false if any of the two edges intersect. Here is my code

function test():boolean
{
    for (i = 0; i < nodes.length ; i++)
    {
        for (j = i ; j < nodes.length ; j ++)
        {
            if (connections[i * nodes.length + j] == 1)
            {
                //we found an edge
                //This is the place where i am stuck I, can't figure out how
                //to take pairs of edges to test them for intersections
            }
        }
    }
}

You can give the answer in any language or even pseudo code.

Note: I don't need any code for intersection algorithm.

Tilemap array in AS3

I have created a tilemap in AS3 that I need to save to a database, the system works absolutely fine. When the user creates an account, a map is automatically created for them (it's always the same sized map, with trees, rocks etc 11x11).

[18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17],
[7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5],

How do I go about saving this to a mysqli database and then get the information and return it back to the AS3 script? I know how to post from AS3, and I know how to get information from a page. I've saved the entire Array under one Column called tileMap, then when I try and query tileMap from the table... nothing is returned. Is it because I am using the [ ] braces? I don't really know how to go about displaying this.

load and unload external swf files from a BUTTON click

I have a huge problem to load and unload my swf external pages in the main container. I have 4 external files to load and each of them is linked to a button and i would like this button (when pressed to lead the correspondant swf external file inside the main container).

here is the code that i am using ... any idea?

var mcExt1:MovieClip;
var load:Loader = new Loader();
load.contentLoaderInfo.addEventListener(Event.COMPLETE, HomeLoaded);
load.load(new URLRequest("home.swf"));


function HomeLoaded(e:Event):void {
mcExt1 = MovieClip(load.contentLoaderInfo.content);
load.contentLoaderInfo.removeEventListener(Event.COMPLETE, HomeLoaded);
mcExt1.x = 0;
mcExt1.y = 95;
addChild(mcExt1);
}

home_btn.addEventListener(MouseEvent.CLICK, loadhome);
function loadhome(e:MouseEvent):void {

    removeChild (mcExt1);
    mcExt1= MovieClip(load.contentLoaderInfo.content);
    load.load(new URLRequest("home.swf"));
    addChild (mcExt1);
    mcExt1.x = 0;
    mcExt1.y = 95;

}   

aboutus_btn.addEventListener(MouseEvent.CLICK, loadaboutus);
function loadaboutus(e:MouseEvent):void {

    removeChild (mcExt1);
    mcExt1= MovieClip(load.contentLoaderInfo.content);
    load.load(new URLRequest("aboutus2.swf"));
    addChild (mcExt1);
    mcExt1.x = 0;
    mcExt1.y = 95;

}   


getinvolved_btn.addEventListener(MouseEvent.CLICK, loadgetinvolved);
function loadgetinvolved(e:MouseEvent):void {

    removeChild (mcExt1);
    mcExt1= MovieClip(load.contentLoaderInfo.content);
    load.load(new URLRequest("getinvolved.swf"));
    addChild (mcExt1);
    mcExt1.x = 0;
    mcExt1.y = 95;

}   

contact_btn.addEventListener(MouseEvent.CLICK, loadcontact);
function loadcontact(e:MouseEvent):void {

    removeChild (mcExt1);
    mcExt1= MovieClip(load.contentLoaderInfo.content);
    load.load(new URLRequest("contact.swf"));
    addChild (mcExt1);
    mcExt1.x = 0;
    mcExt1.y = 95;

}



`   

THANKS A LOT IN ADVANCE !!

Stop scrolling page on focus of another textfield (webview , on iOs , as3)?

I am loading a url(html) through stagewebviewbridge in as3 on iPad , there is a form on that page , on tapping of different textfields (on focus of another textfield) page gets scrolled . I want to remove that scrolling functionality ? Please help.

openfoam: flex yyin.rdbuf(std::cin.rdbuf() error

I want to report a solution to an error I got while installing OpenFOAM 3.0.1 in Mac OS X El Capitan Version 10.11.2 The error was: "error: member reference type 'std::istream *' (aka 'basic_istream *') is a pointer; maybe you meant to use '->'? yyin.rdbuf(std::cin.rdbuf());"

This problem is related to flex version 2.6.0. which I installed using macports.

I could overcome the problem by using "flex 2.5.35 Apple(flex-31)" which is at /usr/bin/flex (instead of /opt/local/flex).

Just change "flex" to "/usr/bin/flex" in the file $(WM_DIR)/rules/General/flex++ of your openfoam source distribution.

make movie clip with function mouse down in action script 3

i will make my hammer(movie clip) following cursor and every time I click the mouse / mouse down, the hammer will come down exposed cursor and return to original position. But i just can make the hammer(movie clip) following cursor. How can I do?

hammer.startDrag(true);

mardi 22 décembre 2015

AS3 Fla File converted from AS2 not showing code in IntelliJ-Idea

I exported an Fla containing AS2 code to AS3 and generated an SWF that is supposed to contain the required object oriented codes.But after i added it to IntelliJ IDE and double clicking, i do not get any inner files.Nor im able to call any instances.What is going wrong here?

creating text in AS3

I followed this tutorial in order to get a better understanding of classes found here - http://ift.tt/1jgTVZ4

I did everything correctly up to step 10, but when I went to export the swf I got a blank screen. I get an error in the compiler that says "expecting identifier before dot."

I don't know what this means but you can download my files and take a look and hopefully give me an answer, thanks!

http://ift.tt/1V55Tr2

How to Create a Doppler Effect Applet for Particles

I need to make an applet which is very similar to Doppler Effect applets, except that wavefronts are made of separate dots (particles like photons). There is a moving source (a round ball) and wavefronts consisting of a certain number of dots (not point-like, but 1 mm in diameter) are generated right at its edge and spread with a uniform speed. As the radius of the wavefront increases, the distance between the dots is increasing as well. But the number of dots and their size must stay the same, to show that these are the same dots moving. As the basis for this applet, I am using the applet found at the site: http://ift.tt/1REJ5iN. The reason I chose this applet is because it is based on an old version of Flash (MX2K4 with ActionScript 1) which allows to create dotted circles. I also checked a number of other Doppler applets which have been made with Easy JavaScript Simulations but they did not allow for dotted circles. So my first question is: can you advise me some programs to create applets with dotted circles? Specifically, I must stress that I need dotted circles with the same number and size of dots but with increased distance between dots as the circle expands. Now when I tried to create Doppler applet with dotted circles using Flash MX2K4 with ActionScript 1, I ran into several problems. In the original applet, wavefront expansion was done in the following way: it was a movie generated from two keyframes, while intermediate keyframes were shape tweened. First keyframe was a circle of a small diameter, and last keyframe was a circle of a large diameter. Both circles were represented by a thin line. When I tried to create applet with dotted circles, I made the first keyframe as a small circle with 1 mm dots almost touching each other. The last keyframe was a large circle with the same number of 1 mm dots but with a large spacing between the dots. The dots were in the same relative positions both in small and large circles. When I attempted to make a movie clip with these first and last frames using a shape tween, it did not keep the same number of dots. It created more and more dots with the same small spacing between them – up until the last frame when the spacing between the dots suddenly became very large (as it should have been). So my second question is why is it happening? And how to solve this problem? This problem arose since I tried to create a movie clip for wavefronts by tweening between the first and last frames in Flash MX2KK. Can you advise me of some other software which can create a movie clip with expanding dotted circles which I can insert into this Flash MX2K4 applet? I understand that this is a very old version of Flash. In fact I tried to use some later versions of Flash (e.g. Flash CC) but they all have the same problem with dot spacing in expanding circles. Thank you in advance for any help. Your help will be oh-so-much appreciated!

Spark Button trapping keydown (spaceBar) event

Question: Is there any reason a Spark Button would trap key events, in particular a "spacebar" key event?

Background: I've inherited and am maintaining a large legacy project done in Flex 4.6. I am seeing a weird behavior with a Spark Button. Essentially, once the button has been clicked on (i.e. given focus) a keyEvent (spaceBar) will trigger the click event handler attached to the button.

Weird, right?

The button is defined in MXML (below) within an MX:Module. The module has key event listeners attached to the stage but the event handlers for those do nothing with the button:

this.stage.addEventListener(KeyboardEvent.KEY_DOWN, echoKeyDownHandler);
this.stage.addEventListener(KeyboardEvent.KEY_UP, echoKeyUpHandler);

If I put a trace statement in the button's event handler to check the event type when this weird behavior occurs, the type is reported as a click. I don't see anything in the docs for the Spark Button about capturing key events like this.

   <s:Button id="toggleBtn"
     label="Editor" 
     click="toggleBtn_clickHandler(event)" 
      x="943" y="8"/>

AS3 MySQL-String to Array

I'm trying to get string from MySQL to be insert into Array and use the Array on my DataGrid. When I use it it fill three empty spaces in my DataGrid and doesn't display their names or any other values.

There is code where I think problem is:

function showResult3 (event:Event):void {
trace("ShowResult3");
var Numer:int;
var contactsTextFormat:TextFormat = new TextFormat();
contactsTextFormat.size = 15;   
var contactListArray:Array = event.target.data.givenContactList.split("(||)");

trace(contactListArray[0]);
trace(contactListArray[2]);

contacts_datagrid_1.columns = ["Nazwa"];
contacts_datagrid_1.setRendererStyle("textFormat",contactsTextFormat);
contacts_datagrid_1.dataProvider = new DataProvider(contactListArray);
//trace(event.target.data.givenContactList);

contacts_datagrid_1.addEventListener(Event.CHANGE, onSelectedGrid);
function onSelectedGrid (event:Event):void{
    trace(testTextBox_txt.text = "Selected " + event.target.selectedItem.Nazwa + " his number: " + event.target.selectedItem.Numer)

}}

Screenshot of the App for Visulation

FlashDevelop - Test IOS on windows - No Devices Detected

I developed an application for mobile, using FlashDevelop's AIR Mobile AS3 App Project template.

Following AIR_Android_readme.txt and AIR_iOS_readme.txt, I successfully packaged it into both apk and ipa.

I can easily test the apk on the computer via bat/RunApp.bat provided by FlashDevelop.

However once I modify RunApp.bat to ios-debug in order to test the ipa, I get the following log in the cmd:

Packaging application for debugging on iOS -interpreter

Packaging: dist\AppName-debug-interpreter.ipa using certificate: cert\iphone_dev.p12...

Installing application for testing on iOS ()

No Devices Detected

Installing the app on the device failed

Press any key to continue . . .

I have android studio and sdk installed and working, however I didn't install anything similar for IOS development, I have iTunes in case it matters.

Any idea what's wrong and how to fix it?

AS3: Normal vector of a shape rotated in 3D space

I have a display object that has been rotated in 3D space. How can I calculate a normal vector for that object for the purpose of backface culling? I am not using Stage3D.

AdvancedDatagrid and itemEditor: Value disappears when clicked

I'm trying to use a ComboBox as itemEditor in an AdvancedDatagrid. Both the grid and the comboBox fills up with values. But when I click in a cell the value disappears. Have I missed a property, or do I have to write an explicit itemEditor to copy the value to and from the itemEditor?

Full code:

<?xml version="1.0"?>
<!-- dpcontrols\ArrayCollectionInAS.mxml -->
<s:Application xmlns:fx="http://ift.tt/rYUnH9" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               initialize="initCB();">

<fx:Script>
    <![CDATA[
        import mx.collections.*;
        [Bindable] public var stateArray:ArrayCollection;

        public function initCB():void {
            stateArray=new ArrayCollection([{label:"AL", data:"Montgomery"},
                                      {label:"AK", data:"Juneau"},
                                      {label:"AR", data:"Little Rock"}]);
        } 

        [Bindable] public var initDG:ArrayCollection = new ArrayCollection([{etikett:'NY', tekst:"New York"}, {etikett:'LA', tekst:"Los Angeles"}]);
    ]]>
</fx:Script>     


<mx:AdvancedDataGrid id="gridIntMapping" y="24" left="10" right="605" height="166" editable="true" dataProvider="{initDG}">
    <mx:columns>
            <mx:AdvancedDataGridColumn width="130" dataField="etikett" headerText="Skjema referanse" editorDataField="text">
                <mx:itemEditor>
                    <fx:Component>                  
                        <mx:ComboBox editable="true" dataProvider="{outerDocument.stateArray}" labelField="label"/>
                    </fx:Component>
                </mx:itemEditor>
            </mx:AdvancedDataGridColumn>
    </mx:columns>
</mx:AdvancedDataGrid>

as3 - How to add a movieclip into the parent's parent?

I have a gun child inside of a movieclip called "player" and "player" is inside another movieclip called "level one".

So inside the gun class, the code spawns a bullet. Which has to spawn in the parent's parent. So the bullet can shoot into the level.

private function fire(m: MouseEvent)
{
    //when bullet fired
    var b = new Bullet;
    MovieClip(MovieClip(parent).parent).addChild(b);
}

However, the bullet never appears in the parent's parent. What could be the issue here?

how to make random movie clip with actionscript 3?

I am very confused about ActionScript 3. because I am already quite familiar with ActionScript 2. Can you help me to make the script actionscript 3, a game that I will make has a 3 "hole" as a movie clip, and then there is the character "rat" as a movie clip out of 20 times. then the "rat" as a movie clip will be out randomly over the "hole". Thanks