As3 Flash: property of 3d mesh - actionscript-3

Below i have purposely made a test script: you can see it live at www.parele.com/plane.html
All source code is below, what im trying to do is change my mesh...please note:i want to change material of my model mesh , to another color , any color not create a new plane as this sample is an example to test this out not my actual hobby project, any files or info needed im happy to supply..I have been at this for a full over 20 hours stuck here and its killing me
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.containers.ObjectContainer3D;
import away3d.debug.AwayStats;
import away3d.entities.Mesh;
import away3d.containers.ObjectContainer3D;
import away3d.loaders.Loader3D;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import away3d.*;
import away3d.materials.ColorMaterial;
import away3d.materials.TextureMaterial;
import away3d.textures.BitmapTexture;
import sunag.animation.AnimationTarget;
import sunag.events.SEAEvent;
import sunag.sea3d.SEA3D;
import away3d.materials.methods.*;
import away3d.primitives.*;
import away3d.textures.*;
import away3d.utils.*;
import away3d.events.*;
[SWF(width = "955",height = "600",frameRate = "50")]
var view:View3D;
var scene:Scene3D;
var sea3d:SEA3D;
var _container:ObjectContainer3D = new ObjectContainer3D();
[Embed(source = "Models/plane.sea",mimeType = "application/octet-stream")]
var homepage:Class;
stage.stageFocusRect = false;
stage.showDefaultContextMenu = false;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
scene = new Scene3D();
view = new View3D(scene);
view.backgroundColor = stage.color;
view.antiAlias = 4;
var dat:BitmapData = new BitmapData(256, 256, false, WHATEVERCOLOUR);
var mMaterial = new TextureMaterial(new BitmapTexture(dat));
scene.addChild(_container);
addChild(view);
sea3d = new SEA3D();
view.blendMode = BlendMode.NORMAL;
sea3d.addEventListener(SEAEvent.COMPLETE, onComplete);
sea3d.loadBytes(new homepage());
function onEnterFrame(e:Event):void
{
var body1:Mesh = sea3d.getMesh("body");
body1.material = mMaterial;
view.render();
}
function onComplete(e:SEAEvent):void
{
view.camera = sea3d.getCamera("Camera001");
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
scene.addChild(sea3d.container);
}

I believe this is what you are looking for: SubMeshes
A mesh you pull from a model is usually made of at least on SubMesh, but can contain several. Changing the Material on that "root" Mesh object doesn't propagate to its SubMeshes. You need to iterate through its SubMeshes and change their material.
hth.

Related

Video not showing using netstream(bytes)

im working on video streaming i have a php api that return the video and then play it using byte array,but video is not showing, but when i look at the trace is hows the downloaded bytes and bytesloaded.Can you give me idea what i'm doing wrong i'm new in actionscript.
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.ProgressEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.NetStreamAppendBytesAction;
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.utils.ByteArray;
var video:Video;
var video_nc:NetConnection;
var video_ns:NetStream;
var video_stream:URLStream;
video_nc = new NetConnection();
video_nc.connect(null);
video_ns = new NetStream(video_nc);
video_ns.client = this;
video_ns.addEventListener(NetStatusEvent.NET_STATUS, ns_statusHandler);
video = new Video(1280, 720);
video.attachNetStream(video_ns);
video.smoothing = true;
video_ns.play(null);
video_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
video_stream = new URLStream();
video_stream.addEventListener(ProgressEvent.PROGRESS, videoStream_progressHandler);
video_stream.load(new URLRequest("https://www.xxxx.com/test.php"));
addChild(video);
function ns_statusHandler(event:NetStatusEvent):void
{
trace(event.info.code);
trace("zzz");
}
function videoStream_progressHandler(event:ProgressEvent):void
{
trace(event.bytesLoaded);
var bytes:ByteArray = new ByteArray();
video_stream.readBytes(bytes);
video_ns.appendBytes(bytes);
//trace(bytes);
}

Text doesn't appear in MovieClip after added as child. What's wrong with my ActionScript 3?

I'm pulling data from external XML. i created a sprite to serve as container for my pages. Those pages are movieclips which i then add each of them to stage as child to container using a for loop. For each movieclip i will add text & images which i will then animate using greensock. but the problem now is a simple text wont appear when i export swf movie. i have no problems loading external xml files and what not. i dont believe this to be a xml or loader problem. where did i go wrong? :~( .I believe i imported all the necessary package too.
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.text.*;
import flash.text.TextFieldAutoSize;
import flash.media.Sound;
import flash.media.SoundTransform;
import flash.media.SoundChannel;
import flash.net.navigateToURL;
import flash.display.*;
import flash.text.TextFormat;
import flash.display.StageScaleMode;
import flash.display.Stage;
public class menu extends Sprite {
protected var container:Sprite = new Sprite();
public function buildPages(e:Event):void {
var menu:XML=new XML(e.target.data);
menu.ignoreWhitespace=true;
container.x = menu.config.frxpos;
container.y = menu.config.frypos;
addChild(container);
var i:Number;
totalPages = menu.pages.page.length();
for(i=0; i<totalPages; i++) {
var pageMc:MovieClip = new MovieClip();
pageMc.name = menu.pages.page[i].#name;
pageMc.id = menu.pages.layoutNum.layNum[i];
container.addChild(pageMc);
pageMc.x = 100;
pageMc.y = 100;
pageMc.width = 200;
pageMc.height = 200;
pageNames[i] = pageMc.name;
pageLayoutNo[i] = pageMc.id;
if(pageMc.name == "registration") {
var myTxt:TextField = new TextField();
myTxt.text = menu.pages.intro.htext;
myTxt.textColor = 0xff0000;
myTxt.x = 150;
myTxt.y = 150;
myTxt.border = true;
myTxt.borderColor = 0x747474;
pageMc.addChild(myTxt);
}
}
}
}

