Adding a movieclip in each square of my calendar (AS3) - arrays

I've got a calendar with squares in wich each date is wrote :
var myArray:Array = new Array();
var row:Number = 0;
var moonNum:Number;
var holder_txt:MovieClip = new MovieClip;
addChild(holder_txt);
holder_txt.x = 35;
holder_txt.y = 10;
startDay -= 1;
for (var t:int = 0; t < getDays(myDate); t++) {
myArray[t] = (t+1);
var textNum:String = myArray[t];
import box;
import moonPhase;
var square:MovieClip = new box();
var moon:MovieClip = new moonPhase();
holder_txt.addChild(square);
square.name = textNum
moonNum= calculateMoonPhase(myDate.fullYear, myDate.month,t+1);
square.texter.text = textNum +" "+ moonNum;
square.x = (startDay) *75
square.y = (row+1)*65
startDay++;
if(startDay >= 7){
startDay = 0;
row++;
I've got a function that calculate the moonPhase for everyday.
moonNum= calculateMoonPhase(myDate.fullYear, myDate.month,t+1);
It results as a number (between 0 and 8).
I've got movieClip of a moon with 8 frames (new moon,full moon...etc).
I'd like to add the movieClip of the moon on each square with the corresponding frame number.
moonClip.gotoAndStop(moonNum);
I've add each moonNum to each square day :
square.texter.text = textNum +" "+ moonNum;
But I've no idea how to add movieclips to each square day...
Any help ?

It's better to add moonPhase in the class box directly. So for each box that you copied, you have an instance of moon in it to.
But, in your sample code, you can add moon to the square directly to.
square.addChild(moon);

Related

Accessing Items in an Array - AS3

I've got an Object item.movieimage that contain some texts (item:Object) that is retrieve from my database. The text is changing every week automatically.
If I do trace(item.movieimage) the output is something like this :
text1
text2
text3
text4
The words changes as the code is taking them from my database. The database changes the words every week.
Now, I want my AS3 code to display the third element of item.movieimage.
I've tried to do this :
var my_str:String = item.movieimage+",";
var ary:Array = my_str.split(",");
trace(ary[2]);
But it's not working. The output is "undefined".
Do you know how can I access a specific item in the Array that I've created ? Or how can I access the third item of item.movieimage ?
If I do trace(ary);, the output is :
text1,
text2,
text3,
text4,
EDIT :
For infos :
trace(typeof(item.movieimage)) and trace(typeof(ary)) are :
typeof(item.movieimage)=string
typeof(ary)=object
EDIT 2 :
Here's a screen capture of item.movieimage
Screen Cap of item.movieimage
EDIT 3
Here's my code in order to understand how "item.movieimage"is working
//Variables for downloading content from my database to my AS3 code
var urlReqSearchAll: URLRequest = new URLRequest("http://www.myWebSite/searchMovie4.php");
var loader5:URLLoader = new URLLoader();
//downloading content
function searchAll():void {
if (contains(list)){
list.removeChildren();
}
urlReqSearchAll.method = URLRequestMethod.POST;
loader5.load(urlReqSearchAll);
loader5.addEventListener(Event.COMPLETE,complete);
var variables:URLVariables = new URLVariables();
}
//Content Downloaded.
function complete(e:Event):void {
addChild(list);
products = JSON.parse(loader5.data) as Array;
hourSaved.data.saved=loader5.data;
products.reverse();
for(var i:int = 0; i < products.length; i++){
createListItem(i, products[i]);
}
displayPage(0);
showList();
}
// If too much items --> creates multiple page
const itemsPerPage:uint = 7;
var currentPageIndex:int = 0;
function displayPage(pageIndex:int):void {
list.removeChildren();
currentPageIndex = pageIndex;
var firstItemIndex:int = pageIndex * itemsPerPage;
var j:int = 0;
var lastItemIndex: int = firstItemIndex + 7; // as lastItemIndex should be 10 more
if (lastItemIndex > products.length) // if lastindex is greater than products length
lastItemIndex = products.length;
for(var i:int = firstItemIndex; i< lastItemIndex; i++){
createListItem( j, products[i]); // j control the position and i points to particular element of array..
j++;
}
next.visible = lastItemIndex < products.length - 1;
if(currentPageIndex==0){
previous.visible=false;
}
}
// Display the information downloded from my database
function createListItem(index:int, item:Object):void {
var listItem:TextField = new TextField();
var myFormat:TextFormat = new TextFormat();
myFormat.size = item.title.length > 13 ? 22 : 26
listItem.multiline = true;
listItem.wordWrap = true;
myFormat.align = TextFormatAlign.CENTER;
myFormat.color = 0xA2947C;
myFormat.font = "Ebrima";
myFormat.bold = true;
listItem.defaultTextFormat = myFormat;
listItem.x = 135;
listItem.y = 123+ index * 84;
listItem.width = 200;
listItem.height = 80;
listItem.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
showDetails(item);
});
list.addChild(listItem);
str = item.title;
}
My php file "SearchMovie4.php" is like this :
$products = array();
while ($row = mysql_fetch_array($sql_result)) {
$products[] = array(
"title" => $row["theTitle"],
"movieimage" => $row["movieimage"],
"movielength" => $row["movielength"],
"story" => $row["story"],
);
}
echo json_encode($products);
So, if I do trace(item.movieimage) in AS3 code, it will display all the items in the row movieimage of my database.
If I do trace(item.title) in AS3 code, it will display all the items in the row title of my database.
What I'd like is to be able to do, in my AS3 code, trace(item.movieimage[2]) in order to show me the third item in the row "movieimage".
Well, the text you've provided to the movieimage property of the item object has not the same delimiter as what you have provided to the split() method; in your case the character of comma!
I suspect the delimiter you have, is the "space" character or a new-line character, like the character of carriage retrun.
In the following code snippet, I've used the "space" as the delimiter character:
var item:Object = new Object();
item.movieimage = "text1 text2 text3 text4";
var my_str:String = item.movieimage;
var ary:Array = my_str.split(" ");
trace(ary[2]); // text3
As #someOne said the output shows the list items are each on a new line, so you need to split() against newlines. One of these should work:
// if server uses "\n" newline char
var movies:Array = item.movieimage.split("\n");
// if server uses "\r" carriage return char
var movies:Array = item.movieimage.split("\r");
// if you aren't sure or there's a mixture of newline chars
var movies:Array = item.movieimage.split(/[\r|\n]+/);
Also note that if you have any control over how the server returns these values, you should just return a JSON array (since I see in your screenshot you are already decoding JSON), then you won't have to do any string splitting.

