i'm trying to scraping into Html with beautiful soup but i've difficult scraping desired data.
i've write this but in this way i found all script in the Html.
response = s.get(dataObject.url)
soup = BeautifulSoup(response.text, 'html.parser')
script = soup.findAll('script')
I need to take 'pf_id' value from this html:
<script>
var qSVariables = ""; // Store Variables
var prodzoom_control = 'on';
var siteSubDirectory = "";
var addbsktTimeElapseVal = "1000";
var pageidentifie = 'product';
var promoSliderHours = "720";
var isKnockout = true;
var product_model_wears_lable = 'Model is wearing';
$(document).ready(function(){
var myVariantGridEM = new variantGrid('myVariantGridEM'); // Load the variant grid class
variants = { "40387759":{'sequence':'','opt2_sequence':'991','wasprice':'RRP €107.50','wasprice_net':'RRP €0.00','price':'€107.50','price_net':'€107.50','sale_item':'false','manufacturer_sku':'','manufacturer_name':'Jordan','option1':'White / University Red / White','option2':'6','option3':'','pf_id':'4038775','sell':'true','stock_status':'in stock','option2_js':'Size 6','option2_mob_js':'Size: 6','stock_int':1,'lead_text':'','promoicon':'<img src=\"/images/articles/icon_freedelivery_large.png\"
</script>
You can split string by "," and then look for 'pf_id'. If you find it split by ":" this time and get second value.
from bs4 import BeautifulSoup
data = """<script>
var qSVariables = ""; // Store Variables
var prodzoom_control = 'on';
var siteSubDirectory = "";
var addbsktTimeElapseVal = "1000";
var pageidentifie = 'product';
var promoSliderHours = "720";
var isKnockout = true
var product_model_wears_lable = 'Model is wearing';
$(document).ready(function(){
var myVariantGridEM = new variantGrid('myVariantGridEM'); // Load the variant grid class
variants = { "40387759":{'sequence':'','opt2_sequence':'991','wasprice':'RRP €107.50','wasprice_net':'RRP €0.00','price':'€107.50','price_net':'€107.50','sale_item':'false','manufacturer_sku':'','manufacturer_name':'Jordan','option1':'White / University Red / White','option2':'6','option3':'','pf_id':'4038775','sell':'true','stock_status':'in stock','option2_js':'Size 6','option2_mob_js':'Size: 6','stock_int':1,'lead_text':'','promoicon':'<img src=\"/images/articles/icon_freedelivery_large.png\"
</script>
"""
soup = BeautifulSoup(data, "html.parser")
script = soup.find("script")
splited_text = str(script).split(',')
result = ""
for i in range(len(splited_text)):
if "pf_id" in splited_text[i]:
result = splited_text[i].split(":")[1]
break
print(result)
Related
I want to use the LANDSAT/LE07/C01/T1_TOA collection in google earth engine and I am struggling to understand how the bits work in order to mask out areas with clouds and shadows. I managed to write the following, but I am not very confident and do not know how to mask out shadows.
var dataset = ee.ImageCollection('LANDSAT/LE07/C01/T1_TOA')
.filterBounds(geometry)
.map(function(image){return image.clip(geometry)})
.filter(ee.Filter.calendarRange(6,8,'month'))
.filterDate('1999-05-01','2017-09-30');
var qas = function(image) {
var qa = image.select('BQA');
var mask = qa.eq(672);
return image.updateMask(mask).copyProperties(image);
}
var merged = dataset.map(qas);
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
return image.addBands(ndvi);
};
var ndvi = merged.map(addNDVI);
How to properly do quality masking with bits?
Try It
var cloudMaskL7 = function(image) {
var qa = image.select('BQA');
var cloud = qa.bitwiseAnd(1 << 4)
.and(qa.bitwiseAnd(1 << 6))
.or(qa.bitwiseAnd(1 << 8));
var mask2 = image.mask().reduce(ee.Reducer.min());
return image
.select(['B3', 'B4'], ['Red', 'NIR'])
.updateMask(cloud.not()).updateMask(mask2)
.set('system:time_start', image.get('system:time_start'));
};
var dataset = ee.ImageCollection("LANDSAT/LE07/C01/T1_TOA")
.filterBounds(geometry)
.filterDate('2012-05-01','2017-09-30')
.map(cloudMaskL7)
var NDVIofLANDSAT = function(image) {
var ndvi = image.normalizedDifference(['NIR', 'Red']).rename('NDVI');
return image.addBands(ndvi);
};
var ndviCollection = dataset
.map(NDVIofLANDSAT)
.select("NDVI");
print("Total no of LANDSAT Images ", ndviCollection);
Map.addLayer (ndviCollection.first().select('NDVI').clip(geometry), {min:0, max:1, 'palette': ['red','yellow', 'green']}, 'NDVI')
I hava a html table create from code in AnguljarJS with a lot of data.
How could i transform this table to JSON? This table is not painted in the HTML file. I've tried everything and I can't transform it. I know there is a method called tableToJSON but that only works with tables that are in the HTML.
let table = document.createElement("table");
table.id = "table";
table.style.display = "none";
let header = table.createTHead();
let row = header.insertRow(0);
row.style.fontWeight = "bold";
row.style.textAlign = "center";
row.style.backgroundColor = "#e2f0ff";
row.style.color = "#04408f";
let cell0 = row.insertCell(0);
cell0.innerHTML = this.$filter("translate")("repository.periodo");
let cell1 = row.insertCell(1);
cell1.innerHTML = this.$filter("translate")("informes.operaciones.areaNegAcc");
let cell2 = row.insertCell(2);
cell2.innerHTML = this.$filter("translate")("repository.dividendos.nomAccionista");
let cell3 = row.insertCell(3);
cell3.innerHTML = this.$filter("translate")("ampliacion.tipope");
let cell4 = row.insertCell(4);
cell4.innerHTML = this.$filter("translate")("informes.operaciones.areaNegPart");
let cell5 = row.insertCell(5);
cell5.innerHTML = this.$filter("translate")("informes.operaciones.nombrePart");
let cell6 = row.insertCell(6);
cell6.innerHTML = this.$filter("translate")("repository.dividendos.porParticipacion");
let cell7 = row.insertCell(7);
cell7.innerHTML = this.$filter("translate")("repository.operaciones.varPorcentaje");
let cell8 = row.insertCell(8);
cell8.innerHTML = this.$filter("translate")("informes.operaciones.saldoEur");
let tBody = document.createElement("tbody");
table.appendChild(tBody);
for (let i = 0; i < vm.listOper.length; i++) {
var rowTb = tBody.insertRow(i);
rowTb.style.textAlign = "center";
rowTb.style.color = "#04408f";
var celltB1 = rowTb.insertCell(0);
celltB1.innerHTML = vm.listOper[i].codPeriodoc;
var celltB2 = rowTb.insertCell(1);
celltB2.innerHTML = vm.listOper[i].desUnidpetAcc;
var celltB3 = rowTb.insertCell(2);
celltB3.innerHTML = vm.listOper[i].codAccion + "-" + vm.listOper[i].desAccion;
var celltB4 = rowTb.insertCell(3);
celltB4.innerHTML = vm.listOper[i].desTipoOper;
var celltB5 = rowTb.insertCell(4);
celltB5.innerHTML = vm.listOper[i].desUnidpetPart;
var celltB6 = rowTb.insertCell(5);
celltB6.innerHTML = vm.listOper[i].codParticip + "-" + vm.listOper[i].desParticip;
var celltB7 = rowTb.insertCell(6);
celltB7.innerHTML = vm.listOper[i].porParticipFormat + "%";
var celltB8 = rowTb.insertCell(7);
celltB8.innerHTML = vm.listOper[i].varPor ? vm.listOper[i].varPor : "-";
var celltB9 = rowTb.insertCell(8);
celltB9.innerHTML = vm.listOper[i].saldoEurFormat;
}
return table;
This is a very un-angular approach, and because you're directly writing to the DOM, you're shooting yourself in the foot when it comes to manipulating or transforming it.
Consider refactoring your table build to be something like this:
let tabledata = []
tabledata.push([
this.$filter("translate")("repository.periodo"),
this.$filter("translate")("informes.operaciones.areaNegAcc"),
this.$filter("translate")("repository.dividendos.nomAccionista"),
this.$filter("translate")("ampliacion.tipope"),
this.$filter("translate")("informes.operaciones.areaNegPart"),
this.$filter("translate")("informes.operaciones.nombrePart"),
this.$filter("translate")("repository.dividendos.porParticipacion"),
this.$filter("translate")("repository.operaciones.varPorcentaje"),
this.$filter("translate")("informes.operaciones.saldoEur)
]);
var elem
for (let i = 0; i < vm.listOper.length; i++) {
elem = vm.listOper[i]
tabledata.push([
elem.codPeriodoc,
elem.desUnidpetAcc,
elem.codAccion + "-" + elem.desAccion,
elem.desTipoOper,
elem.desUnidpetPart,
elem.codParticip + "-" + elem.desParticip,
elem.porParticipFormat + "%",
elem.varPor ? elem.varPor : "-",
elem.saldoEurFormat
]);
}
$scope.tabledata = tabledata;
// json: JSON.parse(tabledata)
<table>
<tr ng-repeat='x in tabledata track by $index' ng-class='{"headerRow":$index==0}'>
<td ng-repeat='y in x'> {{y}} </td>
</tr></table>
Now you've got your data in a tidy little array which you can easily transfer to JSON and a angular friendly table to boot.
I have created a query in my module with this code:
var myName = "something"
var theQuery = _contentManager.Create("Query");
theQuery.As<TitlePart>().Title = myName + "Query";
var filterGroupRecord = new FilterGroupRecord();
var filterRecord = new FilterRecord()
{
Category = "Content", Type = "ContentTypes",
Description = myName , Position = 1,
State = "<Form><Description>" + myName
+ "</Description> <ContentTypes>" + myName + "</ContentTypes></Form>"
};
filterGroupRecord.Filters.Insert(0, filterRecord);
theQuery.As<QueryPart>().FilterGroups.Clear();
theQuery.As<QueryPart>().FilterGroups.Insert(0, filterGroupRecord);
And I know to create a projection widget I should use below code :
var theProjectionWidget = _contentManager.Create("ProjectionWidget");
theProjectionWidget .As<WidgetPart>().Title = myName + "ProjectionWidget";
theProjectionWidget .As<WidgetPart>().RenderTitle = false;
theProjectionWidget .As<WidgetPart>().Zone = "Content";
theProjectionWidget .As<WidgetPart>().Position = "1";
theProjectionWidget .As<WidgetPart>().LayerPart.Name = myName;
But I don't know how to assign the above query to this new projection widget.
How to assign query id to ProjectionPart.QueryLayoutRecordId???!!
I would appreciate any help.
These are links to this discussion in codeproject & codeplex:
http://www.codeproject.com/Questions/876128/How-to-create-a-projection-widget-programmatically
https://orchard.codeplex.com/discussions/580735
After some wrestling with code and debug I found solution for my question.
Anybody with my problem can use this code:
theProjectionWidget.As<ProjectionPart>().Record.QueryPartRecord = new QueryPartRecord(){
ContentItemRecord = theQuery.As<QueryPart>().ContentItem.Record,
FilterGroups = theQuery.As<QueryPart>().FilterGroups,
Id = theQuery.As<QueryPart>().Id,
Layouts = theQuery.As<QueryPart>().Layouts,
SortCriteria = theQuery.As<QueryPart>().SortCriteria
};
I'm creating a photoshop extension where I need to save the file people are working on and upload it to a server. So I want the extension to be able to automatically choose the current file and upload it to my server.
Problem is I don't know how to pre-select a file for people. Here's my code so far:
var app:Application = Photoshop.app;
var doc:Document = app.documents.add();
doc.selection.selectAll();
var color:RGBColor = new RGBColor();
color.red = 0;
color.green = 0;
color.blue = 255;
doc.selection.fill(color);
var saveOptions:JPEGSaveOptions = new JPEGSaveOptions();
//Add other PDF save options here.
doc.saveAs(File.applicationStorageDirectory, saveOptions);
var jsonOBJ:Object = {};
jsonOBJ.option = "iphone";
jsonOBJ.title = "c";
jsonOBJ.description = "s";
jsonOBJ.app_store_url = "iphone";
jsonOBJ.tags = "c";
jsonOBJ.temp_number = 1;
var _service:HTTPService = new HTTPService();
_service.url = "http://localhost:3000/designs";
_service.method = "POST";
_service.contentType = "application/json";
_service.resultFormat = "text";
_service.useProxy = false;
_service.makeObjectsBindable = true;
_service.addEventListener(FaultEvent.FAULT,faultRX);
_service.addEventListener(ResultEvent.RESULT,resultRX);
_service.showBusyCursor = true;
_service.send( JSON.encode( jsonOBJ ) );
function resultRX():void
{
trace(ResultEvent.RESULT);
}
function faultRX():void
{
trace(FaultEvent.FAULT);
}
var file:FileReference;
var filefilters:Array;
var req:URLRequest;
filefilters = [ new FileFilter('Images', '*.jpg') ]; // add other file filters
file.browse(filefilters);
It's a photoshop extension. I ended up using FileReference and link to the file. it worked. I dunno how to actually upload the image though. When I use file.upload(requestUrl), it sends along a wrong content type. –
I'm working on a webpage for a class and am trying to work the navigation using ActionScript 3. My understanding of how it should work is that when you click the links at the top, it removes whatever is currently displayed, using removeChild, and adds the new page's content using addChild.
It works fine when going from the initial page to one of the links. But whenever I go from a page that is not the home page to another page I get:
ArgumentError: Error #2025: The supplied DisplayObject must be a child
of the caller. at flash.display::DisplayObjectContainer/removeChild()
at nutshellMathReCoded4_fla::MainTimeline/hideOtherPages() at
nutshellMathReCoded4_fla::MainTimeline/runSubtraction()
Here is the code:
stop();
// Flash Imports
import flash.events.MouseEvent;
import flash.events.Event;
import flash.media.SoundMixer;
//Page Components //
// Home //
// Links
// Create Header & Nav //
// Logo Link
var headerLogo:logoMainPage = new logoMainPage();
headerLogo.x = 252.85;
headerLogo.y = 18.00;
//Addition Link
var additionLink:addPageLink = new addPageLink();
additionLink.x = 142.35;
additionLink.y = 96.00;
//Subtraction Link
var subtractionLink:subPageLink = new subPageLink();
subtractionLink.x = 208.60;
subtractionLink.y = 144.60;
// Multiplication Link
var multiplicationLink:mulPageLink = new mulPageLink();
multiplicationLink.x = 397.80;
multiplicationLink.y = 100.00;
// Division Link
var divisionLink:divPageLink = new divPageLink();
divisionLink.x = 597.95;
divisionLink.y = 144.60;
//Animation
var animation:mainAnimation = new mainAnimation();
animation.x = 99.90;
animation.y = 244.00;
//Addition //
var addSimpleX:additionSimpleX = new additionSimpleX();
addSimpleX.x = 41;
addSimpleX.y = 395.95;
var addSimpleY:additionSimpleY = new additionSimpleY();
addSimpleY.x = 364;
addSimpleY.y = 395.95;
var addSimpleAnswer:additionSimpleAnswer = new additionSimpleAnswer();
addSimpleAnswer.x = 701;
addSimpleAnswer.y = 395.95;
var additionAddSign:additionSign = new additionSign();
additionAddSign.x = 276.55;
additionAddSign.y = 360.20;
var additionEqualsSign:equalsSign = new equalsSign();
additionEqualsSign.x = 613.95;
additionEqualsSign.y = 360.20;
var addSum:additionSummary = new additionSummary();
addSum.x = 178.25;
addSum.y = 202;
var addTryOut:tryItOut = new tryItOut();
addTryOut.x = 205.70;
addTryOut.y = 475.65;
var addDDLink:digDeeperLink = new digDeeperLink();
addDDLink.x = 274.95;
addDDLink.y = 696;
var addTQLink:quizLink = new quizLink();
addTQLink.x = 465;
addTQLink.y = 696.50;
//Addition Deeper
var addLong:additionExtended = new additionExtended();
addLong.x = 193.00;
addLong.y = 323.00;
var addDDSum:additionDDSummary = new additionDDSummary();
addDDSum.x = 222.40;
addDDSum.y = 201.20;
var addDDB2B:backToBasicsLink = new backToBasicsLink();
addDDB2B.x = 271.95;
addDDB2B.y = 696;
var addDDTQ:quizLink = new quizLink();
addDDTQ.x = 468;
addDDTQ.y = 696;
//Subtraction
var subSimpleX:subtractionSimpleX = new subtractionSimpleX();
subSimpleX.x = 44;
subSimpleX.y = 408.50;
var subSimpleY:subtractionSimpleY = new subtractionSimpleY();
subSimpleY.x = 367;
subSimpleY.y = 408.50;
var subSimpleAnswer:subtractionSimpleAnswer = new subtractionSimpleAnswer();
subSimpleAnswer.x = 692.95;
subSimpleAnswer.y = 408.50;
var subtractionEqualsSign:equalsSign = new equalsSign();
subtractionEqualsSign.x = 612.80;
subtractionEqualsSign.y = 372.95
var subtractionSubSign:subtractionSign = new subtractionSign();
subtractionSubSign.x = 280.85;
subtractionSubSign.y = 371.95;
var subTryOut:tryItOut = new tryItOut();
subTryOut.x = 221.8;
subTryOut.y = 477.95;
var subDDLink:digDeeperLink = new digDeeperLink();
subDDLink.x = 274.95;
subDDLink.y = 696;
var subTQLink:quizLink = new quizLink();
subTQLink.x = 465;
subTQLink.y = 696.50;
var subSum:subtractionSummary = new subtractionSummary();
subSum.x = 147.30;
subSum.y = 210.05;
// Subtraction Dig Deeper
var subBudget:budget = new budget();
subBudget.x = 367.95;
subBudget.y = 400.90;
var subExpenses:expenses = new expenses();
subExpenses.x = 204.00;
subExpenses.y = 513.40;
var subDDT1:subtractionDD1 = new subtractionDD1();
subDDT1.x = 264.05;
subDDT1.y = 211;
var subDDT2:subtractionDD2 = new subtractionDD2();
subDDT2.x = 206.65;
subDDT2.y = 351;
var subDDT3:subtractionDD3 = new subtractionDD3();
subDDT3.x = 131.80;
subDDT3.y = 474.95;
var subDDT4:subtractionDD4 = new subtractionDD4();
subDDT4.x = 291.00;
subDDT4.y = 463;
var subCheckBudgetLink:checkBudgetLink = new checkBudgetLink();
subCheckBudgetLink.x = 437;
subCheckBudgetLink.y = 609.5;
var subB2BLink:backToBasicsLink = new backToBasicsLink();
subB2BLink.x = 271.95;
subB2BLink.y = 696;
var subDDTQLink:quizLink = new quizLink();
subDDTQLink.x = 468;
subDDTQLink.y = 696;
//Multiplication
var mulSimpleX:multiplicationSimpleX = new multiplicationSimpleX();
mulSimpleX.x = 30.85;
mulSimpleX.y = 395.35;
var mulSimpleY:multiplicationSimpleY = new multiplicationSimpleY();
mulSimpleY.x = 370.85;
mulSimpleY.y = 395.35;
var mulSimpleAnswer:multiplicationSimpleAnswer = new multiplicationSimpleAnswer();
mulSimpleAnswer.x = 691.90;
mulSimpleAnswer.y = 395.35;
var multiplicationMulSign:multiplicationSign = new multiplicationSign();
multiplicationMulSign.x = 284.60;
multiplicationMulSign.y = 365.95;
var mulEqualsSign:equalsSign = new equalsSign();
mulEqualsSign.x = 609.80;
mulEqualsSign.y = 356.95;
var mulSummary:multiplicationSummary = new multiplicationSummary();
mulSummary.x = 145.30;
mulSummary.y = 202.40;
var mulTryOut:tryItOut = new tryItOut();
mulTryOut.x = 218.80;
mulTryOut.y = 461.95;
var mulDDLink:digDeeperLink = new digDeeperLink();
mulDDLink.x = 274.95;
mulDDLink.y = 696;
var mulTQLink:quizLink = new quizLink();
mulTQLink.x = 465.00;
mulTQLink.y = 696;
// Multiplication Deeper
var mulDD1:multiplicationDD1 = new multiplicationDD1();
mulDD1.x = 241.15;
mulDD1.y = 209;
var mulDD2:multiplicationDD2 = new multiplicationDD2();
mulDD2.x = 297.05;
mulDD2.y = 350.40;
var mulDD3:multiplicationDD3 = new multiplicationDD3();
mulDD3.x = 316.75;
mulDD3.y = 393.65;
var mulDD4:multiplicationDD4 = new multiplicationDD4();
mulDD4.x = 297.55;
mulDD4.y = 436.90;
var mulB2BLink:backToBasicsLink = new backToBasicsLink();
mulB2BLink.x = 271.95;
mulB2BLink.y = 696;
var mulDDTQL:quizLink = new quizLink();
mulDDTQL.x = 468;
mulDDTQL.y = 696;
// Division
var divSimpleX:divisionSimpleX = new divisionSimpleX();
divSimpleX.x = 42;
divSimpleX.y = 397.5;
var divSimpleY:divisionSimpleY = new divisionSimpleY();
divSimpleY.x = 366.95;
divSimpleY.y = 397.50;
var divSimpleAnswer:divisionSimpleAnswer = new divisionSimpleAnswer();
divSimpleAnswer.x = 698.95;
divSimpleAnswer.y = 397.50;
var divisionDivSign:divisionSign = new divisionSign();
divisionDivSign.x = 277.80;
divisionDivSign.y = 360.95;
var divEqualsSign:equalsSign = new equalsSign();
divEqualsSign.x = 609.80;
divEqualsSign.y = 361.95;
var divSummary:divisionSummary = new divisionSummary();
divSummary.x = 112.50;
divSummary.y = 202.20;
var divTryOut:tryItOut = new tryItOut();
divTryOut.x = 218.80;
divTryOut.y = 466.95;
var divDDLink:digDeeperLink = new digDeeperLink();
divDDLink.x = 274.95;
divDDLink.y = 696;
var divTQLink:quizLink = new quizLink();
divTQLink.x = 274.95;
divTQLink.y = 696;
// Division Deeper
var divDD1:divisionDD1 = new divisionDD1();
divDD1.x = 239.60;
divDD1.y = 215.00;
var divDD2:divisionDD2 = new divisionDD2();
divDD2.x = 328.65;
divDD2.y = 336.70;
var divDD3:divisionDD3 = new divisionDD3();
divDD3.x = 308.95;
divDD3.y = 381.20;
var divB2BLink:backToBasicsLink = new backToBasicsLink();
divB2BLink.x = 271.95;
divB2BLink.y = 696;
var divDDTQLink:quizLink = new quizLink();
divDDTQLink.x = 468;
divDDTQLink.y = 696;
// Quiz
//Title
var titleQuiz:quizTitle = new quizTitle();
titleQuiz.x = 419.40;
titleQuiz.y = 192;
// Random Number Backgrounds
var quizBG1:shortTextBG = new shortTextBG();
quizBG1.x = 44.9;
quizBG1.y = 283;
var quizBG2:shortTextBG = new shortTextBG();
quizBG2.x = 368.95;
quizBG2.y = 283;
var quizBG3:shortTextBG = new shortTextBG();
quizBG3.x = 44.9;
quizBG3.y = 360.25;
var quizBG4:shortTextBG = new shortTextBG();
quizBG4.x = 368.95;
quizBG4.y = 360.25;
var quizBG5:shortTextBG = new shortTextBG();
quizBG5.x = 44.90;
quizBG5.y = 440.20;
var quizBG6:shortTextBG = new shortTextBG();
quizBG6.x = 368.95;
quizBG6.y = 440.20;
var quizBG7:shortTextBG = new shortTextBG();
quizBG7.x = 44.90;
quizBG7.y = 518.80;
var quizBG8:shortTextBG = new shortTextBG();
quizBG8.x = 368.95;
quizBG8.y = 518.80
// Signs
var quizAddSign:additionSign = new additionSign();
quizAddSign.x = 280.05;
quizAddSign.y = 251.90;
var quizSubSign:subtractionSign = new subtractionSign();
quizSubSign.x = 281.40;
quizSubSign.y = 323.80;
var quizMulSign:multiplicationSign = new multiplicationSign();
quizMulSign.x = 288.20;
quizMulSign.y = 414.05;
var quizDivSign:divisionSign = new divisionSign();
quizDivSign.x = 280.05;
quizDivSign.y = 489.20;
var quizAddEqualsSign:equalsSign = new equalsSign();
quizAddEqualsSign.x = 603.90;
quizAddEqualsSign.y = 251.90;
var quizSubEqualsSign:equalsSign = new equalsSign();
quizSubEqualsSign.x = 603.90;
quizSubEqualsSign.y = 330.55;
var quizMulEqualsSign:equalsSign = new equalsSign();
quizMulEqualsSign.x = 603.90;
quizMulEqualsSign.y = 409.20;
var quizDivEqualsSign:equalsSign = new equalsSign();
quizDivEqualsSign.x = 603.90;
quizDivEqualsSign.y = 489.20;
// Check quiz
var quizCheck:checkQuiz = new checkQuiz();
quizCheck.x = 369.95;
quizCheck.y = 626.60;
var answerWrong:wrongAnswer = new wrongAnswer();
var answerCorrect:correctAnswer = new correctAnswer();
// Home Page //;
// Create Header & Nav //
// Logo
addChild(headerLogo);
addChild(additionLink);
addChild(subtractionLink);
addChild(multiplicationLink);
addChild(divisionLink);
addChild(animation);
headerLogo.addEventListener(MouseEvent.CLICK, runIndexPage);
function runIndexPage(e:MouseEvent):void
{
// Hide other Pages
hideOtherPages();
addChild(animation);
animation.gotoAndPlay(1);
}
// Addition Page //
additionLink.addEventListener(MouseEvent.CLICK, runAddition);
function runAddition(e:MouseEvent):void
{
hideOtherPages();
createAdditionPage();
}
subtractionLink.addEventListener(MouseEvent.CLICK, runSubtraction);
function runSubtraction(e:MouseEvent):void
{
hideOtherPages();
createSubtractionPage();
}
multiplicationLink.addEventListener(MouseEvent.CLICK, runMultiplication);
function runMultiplication(e:MouseEvent):void
{
hideOtherPages();
createMultiplicationPage();
}
divisionLink.addEventListener(MouseEvent.CLICK, runDivision);
function runDivision(e:MouseEvent):void
{
hideOtherPages();
createDivisionPage();
}
//Global Functions
function createAdditionPage():void
{
addChild(addSimpleX);
addChild(addSimpleY);
addChild(addSimpleAnswer);
addChild(additionAddSign);
addChild(additionEqualsSign);
addChild(addSum);
addChild(addTryOut);
addChild(addDDLink);
addChild(addTQLink);
}
function createSubtractionPage():void
{
addChild(subSimpleX);
addChild(subSimpleY);
addChild(subSimpleAnswer);
addChild(subtractionSubSign);
addChild(subtractionEqualsSign);
addChild(subSum);
addChild(subTryOut);
addChild(subDDLink);
addChild(subTQLink);
}
function createMultiplicationPage():void
{
addChild(mulSimpleX);
addChild(mulSimpleY);
addChild(mulSimpleAnswer);
addChild(multiplicationMulSign);
addChild(mulEqualsSign);
addChild(mulSummary);
addChild(mulTryOut);
addChild(mulDDLink);
addChild(mulTQLink);
}
function createDivisionPage():void
{
addChild(divSimpleX);
addChild(divSimpleY);
addChild(divSimpleAnswer);
addChild(divisionDivSign);
addChild(divEqualsSign);
addChild(divSummary);
addChild(divTryOut);
addChild(divDDLink);
addChild(divTQLink);
}
function hideOtherPages():void
{
if(animation)
{
removeChild(animation);
SoundMixer.stopAll();
}
else if(addSimpleX)
{
removeChild(addSimpleX);
removeChild(addSimpleY);
removeChild(addSimpleAnswer);
removeChild(additionAddSign);
removeChild(additionEqualsSign);
removeChild(addSum);
removeChild(addTryOut);
removeChild(addDDLink);
removeChild(addTQLink);
}
else if(addLong)
{
removeChild(addLong);
removeChild(addDDSum);
removeChild(addDDB2B);
removeChild(addDDTQ);
}
else if(subSimpleX)
{
removeChild(subSimpleX);
removeChild(subSimpleY);
removeChild(subSimpleAnswer);
removeChild(subtractionSubSign);
removeChild(subtractionEqualsSign);
removeChild(subSum);
removeChild(subTryOut);
removeChild(subDDLink);
removeChild(subTQLink);
}
else if(subBudget)
{
removeChild(subBudget);
removeChild(subExpenses);
removeChild(subDDT1);
removeChild(subDDT2);
removeChild(subDDT3);
removeChild(subDDT4);
removeChild(subCheckBudgetLink);
removeChild(subB2BLink);
removeChild(subDDTQLink);
}
else if(mulSimpleX)
{
removeChild(mulSimpleX);
removeChild(mulSimpleY);
removeChild(mulSimpleAnswer);
removeChild(multiplicationMulSign);
removeChild(mulEqualsSign);
removeChild(mulSummary);
removeChild(mulDDLink);
removeChild(mulTQLink);
}
else if(mulDD1)
{
removeChild(mulDD1);
removeChild(mulDD2);
removeChild(mulDD3);
removeChild(mulDD4);
removeChild(mulB2BLink);
removeChild(mulDDTQL);
}
else if(divSimpleX)
{
removeChild(divSimpleX);
removeChild(divSimpleY);
removeChild(divSimpleAnswer);
removeChild(divisionDivSign);
removeChild(divEqualsSign);
removeChild(divSummary);
removeChild(divTryOut);
removeChild(divDDLink);
removeChild(divTQLink);
}
else if(divDD1)
{
removeChild(divDD1);
removeChild(divDD2);
removeChild(divDD3);
removeChild(divB2BLink);
removeChild(divDDTQLink);
}
else if(titleQuiz)
{
removeChild(titleQuiz);
removeChild(quizBG1);
removeChild(quizBG2);
removeChild(quizBG3);
removeChild(quizBG4);
removeChild(quizBG5);
removeChild(quizBG6);
removeChild(quizBG7);
removeChild(quizBG8);
removeChild(quizAddSign);
removeChild(quizSubSign);
removeChild(quizMulSign);
removeChild(quizDivSign);
removeChild(quizAddEqualsSign);
removeChild(quizSubEqualsSign);
removeChild(quizMulEqualsSign);
removeChild(quizDivEqualsSign);
removeChild(quizCheck);
//Dynamic Quiz Removal Section ****
}
}
This code looks terrifying, but I won't dive into it as it is not the merits of the question. The problem is that you are only checking (in function hideOtherPages()) an existence of the objects, and not if they are added to Stage. You cannot remove from stage an object that is not there, this is why you gets this error, and it states just that.
You can check if your objects are added to stage before you will try to remove them.
You can remove all children from an object by simple loop.
The second option is the best in this case. You would create a Sprite, and...
var myContainer:Sprite = new Sprite();
addChild(myContainer);
// Here you are adding children/first set of visible objects
myContainer.addChild(myObject);
// ...
And now just before you will add new set of objects to container you can call "clearContainer()" function to remove previous ones.
function clearContainer() : void {
while(myContainer.numChildren) {
myContainer.removeChildAt(0);
}
}
Your code will be GREATLY reduced because of this, as you won't be forced to remove every item manually...
Alternatively if you want to keep a brute force, you can just check if objects exist before remove them manually, and you can do this by using function getChildByName(name:String) . You can set a property "name" for your objects and then check if "getChildByName" will return object or null, and if it is an object, you would remove it. So at the beginning it would look like this:
var divisionLink:divPageLink = new divPageLink();
divisionLink.x = 597.95;
divisionLink.y = 144.60;
divisionLink.name = "divisionLink"; // setting a name
And your removing would look like this:
else if(divisionLink && this.getChildByName("divisionLink"))
{
removeChild(divisionLink);
}
And do this with every item. This is tedious and slow, so I wouldn't recommend it, but included it for educational purposes.