Preloader not running - actionscript-3

Iam trying to run preloader with percentage but it not show the percent in dynamic text please anyone give the solution..
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.display.LoaderInfo;
loaderInfo.addEventListener(ProgressEvent.PROGRESS, loading);
function loading(e:ProgressEvent):void
{
var Percent:Number = e.bytesLoaded/e.bytesTotal*100;
myText.text = Math.round(Percent)+"%";
if(Percent == 100)
{
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loading);
}
}

Related

How do I stop sound using AS3)

my sounds in code called sound1 , sound2 my sounds in class called sounda , soundb I hope find answers to fix my problem`
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
stop();
var sound1:sounda = new sounda();
var sound2:soundb = new soundb();
cbox.addItem( { label: "chose"} )
cbox.addItem( { label: "first"} )
cbox.addItem( { label: "sec"} )
cbox.addEventListener(Event.CHANGE,plays);
function plays(e:Event):void
{
if (cbox.selectedItem.label == "first")
{
sound1.play();
//not working
sound2.stop();
}
if (cbox.selectedItem.label == "sec")
{
sound2.play();
//not working
sound1.stop();
}
}
//when I play sound1 then when I play sound2 .. sound1 still playing
to stop all sounds from playing
import flash.media.SoundMixer;
SoundMixer.stopAll();
to stop a single sound, you must using SoundChannel
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLLoader;
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
mySound.load(new URLRequest("myFavSong.mp3"));
myChannel = mySound.play();
// ...
myChannel.stop();

AS3 1084: Syntax error: expecting rightparen before colon

i'm trying to make an AS3 shooting game, which is player right to left.
I want to make it so that, when i shoot (spawnKogel) shootAllow becomes false, and then initiates kogelCheck, which checks if the bullet (Kogel) is < -10. If that's true, shootAllow becomes True, and i can shoot again.
But i'm getting the error in the title, at the end of the spawnKogel, when I try to initialize kogelCheck. Here's my code:
package
{
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.ui.Keyboard;
import flash.ui.Mouse;
import flash.events.MouseEvent;
import flash.display.Stage;
import flash.media.Sound;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class amateurodius extends MovieClip
{
public var schip:ruimteschip = new ruimteschip();
public var Kogel = new Bullet();
var sound = new lazor();
var BGM = new Muziek();
var backdrop = new background();
var shootAllow:Boolean = true;
public function amateurodius()
{
addEventListener(Event.ADDED_TO_STAGE, initialize);
addEventListener(Event.ENTER_FRAME, vijandmaken);
stage.addEventListener(KeyboardEvent.KEY_DOWN, spawnKogel);
addEventListener(Event.ENTER_FRAME, kogelCheck);
Mouse.hide();
}
function initialize(e:Event)
{
addChild(backdrop);
addChild(schip);
BGM.play();
}
function spawnKogel(e:KeyboardEvent):void
{
if (shootAllow == true)
{
if (e.keyCode == Keyboard.SPACE)
{
addChild(Kogel);
Kogel.x = schip.x;
Kogel.y = schip.y;
sound.play();
shootAllow = false;
kogelCheck (e:Event);
}
}
}
function kogelCheck (e:Event)
{
if (Kogel.x < -30)
{
shootAllow == true;
}
else
{
shootAllow == false;
}
}
Remove the type from event when you call kogelCheck:
// Just passing on the event, doesn't need type declaration
kogelCheck (e);

Flash AS3 Security Sandbox Violation / s.ytimg.com

I have been reading about this trouble for days now and i'm going mad. Please Help!
I'm trying to load in vain a YouTube video into my portfolio. I'v uploaded the video on Youtube and it's Public.
I've tried the code with a bunch of other Youtube videos and it works perfect with them all except with mine...
Like i said i'm going MAD!!! please help!!
* Security Sandbox Violation *
SecurityDomain 'http://s.ytimg.com/crossdomain.xml' tried to access incompatible context 'file:///M|/Architecture/PORTFOLIO/WEB/PORTFOLIO.swf'
Here's the code of the part in context:
import flash.display.Loader;
import flash.net.URLRequest;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import fl.controls.ProgressBar;
import fl.controls.ProgressBar;
import fl.transitions.TweenEvent;
import flash.events.Event;
import fl.controls.ProgressBar;
import flash.ui.MouseCursor;
import flash.system.Security;
pages.visible = false;
pages.fullPage.alpha = 0;
var my_images:XMLList;
var my_total:Number;
var page_no:Number = 1;
pages.pb.alpha = 0;
pages.btnBallon.visible = false;
pages.btnBallon.removeEventListener(MouseEvent.CLICK, lVid);
pages.btnBallon.buttonMode = false;
//Youtube loader
Security.allowDomain("*");
Security.allowDomain("www.youtube.com");
Security.allowDomain("youtube.com");
Security.allowDomain("s.ytimg.com");
Security.allowDomain("i1.ytimg.com");
Security.allowDomain("i.ytimg.com");
Security.allowDomain("http://s.ytimg.com/crossdomain.xml");
Security.allowDomain("popslinger.org");
Security.allowDomain("http://www.box.net/api/crossdomain.xml");
Security.loadPolicyFile("http://i.ytimg.com/crossdomain.xml");
Security.loadPolicyFile("http://www.youtube.com/crossdomain.xml");
Security.loadPolicyFile("http://s.ytimg.com/crossdomain.xml");
Security.loadPolicyFile('http://youtube.com/crossdomain.xml');
Security.loadPolicyFile("http://www.box.net/api/crossdomain.xml");
function video():void{
pages.btnBallon.visible = true;
pages.btnBallon.addEventListener(MouseEvent.CLICK, lVid);
pages.btnBallon.buttonMode = true;
}
function lVid(e:Event = null):void{
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
}
function onInit(e:Event):void{
addChild(loader);
player = loader.content;
player.addEventListener("onReady",onPlayerReady);
}
function onPlayerReady(e:Event):void{
var pageTween:Tween = new Tween(pages.fullPage, "alpha", Strong.easeOut,pages.fullPage.alpha, 0, 1, true);
player.setSize = (560,315);
player.x = pages.x + 120;
player.y = pages.y;
pages.visible = false;
pages.btnBallon.visible = false;
pages.btnBallon.removeEventListener(MouseEvent.CLICK, lVid);
pages.btnBallon.buttonMode = false;
/*pages.btnNext.removeEventListener(MouseEvent.CLICK, nextPage);
pages.btnNext.visible = false;
pages.btnPrev.removeEventListener(MouseEvent.CLICK, nextPage);
pages.btnPrev.visible = false;*/
player.loadVideoByUrl("www.youtube.com/embed/omcl93EYTrM",0);
//player.loadVideoById("omcl93EYTrM",0);
}
Try change this value:
File -> Publish settings

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);
}
}
}
}

Error 1119 when creating "Load Text" button

A section of a Flash animation I'm creating involves an area where people can write on a notepad, save their work and update it at a later time. The file will be downloaded by users before they run it, rather than from a webpage. Here is the code I have so far:
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.display.MovieClip;
import flash.events.Event;
stop();
var MyNotes:FileReference = new FileReference()
Save_btn.addEventListener (MouseEvent.CLICK, SaveText);
function SaveText(Event:MouseEvent):void {
MyNotes.save(TypeOwn_txt.text, "MyNotes.txt");
}
Load_btn.addEventListener (MouseEvent.CLICK, LoadText);
function LoadText(Event:MouseEvent):void {
MyNotes.addEventListener(Event.SELECT, onFileSelected);
var swfTypeFilter:FileFilter = new FileFilter("Text Files","*.txt; .html;*.htm;*.php");
var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");
MyNotes.browse([swfTypeFilter, allTypeFilter]);
}
function onFileSelected(event:Event):void
{
trace("onFileSelected");
MyNotes.addEventListener(Event.COMPLETE, onFileLoaded);
MyNotes.load();
}
function onFileLoaded(event:Event):void
{
var fileReference:FileReference=event.target as FileReference;
var data:ByteArray=fileReference["data"];
TypeOwn_txt.text=data.toString();
}
The problem is I receive a "Symbol 'Structure Summary', Layer 'Actions', Frame 29, Line 19 1119: Access of possibly undefined property SELECT through a reference with static type flash.events:MouseEvent.
" in regards to the line "MyNotes.addEventListener(Event.SELECT, onFileSelected);". I've done some research and understand this is something to do with the parent not being identified as a MovieClip, or something along those lines. I'm still not sure, however I don't have a clue how to proceed! Thanks.
Just to let you know the problem is solved, although I really don't know how. I used this site for a template and worked backwards. I'll put in the working Code below in case it's of use to somebody else.
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.display.MovieClip;
var myNotes:FileReference;
Load_btn.addEventListener(MouseEvent.CLICK, onLoadClicked);
function onLoadClicked(event:MouseEvent):void
{
trace("onBrowse");
myNotes=new FileReference();
myNotes.addEventListener(Event.SELECT, onFileSelected);
var swfTypeFilter:FileFilter = new FileFilter("Text Files","*.txt; *.html;*.htm;*.php");
var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");
myNotes.browse([swfTypeFilter, allTypeFilter]);
}
function onFileSelected(event:Event):void
{
trace("onFileSelected");
myNotes.addEventListener(Event.COMPLETE, onFileLoaded);
myNotes.addEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
myNotes.load();
}
function onFileLoaded(event:Event):void
{
var fileReference:FileReference=event.target as FileReference;
var data:ByteArray=fileReference["data"];
textArea.text=data.toString();
myNotes.removeEventListener(Event.COMPLETE, onFileLoaded);
myNotes.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
}
function onFileLoadError(event:Event):void
{
myNotes.removeEventListener(Event.COMPLETE, onFileLoaded);
myNotes.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
trace("File load error");
}
Save_btn.addEventListener (MouseEvent.CLICK, SaveText);
function SaveText(Event:MouseEvent):void {
myNotes=new FileReference();
myNotes.save(textArea.text, "MyNotes.txt");
}
Thanks to everyone who contributed.