Can i display multiple copies of a movieclip inside a array at once

Is there a way to make the code below work properly? When I use this code it only shows one movieclip:
var tempHead:head001 = new head001();
var mcArr:Array = new Array( tempHead );
var firstHead:MovieClip = mcArr[0];
firstHead.y = 30;
addChild(firstHead);
var secondHead:MovieClip = mcArr[0];
secondHead.y = 180;
addChild(secondHead);
`
You were just assigning a reference to the MovieClip. That'y, its not working.
First take instance of head001 class using new operator as much you want and store it to an array, then you can access very easily.
var tempHead: head001;
var mcArr: Array = new Array();
for (var i: uint = 0; i < 2; i++) {
tempHead = new head001();
addChild(tempHead);
mcArr.push(tempHead);
mcArr[i].y = mcArr[i].height * i;
}

How to display routes on OpenStreetMaps from richtextbox data, how create list which two value from another array?

I have this function which get back longitude and latitude from my Rtb data (first picture):
// funkcja pobierająca szerokość i długość geograficzną w formacie dziesiętnym
private Tuple<double, double>[] wsp_geograficzne(string[] lines)
{
return Array.ConvertAll(lines, line =>
{
string[] elems = line.Split(',');
return new Tuple<double, double>(0.01*double.Parse(elems[1]), 0.01*double.Parse(elems[3]));
});
}
This line calls this above function:
var data = wsp_geograficzne(richTextBox1.Lines);
This is a sample, which display routes on my OpenStreetMaps.
GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");// Constructing object for Overlay
gMapControl1.Overlays.Add(routes);
List<PointLatLng> list = new List<PointLatLng>(); // The list of Coordinates to be plotted
list.Add(new PointLatLng(53.119149707703, 23.1447064876556));
list.Add(new PointLatLng(53.11963262556597, 23.1468522548676));
list.Add(new PointLatLng(53.1205276192621, 23.1460046768188));
list.Add(new PointLatLng(53.120701464779, 23.1463050842285));
list.Add(new PointLatLng(53.1200962217943, 23.1489872932434));
list.Add(new PointLatLng(53.1196970143107, 23.1489014625549));
list.Add(new PointLatLng(53.119439459128, 23.1490087509155));
GMapRoute r = new GMapRoute(list, "myroute"); // object for routing
r.Stroke.Width = 5;
r.Stroke.Color = Color.Blue;
routes.Routes.Add(r);
gMapControl1.ZoomAndCenterRoute(r);
gMapControl1.Zoom = 15;
It looks like on the picture:
I want display routes from my data "wsp_geograficzne" (wsp_geograficzne include longitude and latitude) on this map. How should I do it? Is there any method that allow me to create List which data from "wsp_geograficzne"? I trying something like this:
List<PointLatLng> nowa = new List<PointLatLng>();
foreach (var p in data)
nowa.Add(p.Item1, p.Item2);
but it dont works. I get back error: Error 2 No overload for method 'Add' takes 2 arguments.
Please help :)
Ok I find answer (new function which get back 2 value (longitude and latitude) from rtb (longitude and latitude are back in decimal notation):
// funkcja pobierająca szerokość i długość geograficzną w formacie dziesiętnym
private Tuple<double, double>[] wsp_geograficzne(string[] lines)
{
return Array.ConvertAll(lines, line =>
{
string[] elems = line.Split(',');
double we1 = 0.01 * double.Parse(elems[3], EnglishCulture);
int stopnie1 = (int)we1;
double minuty1 = ((we1 - stopnie1) * 100) / 60;
double szerokosc_dziesietna = stopnie1 + minuty1;
double we2 = 0.01 * double.Parse(elems[5], EnglishCulture);
int stopnie2 = (int)we2;
double minuty2 = ((we2 - stopnie2) * 100) / 60;
double dlugosc_dziesietna = stopnie2 + minuty2;
return new Tuple<double, double>(szerokosc_dziesietna, dlugosc_dziesietna);
});
}
And this is a part which display routes on the map.
{
var data = wsp_geograficzne(richTextBox1.Lines);
List<PointLatLng> nowa = new List<PointLatLng>();
foreach (var p in data)
nowa.Add(new PointLatLng(p.Item1, p.Item2));
GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");
gMapControl1.Overlays.Add(routes);
GMapRoute r = new GMapRoute(nowa, "myroute"); // object for routing
r.Stroke.Width = 9;
r.Stroke.Color = Color.Blue;
routes.Routes.Add(r);
gMapControl1.ZoomAndCenterRoute(r);
gMapControl1.Zoom = 16;
}
If someone has another notations this part:
List<PointLatLng> nowa = new List<PointLatLng>();
foreach (var p in data)
nowa.Add(new PointLatLng(p.Item1, p.Item2));
please show me here.
Greetings from Poland :).

Actionscript 3, Flash CC: Placing Objects In An Array From The Library Onto The Stage

Hello programming gurus of stackoverflow, I am hoping that at least one of you will be able to help me with my coding problem. This is the first time I'm posting on this site, so if I miss something with the structure of my post, or anything please let me know (preferably not in a condescending matter) and I will gladly change it.
I actually had a different problem I was going to ask about, but I recently realized that some objects from my library weren't showing up on my stage. Hopefully, if this gets solved I won't have my other problem.
I am creating a learning module app using Flash CC and Actionscript 3, I like to think I am fairly proficient with Flash, but right now all my code is on the timeline because when I started I wasn't aware of the package setup. When I finish with the learning module I'll try and move everything to an AS package, so please bear with me.
This current frame of the module is a drag and drop game where the user drags the correct food, for the animal they chose in the previous frame, to the animal in the middle. The animal is dynamically placed on the stage, as well as an array of six possible food choices, all MovieClips pulled from the library. The array of food elements is actually not what I'm having problem with, they appear on my stage with no problems at all. The problem I'm having is when the user drags the correct food onto the animal, and the win condition is met, the array of balloon elements does not show up on the stage. I find it weird because I'm using near identical code for both the food and balloon array.
Here is my full code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
foodPet();
function foodPet():void {
//all of my pet, food, and balloon library objects have been exported for AS
var theBird:pet_bird = new pet_bird;
var theCat:pet_cat = new pet_cat;
var theChicken:pet_chicken = new pet_chicken;
var theDog:pet_dog = new pet_dog;
var theDuck:pet_duck = new pet_duck;
var theGuinea:pet_guinea = new pet_guinea;
var theHamster:pet_hamster = new pet_hamster;
var birdSeed:food_bird_seed = new food_bird_seed;
var catFood:food_cat_food = new food_cat_food;
var chickenFeed:food_chicken_feed = new food_chicken_feed;
var chocolate:food_chocolate = new food_chocolate;
var dogFood:food_dog_food = new food_dog_food;
var duckFood:food_duck_food = new food_duck_food;
var animalList:Array = [theBird, theCat, theChicken, theDog,
theDuck, theGuinea, theHamster];
var food1Array:Array = [birdSeed, catFood, chickenFeed,
chocolate, dogFood, duckFood, 4];
var xPosFood:Array = new Array();
var yPosFood:Array = new Array();
xPosFood = [32, 71, 146, 363, 431, 512];
yPosFood = [304, 222, 123, 123, 222, 304];
var animalClip:MovieClip;
animalClip = animalList[chosenAnimal];
addChild(animalClip);
animalClip.x = 256;
animalClip.y = 287;
animalClip.name = "selectedAnimal";
for (var i:uint = 0; i < food1Array.length - 1; i++){ //Where the food gets added
var isItRight:Boolean = false;
var foodName:String = ("food" + i);
var foodClip:MovieClip;
foodClip = food1Array[i];
foodClip.x = xPosFood[i];
foodClip.y = yPosFood[i];
foodClip.name = foodName;
addChild(foodClip);
trace(foodClip.parent);
foodDragSetup(foodClip, animalClip, food1Array[food1Array.length - 1], isItRight);
}
}
function foodDragSetup(clip:MovieClip, targ:MovieClip, correctNum:uint, isItRight:Boolean) {
var beingDragged:Boolean = false;
var xPos:Number = clip.x;
var yPos:Number = clip.y;
clip.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag);
function beginDrag(event:MouseEvent):void
{
clip.startDrag();
if (int(clip.name.substr(4)) == correctNum){
isItRight = true;
}
this.beingDragged = true;
setChildIndex(clip, numChildren - 1);
clip.addEventListener(MouseEvent.MOUSE_UP, endDrag);
}
function endDrag(event:MouseEvent):void
{
if (this.beingDragged) {
this.beingDragged = false;
clip.stopDrag();
if ((isItRight) && (clip.hitTestPoint(targ.x, targ.y, true))){
trace(targ.name + " has been hit.");
clip.x = targ.x;
clip.y = targ.y;
win_animal_food();
} else {
isItRight = false;
clip.x = xPos;
clip.y = yPos;
}
}
}
}
function win_animal_food():void {
const BALLOON_ROW:int = 4;
var count:uint = 0;
var altX:uint = 0;
var bBalloon:blue_balloon = new blue_balloon;
var gBalloon:green_balloon = new green_balloon;
var oBalloon:orange_balloon = new orange_balloon;
var pBalloon:purple_balloon = new purple_balloon;
var rBalloon:red_balloon = new red_balloon;
var yBalloon:yellow_balloon = new yellow_balloon;
var balloonList:Array = [bBalloon, gBalloon, oBalloon,
pBalloon, rBalloon, yBalloon, bBalloon, gBalloon,
oBalloon, pBalloon, rBalloon, yBalloon, bBalloon,
gBalloon, oBalloon, pBalloon];
var balloonY:Array = [144, -205, -265, -325];
var balloonX:Array = [0, 140, 284, 428, 68, 212, 356, 500];
for (var ballY:uint = 0; ballY < balloonY.length; ballY++){ //Where balloons
for (var ballX:uint = altX; ballX < altX + BALLOON_ROW; ballX++){ //get added
var balloonName:String = ("balloon" + count);
var balloonClip:MovieClip;
balloonClip = balloonList[count];
balloonClip.x = balloonX[ballX];
balloonClip.y = balloonY[ballY];
balloonClip.name = balloonName;
addChild(balloonClip);
trace(balloonClip.parent);
trace(balloonClip + " has been added!");
balloonClip.addEventListener(MouseEvent.CLICK, balloonPop);
count++;
}
if (altX == 0) {
altX = BALLOON_ROW;
} else {
altX = 0;
}
}
function balloonPop(event:MouseEvent):void {
event.target.play();
event.target.removeEventListener(MouseEvent.CLICK, balloonPop);
}
}
I thought there might have been a problem with my balloon MovieClips, so I subbed them in the food array:
var birdSeed:blue_balloon = new blue_balloon;
var catFood:green_balloon = new green_balloon;
var chickenFeed:orange_balloon = new orange_balloon;
var chocolate:purple_balloon = new purple_balloon;
var dogFood:red_balloon = new red_balloon;
var duckFood:yellow_balloon = new yellow_balloon;
They all showed up on the stage, so there's nothing wrong with the MovieClips.
Added: The first values of balloonXArray and balloonYArray were originally -4 and -145 respectively, but when I started having problems I wanted to make sure the balloons were showing up so I set the first values to 0 and 144 the balloon height and width are both 144 and their cross (not sure on it's name) is in the top left corner.
Added: The reason why there are multiple instances of the same balloon in the balloonList is because I need four rows of four balloons, but only have six different balloons.
I know the balloons are on the stage because the debug display shows their x and y values on the viewable stage. Using trace(foodClip.parent) and trace(balloonClip.parent) shows that the balloons and food all have the same parent, MainTimeline, so I know the balloons aren't getting added to some different space.
I have searched online, but have not come across anyone with a similar problem. Thus, I am asking on this forum if anyone can tell me why my balloons will not show up on the stage.
Please and thank you.
One thing I see straight off in the baloonList is that you have the same object instances listed multiple times. Each instance can only exist on stage exactly once. If you addChild() an instance that is already on stage, the instance is first removed, then re-added at the top of the display list.
You should change:
var bBalloon:blue_balloon = new blue_balloon;
var gBalloon:green_balloon = new green_balloon;
var oBalloon:orange_balloon = new orange_balloon;
var pBalloon:purple_balloon = new purple_balloon;
var rBalloon:red_balloon = new red_balloon;
var yBalloon:yellow_balloon = new yellow_balloon;
var balloonList:Array = [bBalloon, gBalloon, oBalloon,
pBalloon, rBalloon, yBalloon, bBalloon, gBalloon,
oBalloon, pBalloon, rBalloon, yBalloon, bBalloon,
gBalloon, oBalloon, pBalloon];
to:
var balloonList:Array = [
new blue_balloon,
new green_balloon,
new orange_balloon,
new purple_balloon,
new red_balloon,
new yellow_balloon,
new blue_balloon,
new green_balloon,
new orange_balloon,
new purple_balloon,
new red_balloon,
new yellow_balloon,
new blue_balloon,
new blue_balloon,
new green_balloon,
new orange_balloon,
new purple_balloon
];

Nevron BarChart with DateTimeScaleConfigurator weired series plotting?

I am using Nevron Charting Control ver.11.1.17.12 in application. I am facing problem in drawing the chart correct with the DateTimeScaleConfigurator. Here are following problem:
Series Bar overlapping each other if series count increases.
Series getting out of the Axis lines.
X Axis Scale automatically add previous year December and next year Jan in the scale which cause the chart to have blank area in case of Surface Chart.
//code snippet to draw Bar Chart Series
NBarSeries bar = new NBarSeries();
bar.UniqueId = new Guid(outputVariable.UniqueId);
bar.Name = outputVariable.LegendText;
chart.Series.Add(bar);
bar.HasBottomEdge = false;
bar.MultiBarMode = chart.Series.Count == 1 ? MultiBarMode.Series : MultiBarMode.Clustered;
// bar.InflateMargins = true;
bar.UseZValues = false;
indexOfSeries = chart.Series.IndexOf(bar);
ConfigureChartSeries(bar, indexOfSeries, outputVariable);
SetSeriesAxisInformation(bar, outputVariable.Unit);
bar.UseXValues = true;
foreach (DataRow row in seriesDataTable.Rows)
{
bar.XValues.Add(Convert.ToDateTime(row["TimeStamp"]).ToOADate());
}
code snippet to Add Surface Chart Series
chart.Enable3D = true;
chart.BoundsMode = BoundsMode.Stretch;
(chart as NCartesianChart).Fit3DAxisContent = true;
chart.Projection.SetPredefinedProjection(PredefinedProjection.OrthogonalTop);
chart.LightModel.EnableLighting = false;
chart.Wall(ChartWallType.Back).Visible = false;
chart.Wall(ChartWallType.Left).Visible = false;
chart.Wall(ChartWallType.Floor).Visible = false;
// setup Y axis
chart.Axis(StandardAxis.PrimaryY).Visible = false;
// setup Z axis
NAxis axisZ = chart.Axis(StandardAxis.Depth);
axisZ.Anchor = new NDockAxisAnchor(AxisDockZone.TopLeft);
NLinearScaleConfigurator scaleZ = new NLinearScaleConfigurator();
scaleZ.InnerMajorTickStyle.Visible = false;
scaleZ.MajorGridStyle.ShowAtWalls = new ChartWallType[0];
scaleZ.RoundToTickMin = false;
scaleZ.RoundToTickMax = false;
axisZ.ScaleConfigurator = scaleZ;
axisZ.Visible = true;
// add a surface series
NGridSurfaceSeries surface = new NGridSurfaceSeries();
surface.UniqueId = new Guid(outputVariable.UniqueId);
surface.Name = outputVariable.LegendText;
chart.Series.Add(surface);
surface.Legend.Mode = SeriesLegendMode.SeriesLogic;
surface.ValueFormatter = new NNumericValueFormatter("0.0");
surface.FillMode = SurfaceFillMode.Zone;
surface.FrameMode = SurfaceFrameMode.Contour;
surface.ShadingMode = ShadingMode.Flat;
surface.DrawFlat = true;
// Already set this property to false and working in other chart.
surface.InflateMargins = false;
surface.FrameColorMode = SurfaceFrameColorMode.Zone;
surface.SmoothPalette = true;
surface.Legend.Format = "<zone_value>";
surface.FillMode = SurfaceFillMode.Zone;
surface.FrameMode = SurfaceFrameMode.Contour;
CreateSurfaceSeries(outputVariable, surface);
chartControl.Refresh();
And the ScaleConfigurator configuration
chartPrimaryXAxis = chart.Axis(StandardAxis.PrimaryX);
// X Axis Configuration
dateTimeScale = new NDateTimeScaleConfigurator();
dateTimeScale.Title.Text = string.Empty;
dateTimeScale.LabelStyle.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.Scale, 90);
dateTimeScale.LabelStyle.ContentAlignment = ContentAlignment.MiddleLeft;
dateTimeScale.LabelStyle.TextStyle.FontStyle = new NFontStyle("Times New Roman", 6);
dateTimeScale.LabelFitModes = new LabelFitMode[] { LabelFitMode.AutoScale };
chartPrimaryXAxis.ScaleConfigurator = dateTimeScale;
chartPrimaryXAxis.ScrollBar.ResetButton.Visible = true;
chartPrimaryXAxis.ScrollBar.ShowSliders = true;
dateTimeScale.EnableUnitSensitiveFormatting = true;
Here is the generated output:
Any idea regarding this problem will be deeply appreciated.
Thanks in advance.
Series Bar overlapping each other if series count increases.
&
Series bar getting out of the Axis lines.
Answer: When you are using categorial data then use NOrdinalScaleConfigurator rather than NDateTimeScaleConfigurator. It will not solve the problem and put the series bar in the center of the scale and auto resize them according to the chart size also.
X Axis Scale automatically add previous year December and next year
Jan in the scale which cause the chart to have blank area in case of
Surface Chart.
Answer:
Set the following properties of the DateTimeScaleConfigurator to false to avoid such behavior.
dateTimeScale.RoundToTickMax = false;
dateTimeScale.RoundToTickMin = false;

Resources