Starling, hitTest: rotation and scale

I'm working on a game in which the shapes have to collide after changing rotation and size. As long as image1 isn't rotated using its .pivotX and .pivotY the hitTest works but as soon as I rotate around pivot the collision is wrong. I tried to use matrix but without good results.
Anyone can help me? Here the code:
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import starling.core.Starling;
import starling.display.Image;
import starling.display.Sprite;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
public class HitTest extends Sprite
{
[Embed(source="src/image.png")]
public static const ImagePng:Class;
public function HitTest()
{
addEventListener(starling.events.Event.ADDED_TO_STAGE, init);
}
private function init():void{
//First Image
var bitmap1:Bitmap = new ImagePng();
var texture1:Texture = Texture.fromBitmap(bitmap1);
var image1:Image = new Image(texture1);
addChild(image1);
/*
Here's the problem:
If you don't use .pivotX and .pivotY image1 doesn't rotate around its center but hits image2
If you use .pivotX and .pivotY image1 rotates around its center but the hittest doesn't work.
*/
// image1.pivotX = image1.width/2;
// image1.pivotY = image1.height/2;
image1.x=215;
image1.y=50;
image1.rotation=1;
var rect1:Rectangle = image1.getBounds(this);
var offset1:Matrix = new Matrix;
offset1.rotate(1);
offset1.tx = image1.x - rect1.x;
offset1.ty = image1.y - rect1.y;
var bitmapData1:BitmapData = new BitmapData(rect1.width, rect1.height, true, 0);
bitmapData1.draw(bitmap1, offset1);
//Second Image
var bitmap2:Bitmap = new ImagePng();
var texture2:Texture = Texture.fromBitmap(bitmap2);
var image2:Image = new Image(texture2);
addChild(image2);
image2.x=270;
image2.y=-10;
var rect2:Rectangle = image2.getBounds(this);
var offset2:Matrix = new Matrix;
offset2.tx = image2.x - rect2.x;
offset2.ty = image2.y - rect2.y;
var bitmapData2:BitmapData = new BitmapData(rect2.width, rect2.height, true, 0);
bitmapData2.draw(bitmap2, offset2);
var point1:Point = new Point(rect1.x, rect1.y);
var point2:Point = new Point(rect2.x, rect2.y);
//Hit Test
if(bitmapData1.hitTest(point1,255,bitmapData2,point2,255))
{
image2.color=0x00ff00;
}
}
}
}
This is again with matrix, but I think it works pretty well (it's somehow old, but the idea remains the same): http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/

How to resize my imported external swf file to fit(fullscreen) into stage? please give some sample codes

I used this code to import my swf file.now I want my swf file to fill all my stage(fullscreen).please give some sample code.
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.display.StageScaleMode;
var ldr:Loader = new Loader();
var urlReq:URLRequest = new URLRequest("File/game.swf");
ldr.load(urlReq);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
addChild(ldr);
function loaded(event:Event):void
{
var content:Sprite = event.target.content;
content.scaleX = 1 ;
}
This will stretch the loaded swf to fill the stage:
function loaded(event:Event):void
{
var content:Sprite = event.target.content;
content.scaleX = stage.stageWidth/content.width;
content.scaleY = stage.stageHeight/content.height;
}

StageText. How to store user input in a variable?

I have a a stageText object which is working on my phone. I can type into the field and it displays the text. How do I capture the input text and store it in a variable for later use? Thank you.
var qatAccessCode:StageText = new StageText();
qatAccessCode.softKeyboardType = SoftKeyboardType.NUMBER;
qatAccessCode.restrict = "0-9";
qatAccessCode.returnKeyLabel = ReturnKeyLabel.GO;
qatAccessCode.stage = this.stage;
qatAccessCode.viewPort = new Rectangle(225, 765, 200, 35 );
you make a one String variable. and stageText add Change Event. and stored stageText property text when occur event. later use a String variable.
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.geom.Rectangle;
import flash.text.ReturnKeyLabel;
import flash.text.SoftKeyboardType;
import flash.text.StageText;
import flash.events.Event;
var str:String;
var stageText:StageText = new StageText();
stageText.softKeyboardType = SoftKeyboardType.NUMBER;
stageText.restrict = "0-9";
stageText.returnKeyLabel = ReturnKeyLabel.GO;
stageText.stage = this.stage;
stageText.viewPort = new Rectangle(10, 10, 300, 40 );
stageText.addEventListener(Event.CHANGE, onChange);
function onChange(e:Event):void
{
str = stageText.text;
trace(str);
}